| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 54168b7 commit 428301a
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1298,6 +1298,15 @@ Starts the Node.js command line test runner. This flag cannot be combined with | |||
| 1298 | 1298 | See the documentation on [running tests from the command line][] | |
| 1299 | 1299 | for more details. | |
| 1300 | 1300 | ||
| 1301 | + ### `--test-concurrency` | ||
| 1302 | + | ||
| 1303 | + <!-- YAML | ||
| 1304 | + added: REPLACEME | ||
| 1305 | + --> | ||
| 1306 | + | ||
| 1307 | + The maximum number of test files that the test runner CLI will execute | ||
| 1308 | + concurrently. The default value is `os.availableParallelism() - 1`. | ||
| 1309 | + | ||
| 1301 | 1310 | ### `--test-name-pattern` | |
| 1302 | 1311 | ||
| 1303 | 1312 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -367,11 +367,12 @@ When searching for test files to execute, the test runner behaves as follows: | |||
| 367 | 367 | automatically executed by the test runner, but are supported if explicitly | |
| 368 | 368 | provided on the command line. | |
| 369 | 369 | ||
| 370 | - Each matching test file is executed in a separate child process. If the child | ||
| 371 | - process finishes with an exit code of 0, the test is considered passing. | ||
| 372 | - Otherwise, the test is considered to be a failure. Test files must be | ||
| 373 | - executable by Node.js, but are not required to use the `node:test` module | ||
| 374 | - internally. | ||
| 370 | + Each matching test file is executed in a separate child process. The maximum | ||
| 371 | + number of child processes running at any time is controlled by the | ||
| 372 | + [`--test-concurrency`][] flag. If the child process finishes with an exit code | ||
| 373 | + of 0, the test is considered passing. Otherwise, the test is considered to be a | ||
| 374 | + failure. Test files must be executable by Node.js, but are not required to use | ||
| 375 | + the `node:test` module internally. | ||
| 375 | 376 | ||
| 376 | 377 | Each test file is executed as if it was a regular script. That is, if the test | |
| 377 | 378 | file itself uses `node:test` to define tests, all of those tests will be | |
@@ -2449,6 +2450,7 @@ added: v18.7.0 | |||
| 2449 | 2450 | [TAP]: https://testanything.org/ | |
| 2450 | 2451 | [TTY]: tty.md | |
| 2451 | 2452 | [`--experimental-test-coverage`]: cli.md#--experimental-test-coverage | |
| 2453 | + [`--test-concurrency`]: cli.md#--test-concurrency | ||
| 2452 | 2454 | [`--test-name-pattern`]: cli.md#--test-name-pattern | |
| 2453 | 2455 | [`--test-only`]: cli.md#--test-only | |
| 2454 | 2456 | [`--test-reporter-destination`]: cli.md#--test-reporter-destination | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -400,6 +400,10 @@ Specify the minimum allocation from the OpenSSL secure heap. The default is 2. T | |||
| 400 | 400 | .It Fl -test | |
| 401 | 401 | Starts the Node.js command line test runner. | |
| 402 | 402 | . | |
| 403 | + .It Fl -test-concurrency | ||
| 404 | + The maximum number of test files that the test runner CLI will execute | ||
| 405 | + concurrently. | ||
| 406 | + . | ||
| 403 | 407 | .It Fl -test-name-pattern | |
| 404 | 408 | A regular expression that configures the test runner to only execute tests | |
| 405 | 409 | whose name matches the provided pattern. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ const { | |||
| 21 | 21 | prepareMainThreadExecution(false); | |
| 22 | 22 | markBootstrapComplete(); | |
| 23 | 23 | ||
| 24 | - let concurrency = true; | ||
| 24 | + let concurrency = getOptionValue('--test-concurrency') || true; | ||
| 25 | 25 | let inspectPort; | |
| 26 | 26 | ||
| 27 | 27 | if (isUsingInspector()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -570,6 +570,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 570 | 570 | AddOption("--test", | |
| 571 | 571 | "launch test runner on startup", | |
| 572 | 572 | &EnvironmentOptions::test_runner); | |
| 573 | + AddOption("--test-concurrency", | ||
| 574 | + "specify test runner concurrency", | ||
| 575 | + &EnvironmentOptions::test_runner_concurrency); | ||
| 573 | 576 | AddOption("--experimental-test-coverage", | |
| 574 | 577 | "enable code coverage in the test runner", | |
| 575 | 578 | &EnvironmentOptions::test_runner_coverage); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,6 +156,7 @@ class EnvironmentOptions : public Options { | |||
| 156 | 156 | std::string redirect_warnings; | |
| 157 | 157 | std::string diagnostic_dir; | |
| 158 | 158 | bool test_runner = false; | |
| 159 | + uint64_t test_runner_concurrency = 0; | ||
| 159 | 160 | bool test_runner_coverage = false; | |
| 160 | 161 | std::vector<std::string> test_name_pattern; | |
| 161 | 162 | std::vector<std::string> test_reporter; | |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments