| 22 | }); |
| 23 | |
| 24 | function spawnProcess(cli, bench, state) { |
| 25 | const cmd = process.execPath || process.argv[0]; |
| 26 | while (state.finished < state.n) { |
| 27 | const child = spawnSync(cmd, [cli, '--version'], { |
| 28 | env: { npm_config_loglevel: 'silent', ...process.env }, |
| 29 | }); |
| 30 | // Log some information for debugging if it fails, which it shouldn't. |
| 31 | if (child.status !== 0) { |
| 32 | console.log('---- STDOUT ----'); |
| 33 | console.log(child.stdout.toString()); |
| 34 | console.log('---- STDERR ----'); |
| 35 | console.log(child.stderr.toString()); |
| 36 | throw new Error(`Child process stopped with exit code ${child.status}`); |
| 37 | } |
| 38 | state.finished++; |
| 39 | if (state.finished === 0) { |
| 40 | // Finished warmup. |
| 41 | bench.start(); |
| 42 | } |
| 43 | |
| 44 | if (state.finished === state.n) { |
| 45 | bench.end(state.n); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function main({ n, cli }) { |
| 51 | cli = path.resolve(__dirname, '../../', cli); |