forked from rocicorp/replicache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
74 lines (61 loc) · 1.76 KB
/
Copy pathrunner.js
File metadata and controls
74 lines (61 loc) · 1.76 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* eslint-env node, es2020 */
import * as playwright from 'playwright';
import {startDevServer} from '@web/dev-server';
import getPort from 'get-port';
import * as os from 'os';
import * as path from 'path';
import {promises as fs} from 'fs';
async function main() {
const verbose = process.argv.includes('--verbose');
const devtools = process.argv.includes('--devtools');
const port = await getPort();
const server = await startDevServer({
config: {
rootDir: process.cwd(),
port,
watch: false,
},
readCliArgs: false,
readFileConfig: false,
logStartMessage: verbose,
});
const browserType = 'chromium';
const userDataDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'replicache-playwright-'),
);
const context = await playwright[
browserType
].launchPersistentContext(userDataDir, {devtools});
const page = await context.newPage();
await page.goto(`http://127.0.0.1:${port}/perf/index.html`);
await page.waitForFunction('typeof nextTest === "function"');
logLine('Running benchmarks please wait...');
if (devtools) {
console.log('Enter `await nextTest()` in the devtools console');
return;
}
for (;;) {
const testResult = await page.evaluate('nextTest(["replicache"])');
if (testResult === null) {
break;
}
logLine(testResult);
}
logLine('Done!');
await server.stop();
await fs.rmdir(userDataDir, {recursive: true});
// context.close does not terminate! Give it a second.
Promise.race([context.close(), wait(1000)]);
}
main().catch(err => {
console.error(err);
process.exit(1);
});
/** @param {string} s */
function logLine(s) {
process.stdout.write(s + '\n');
}
/** @param {number} n */
function wait(n) {
return new Promise(resolve => setTimeout(resolve, n));
}