-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
/
testViteIntegration.js
59 lines (51 loc) · 1.31 KB
/
testViteIntegration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const playwright = require('playwright');
/**
* @param {number} timeoutMS
* @returns {Promise<void>}
*/
function sleep(duration) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, duration);
});
}
/**
* Attempts page.goto with retries
*
* @remarks The server and runner can be started up simultaneously
* @param {import('playwright').PAge} page
* @param {string} url
* @returns {boolean}
*/
async function attemptGoto(page, url) {
const maxAttempts = 10;
const retryTimeoutMS = 250;
let didNavigate = false;
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
try {
// eslint-disable-next-line no-await-in-loop
await page.goto(url);
didNavigate = true;
} catch (error) {
// eslint-disable-next-line no-await-in-loop
await sleep(retryTimeoutMS);
}
}
return didNavigate;
}
async function main() {
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
page.on('console', (consoleMessage) => {
throw new Error(
`Expected no console messages but got ${consoleMessage.type()}: '${consoleMessage.text()}' `,
);
});
await attemptGoto(page, 'http://localhost:5001/');
await browser.close();
}
main().catch((error) => {
console.error(error);
process.exit(1);
});