-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.ts.example
74 lines (57 loc) · 1.61 KB
/
test.ts.example
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
import { InitialRenderBenchmark, InitialRenderSamples, ITab, Runner } from "chrome-tracing";
import * as fs from "fs";
const BASE_PORT = 9292;
let browserOpts = process.env.CHROME_BIN ? {
type: "exact",
executablePath: process.env.CHROME_BIN
} : {
type: "system"
};
let experiments = JSON.parse(fs.readFileSync('config/experiments.json', 'utf8'));
async function sleep(ms) {
await new Promise(resolve => setTimeout(resolve, 2500));
}
class EmberBench extends InitialRenderBenchmark {
static all(): EmberBench[] {
return experiments.map((experiment, i) => {
let { name, url } = experiment;
let port = BASE_PORT + i;
if (!url) {
url = "/";
} else if (url.charAt(0) !== "/") {
url = "/" + url;
}
return new EmberBench(name, port, `http://localhost:${port}${url}`);
});
}
constructor(name: string, private port: number, private url: string) {
super({
name,
url,
markers: [
{ start: "domLoading", label: "done" },
],
browser: browserOpts
});
}
async warm(tab: ITab): Promise<void> {
await tab.navigate(`http://localhost:${this.port}/preload.html`, true);
await sleep(2500);
await tab.navigate(this.url, true);
await sleep(2500);
await tab.navigate(this.url, true);
await sleep(2500);
await tab.navigate(this.url, true);
await sleep(2500);
}
}
new Runner(EmberBench.all())
.run(100)
.then(results => {
results.forEach(result => {
fs.writeFileSync(`results/${result.set}.json`, JSON.stringify(result))
});
}).catch(err => {
console.error(err.stack);
process.exit(1);
});