forked from ArnaudBarre/esm-dev-server-limit
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.ts
43 lines (38 loc) · 1.22 KB
/
test.ts
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 { spawn } from "node:child_process";
import { launch } from "puppeteer";
import { genCode } from "./codegen.js";
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
const runTest = async (width: number, depth: number) => {
const runs: number[] = [];
for (let i = 0; i < 5; i++) {
genCode(width, depth);
const process = spawn("vite");
const page = await browser.newPage();
await wait(500);
const start = performance.now();
await page.goto(`http://localhost:5173`);
await page.waitForSelector("#app", { timeout: 10_000 });
runs.push(Math.round(performance.now() - start));
await page.close();
process.kill();
await wait(500);
}
console.log(
`${width * depth} TS modules (${width}x${depth}) loaded in: ${
runs.slice().sort((a, z) => a - z)[2]
}ms (runs: [${runs}])`,
);
};
const browser = await launch();
if (process.argv.length === 4) {
const [width, depth] = process.argv.slice(2);
await runTest(Number(width), Number(depth));
} else {
await runTest(50, 20);
await runTest(20, 50);
await runTest(100, 20);
await runTest(250, 20);
await runTest(400, 25);
}
await browser.close();
console.log("Finished, you can kill the process");