GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_runner: run single test file benchmark · nodejs/node@c4979eb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/test_runner
    • run-single-test-file.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/test_runner/run-single-test-file.js‎

Copy file name to clipboard
+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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.