/
coverage.js
32 lines (30 loc) · 1004 Bytes
/
coverage.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
// This benchmark is meant to exercise a grab bag of code paths that would
// be expected to run slower under coverage. To use this benchmark, create an
// alternate node bin that enables coverage and compare it against ./node
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
n: [1e5]
});
const path = require('path');
const { randomUUID } = require('crypto');
const { rmSync } = require('fs');
const { spawnSync } = require('child_process');
const tmpdir = require('../../test/common/tmpdir');
const coverageDir = path.join(tmpdir.path, `./cov-${randomUUID()}`);
function main({ n }) {
bench.start();
const result = spawnSync(process.execPath, [
require.resolve('../fixtures/coverage-many-branches'),
], {
env: {
NODE_V8_COVERAGE: coverageDir,
N: n,
}
});
rmSync(coverageDir, { recursive: true, force: true });
if (result.status !== 0) {
throw new Error(result.stderr.toString('utf8'));
}
bench.end(n);
}