mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00
test_runner: run single test file benchmark
PR-URL: https://github.com/nodejs/node/pull/56479 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
parent
dc5d0f9bb4
commit
8975748527
62
benchmark/test_runner/run-single-test-file.js
Normal file
62
benchmark/test_runner/run-single-test-file.js
Normal file
@ -0,0 +1,62 @@
|
||||
'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'],
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user