-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke-test.mjs
More file actions
43 lines (38 loc) · 1.43 KB
/
smoke-test.mjs
File metadata and controls
43 lines (38 loc) · 1.43 KB
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
import puppeteer from 'puppeteer';
const url = process.argv[2] || 'http://127.0.0.1:4173/';
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const page = await browser.newPage();
const pageErrors = [];
const consoleErrors = [];
const failed = [];
page.on('pageerror', (e) => pageErrors.push(e.message));
page.on('console', (m) => {
if (m.type() === 'error') consoleErrors.push(m.text());
});
page.on('response', (r) => {
if (r.status() >= 400) failed.push(`[${r.status()}] ${r.url()}`);
});
try {
await page.goto(url, { waitUntil: 'networkidle0', timeout: 45000 });
await new Promise((r) => setTimeout(r, 3000));
const rootHtml = await page.evaluate(
() => document.getElementById('react-root')?.innerHTML?.slice(0, 400) || ''
);
const title = await page.title();
console.log('URL:', url);
console.log('TITLE:', title);
console.log('ROOT HTML LEN:', rootHtml.length);
console.log('ROOT HTML HEAD:\n', rootHtml);
console.log('\nPAGE ERRORS (' + pageErrors.length + '):');
pageErrors.slice(0, 20).forEach((e) => console.log(' - ' + e));
console.log('\nCONSOLE ERRORS (' + consoleErrors.length + '):');
consoleErrors.slice(0, 20).forEach((e) => console.log(' - ' + e));
console.log('\nFAILED REQS (' + failed.length + '):');
failed.slice(0, 20).forEach((e) => console.log(' - ' + e));
} catch (e) {
console.log('NAV ERR:', e.message);
} finally {
await browser.close();
}