Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c4979eb

Browse filesBrowse files
pmarchiniaduh95
authored andcommitted
test_runner: run single test file benchmark
PR-URL: #56479 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent 9414d3c commit c4979eb
Copy full SHA for c4979eb

File tree

Expand file treeCollapse file tree

1 file changed

+62
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+62
-0
lines changed
Open diff view settings
Collapse file
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
const tmpdir = require('../../test/common/tmpdir');
5+
const { run } = require('node:test');
6+
const { writeFileSync, mkdirSync } = require('node:fs');
7+
const { join } = require('node:path');
8+
9+
const fixtureContent = "const test = require('node:test'); test('test has ran');";
10+
11+
function makeTestDirWithFiles(dirPath, count) {
12+
mkdirSync(dirPath);
13+
for (let i = 0; i < count; i++) {
14+
writeFileSync(join(dirPath, `test-${i}.js`), fixtureContent);
15+
}
16+
}
17+
18+
function getTestDirPath(numberOfTestFiles) {
19+
return join(tmpdir.path, `${numberOfTestFiles}-tests`);
20+
}
21+
22+
function setup(numberOfTestFiles) {
23+
tmpdir.refresh();
24+
const dirPath = getTestDirPath(numberOfTestFiles);
25+
makeTestDirWithFiles(dirPath, numberOfTestFiles);
26+
}
27+
28+
/**
29+
* This benchmark evaluates the overhead of running a single test file under different
30+
* isolation modes.
31+
* Specifically, it compares the performance of running tests in the
32+
* same process versus creating multiple processes.
33+
*/
34+
const bench = common.createBenchmark(main, {
35+
numberOfTestFiles: [1, 10, 100],
36+
isolation: ['none', 'process'],
37+
}, {
38+
// We don't want to test the reporter here
39+
flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'],
40+
});
41+
42+
async function runBenchmark({ numberOfTestFiles, isolation }) {
43+
const dirPath = getTestDirPath(numberOfTestFiles);
44+
const stream = run({
45+
cwd: dirPath,
46+
isolation,
47+
concurrency: false, // We don't want to run tests concurrently
48+
});
49+
50+
// eslint-disable-next-line no-unused-vars
51+
for await (const _ of stream);
52+
53+
return numberOfTestFiles;
54+
}
55+
56+
function main(params) {
57+
setup(params.numberOfTestFiles);
58+
bench.start();
59+
runBenchmark(params).then(() => {
60+
bench.end(1);
61+
});
62+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.