-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathrun-single-test-file.js
More file actions
69 lines (59 loc) · 1.78 KB
/
run-single-test-file.js
File metadata and controls
69 lines (59 loc) · 1.78 KB
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
'use strict';
const common = require('../common');
const tmpdir = require('../../test/common/tmpdir');
const { run } = require('node:test');
const { writeFileSync, mkdirSync } = require('node:fs');
const { join } = require('node:path');
const fixtureContent = "const test = require('node:test'); test('test has ran');";
function makeTestDirWithFiles(dirPath, count) {
mkdirSync(dirPath);
for (let i = 0; i < count; i++) {
writeFileSync(join(dirPath, `test-${i}.js`), fixtureContent);
}
}
function getTestDirPath(numberOfTestFiles) {
return join(tmpdir.path, `${numberOfTestFiles}-tests`);
}
function setup(numberOfTestFiles) {
tmpdir.refresh();
const dirPath = getTestDirPath(numberOfTestFiles);
makeTestDirWithFiles(dirPath, numberOfTestFiles);
}
/**
* This benchmark evaluates the overhead of running a single test file under different
* isolation modes.
* Specifically, it compares the performance of running tests in the
* same process versus creating multiple processes.
*/
const bench = common.createBenchmark(
main,
{
numberOfTestFiles: [1, 10, 100],
isolation: ['none', 'process'],
},
{
// We don't want to test the reporter here
flags: [
'--test-reporter=./benchmark/fixtures/empty-test-reporter.js',
'--test-reporter-destination=stdout',
],
},
);
async function runBenchmark({ numberOfTestFiles, isolation }) {
const dirPath = getTestDirPath(numberOfTestFiles);
const stream = run({
cwd: dirPath,
isolation,
concurrency: false, // We don't want to run tests concurrently
});
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
return numberOfTestFiles;
}
function main(params) {
setup(params.numberOfTestFiles);
bench.start();
runBenchmark(params).then(() => {
bench.end(1);
});
}