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