-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
362 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
</head> | ||
|
||
<body> | ||
<div id="insert"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { afterAll, beforeAll, expect, test } from 'vitest'; | ||
import { preview } from 'vite'; | ||
import type { PreviewServer } from 'vite'; | ||
import { Browser, Page, chromium } from 'playwright'; | ||
import { TIMEOUT } from './constants'; | ||
|
||
let browser: Browser; | ||
let server: PreviewServer; | ||
let page: Page; | ||
|
||
beforeAll(async () => { | ||
browser = await chromium.launch({ headless: true }); | ||
server = await preview({ preview: { port: 3000 } }); | ||
page = await browser.newPage(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await browser.close(); | ||
await new Promise<void>((resolve, reject) => { | ||
server.httpServer.close((error) => (error ? reject(error) : resolve())); | ||
}); | ||
}); | ||
|
||
test( | ||
'add attrs', | ||
async () => { | ||
try { | ||
await page.goto('http://localhost:3000'); | ||
await page.evaluate(async () => { | ||
await window.simpleLoadScript({ | ||
url: '//code.jquery.com/jquery-2.2.3.js', | ||
attrs: { id: 'jquery', 'data-test': 'test' }, | ||
}); | ||
}); | ||
const jquery = await page.$('script#jquery'); | ||
const id = await page.evaluate((script) => script?.id, jquery); | ||
const dataTest = await page.evaluate( | ||
(script) => script?.dataset.test, | ||
jquery, | ||
); | ||
|
||
expect(id).toBe('jquery'); | ||
expect(dataTest).toBe('test'); | ||
} catch (err) { | ||
expect(err).toBeUndefined(); | ||
} | ||
}, | ||
TIMEOUT, | ||
); | ||
|
||
test( | ||
'dom not add attrs', | ||
async () => { | ||
try { | ||
await page.goto('http://localhost:3000'); | ||
await page.evaluate(async () => { | ||
await window.simpleLoadScript({ | ||
url: '//code.jquery.com/jquery-2.2.3.js', | ||
}); | ||
}); | ||
const jquery = await page.$('script'); | ||
const jqueryWithId = await page.$('script#jquery'); | ||
const nodeType = await page.evaluate( | ||
(script) => script?.nodeType, | ||
jquery, | ||
); | ||
const nodeTypeWithId = await page.evaluate( | ||
(script) => script?.nodeType, | ||
jqueryWithId, | ||
); | ||
|
||
expect(nodeType).toBe(1); | ||
expect(nodeTypeWithId).toBeUndefined(); | ||
} catch (err) { | ||
expect(err).toBeUndefined(); | ||
} | ||
}, | ||
TIMEOUT, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const TIMEOUT = 60_000; |
Oops, something went wrong.