• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* eslint-disable node-core/require-common-first, node-core/required-modules */
2
3'use strict';
4
5const assert = require('assert');
6const fork = require('child_process').fork;
7const path = require('path');
8
9const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
10
11function runBenchmark(name, env) {
12  const argv = ['test'];
13
14  argv.push(name);
15
16  const mergedEnv = { ...process.env, ...env };
17
18  const child = fork(runjs, argv, {
19    env: mergedEnv,
20    stdio: ['inherit', 'pipe', 'inherit', 'ipc']
21  });
22  child.stdout.setEncoding('utf8');
23
24  let stdout = '';
25  child.stdout.on('data', (line) => {
26    stdout += line;
27  });
28
29  child.on('exit', (code, signal) => {
30    assert.strictEqual(code, 0);
31    assert.strictEqual(signal, null);
32    // This bit makes sure that each benchmark file is being sent settings such
33    // that the benchmark file runs just one set of options. This helps keep the
34    // benchmark tests from taking a long time to run. Therefore, each benchmark
35    // file should result in three lines of output: a blank line, a line with
36    // the name of the benchmark file, and a line with the only results that we
37    // get from testing the benchmark file.
38    assert.ok(
39      /^(?:\n.+?\n.+?\n)+$/.test(stdout),
40      `benchmark file not running exactly one configuration in test: ${stdout}`
41    );
42  });
43}
44
45module.exports = runBenchmark;
46