-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
runner.js
executable file
·71 lines (61 loc) · 1.88 KB
/
runner.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
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
"use strict";
/* eslint-disable no-console */
const consoleReporter = require("./console-reporter");
const pathToSuites = require("./path-to-suites");
const benchmarks = require(".");
const fs = require("fs");
const path = require("path");
const { toFileUrl } = require("../lib/jsdom/utils");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const { argv } = yargs(hideBin(process.argv))
.usage("Run the jsdom benchmark suite")
.option("suites", {
type: "array",
alias: "s",
describe: "suites that you want to run, e.g.: dom/construction/createElement dom/foo"
})
.option("bundle", {
type: "boolean",
describe: "generate the JavaScript bundle required to run benchmarks in a browser"
})
.help();
if (argv.bundle) {
const bundle = require("browserify")({ debug: true });
bundle.require(path.resolve(__dirname, ".."), { expose: "jsdom" });
bundle.require(path.resolve(__dirname, "browser-runner.js"), { expose: "jsdom-browser-runner" });
bundle.bundle()
.pipe(fs.createWriteStream(path.resolve(__dirname, "browser-bundle.js")))
.on("finish", () => {
console.info(
"Open the following page in Chrome to begin benchmarking:",
toFileUrl(path.resolve(__dirname, "browser-runner.html"))
);
});
return;
}
let suitesToRun;
if (argv.suites) {
suitesToRun = pathToSuites(benchmarks, argv.suites);
} else {
suitesToRun = pathToSuites(benchmarks);
}
suitesToRun.forEach(consoleReporter);
function runNext() {
/* eslint-disable no-invalid-this */
if (this && this.off) {
// there is no .once()
this.off("complete", runNext);
}
/* eslint-enable no-invalid-this */
const suite = suitesToRun.shift();
if (!suite) {
console.log("Done!");
return;
}
suite.off("complete", runNext);
suite.on("complete", runNext);
suite.run({ async: true });
}
runNext();