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, cli: add --test-concurrency flag · nodejs/node@709c6c0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc
    • api
      • cli.md
      • test.md
    • node.1
  • lib/internal/main
    • test_runner.js
  • src
    • node_options.cc
    • node_options.h
  • test/parallel
    • test-runner-cli-concurrency.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+9Lines changed: 9 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,15 @@ Starts the Node.js command line test runner. This flag cannot be combined with
16261626
See the documentation on [running tests from the command line][]
16271627
for more details.
16281628

1629+
### `--test-concurrency`
1630+
1631+
<!-- YAML
1632+
added: REPLACEME
1633+
-->
1634+
1635+
The maximum number of test files that the test runner CLI will execute
1636+
concurrently. The default value is `os.availableParallelism() - 1`.
1637+
16291638
### `--test-name-pattern`
16301639

16311640
<!-- YAML
Collapse file

‎doc/api/test.md‎

Copy file name to clipboardExpand all lines: doc/api/test.md
+7-5Lines changed: 7 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,12 @@ When searching for test files to execute, the test runner behaves as follows:
373373
automatically executed by the test runner, but are supported if explicitly
374374
provided on the command line.
375375

376-
Each matching test file is executed in a separate child process. If the child
377-
process finishes with an exit code of 0, the test is considered passing.
378-
Otherwise, the test is considered to be a failure. Test files must be
379-
executable by Node.js, but are not required to use the `node:test` module
380-
internally.
376+
Each matching test file is executed in a separate child process. The maximum
377+
number of child processes running at any time is controlled by the
378+
[`--test-concurrency`][] flag. If the child process finishes with an exit code
379+
of 0, the test is considered passing. Otherwise, the test is considered to be a
380+
failure. Test files must be executable by Node.js, but are not required to use
381+
the `node:test` module internally.
381382

382383
Each test file is executed as if it was a regular script. That is, if the test
383384
file itself uses `node:test` to define tests, all of those tests will be
@@ -2562,6 +2563,7 @@ added:
25622563
[TTY]: tty.md
25632564
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
25642565
[`--import`]: cli.md#--importmodule
2566+
[`--test-concurrency`]: cli.md#--test-concurrency
25652567
[`--test-name-pattern`]: cli.md#--test-name-pattern
25662568
[`--test-only`]: cli.md#--test-only
25672569
[`--test-reporter-destination`]: cli.md#--test-reporter-destination
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ Specify the minimum allocation from the OpenSSL secure heap. The default is 2. T
418418
.It Fl -test
419419
Starts the Node.js command line test runner.
420420
.
421+
.It Fl -test-concurrency
422+
The maximum number of test files that the test runner CLI will execute
423+
concurrently.
424+
.
421425
.It Fl -test-name-pattern
422426
A regular expression that configures the test runner to only execute tests
423427
whose name matches the provided pattern.
Collapse file

‎lib/internal/main/test_runner.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/test_runner.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const {
2222
prepareMainThreadExecution(false);
2323
markBootstrapComplete();
2424

25-
let concurrency = true;
25+
let concurrency = getOptionValue('--test-concurrency') || true;
2626
let inspectPort;
2727

2828
if (isUsingInspector()) {
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
595595
AddOption("--test",
596596
"launch test runner on startup",
597597
&EnvironmentOptions::test_runner);
598+
AddOption("--test-concurrency",
599+
"specify test runner concurrency",
600+
&EnvironmentOptions::test_runner_concurrency);
598601
AddOption("--experimental-test-coverage",
599602
"enable code coverage in the test runner",
600603
&EnvironmentOptions::test_runner_coverage);
Collapse file

‎src/node_options.h‎

Copy file name to clipboardExpand all lines: src/node_options.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class EnvironmentOptions : public Options {
159159
std::string env_file;
160160
bool has_env_file_string = false;
161161
bool test_runner = false;
162+
uint64_t test_runner_concurrency = 0;
162163
bool test_runner_coverage = false;
163164
std::vector<std::string> test_name_pattern;
164165
std::vector<std::string> test_reporter;
Collapse file

‎test/parallel/test-runner-cli-concurrency.js‎

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
const common = require('../common');
3+
const tmpdir = require('../common/tmpdir');
4+
const { deepStrictEqual, strictEqual } = require('node:assert');
5+
const { spawnSync } = require('node:child_process');
6+
const { readdirSync, writeFileSync } = require('node:fs');
7+
const { join } = require('node:path');
8+
const { beforeEach, test } = require('node:test');
9+
10+
function createTestFile(name) {
11+
writeFileSync(join(tmpdir.path, name), `
12+
const fs = require('node:fs');
13+
14+
fs.unlinkSync(__filename);
15+
setTimeout(() => {}, 1_000_000_000);
16+
`);
17+
}
18+
19+
beforeEach(() => {
20+
tmpdir.refresh();
21+
createTestFile('test-1.js');
22+
createTestFile('test-2.js');
23+
});
24+
25+
test('concurrency of one', () => {
26+
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], {
27+
cwd: tmpdir.path,
28+
timeout: common.platformTimeout(1000),
29+
});
30+
31+
strictEqual(cp.stderr.toString(), '');
32+
strictEqual(cp.error.code, 'ETIMEDOUT');
33+
deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']);
34+
});
35+
36+
test('concurrency of two', () => {
37+
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], {
38+
cwd: tmpdir.path,
39+
timeout: common.platformTimeout(1000),
40+
});
41+
42+
strictEqual(cp.stderr.toString(), '');
43+
strictEqual(cp.error.code, 'ETIMEDOUT');
44+
deepStrictEqual(readdirSync(tmpdir.path), []);
45+
});

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.