Skip to content

Commit 97d854e

Browse files
cjihrigaduh95
authored andcommitted
test_runner,cli: mark test isolation as stable
This commit stabilizes test isolation configuration in the test runner. PR-URL: #56298 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
1 parent e4b795e commit 97d854e

14 files changed

+55
-48
lines changed

doc/api/cli.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -1037,20 +1037,6 @@ generated as part of the test runner output. If no tests are run, a coverage
10371037
report is not generated. See the documentation on
10381038
[collecting code coverage from tests][] for more details.
10391039

1040-
### `--experimental-test-isolation=mode`
1041-
1042-
<!-- YAML
1043-
added: v22.8.0
1044-
-->
1045-
1046-
> Stability: 1.0 - Early development
1047-
1048-
Configures the type of test isolation used in the test runner. When `mode` is
1049-
`'process'`, each test file is run in a separate child process. When `mode` is
1050-
`'none'`, all test files run in the same process as the test runner. The default
1051-
isolation mode is `'process'`. This flag is ignored if the `--test` flag is not
1052-
present. See the [test runner execution model][] section for more information.
1053-
10541040
### `--experimental-test-module-mocks`
10551041

10561042
<!-- YAML
@@ -2235,8 +2221,8 @@ added:
22352221
-->
22362222

22372223
The maximum number of test files that the test runner CLI will execute
2238-
concurrently. If `--experimental-test-isolation` is set to `'none'`, this flag
2239-
is ignored and concurrency is one. Otherwise, concurrency defaults to
2224+
concurrently. If `--test-isolation` is set to `'none'`, this flag is ignored and
2225+
concurrency is one. Otherwise, concurrency defaults to
22402226
`os.availableParallelism() - 1`.
22412227

22422228
### `--test-coverage-branches=threshold`
@@ -2320,6 +2306,23 @@ added:
23202306
Configures the test runner to exit the process once all known tests have
23212307
finished executing even if the event loop would otherwise remain active.
23222308

2309+
### `--test-isolation=mode`
2310+
2311+
<!-- YAML
2312+
added: v22.8.0
2313+
changes:
2314+
- version: REPLACEME
2315+
pr-url: https://github.com/nodejs/node/pull/56298
2316+
description: This flag was renamed from `--experimental-test-isolation` to
2317+
`--test-isolation`.
2318+
-->
2319+
2320+
Configures the type of test isolation used in the test runner. When `mode` is
2321+
`'process'`, each test file is run in a separate child process. When `mode` is
2322+
`'none'`, all test files run in the same process as the test runner. The default
2323+
isolation mode is `'process'`. This flag is ignored if the `--test` flag is not
2324+
present. See the [test runner execution model][] section for more information.
2325+
23232326
### `--test-name-pattern`
23242327

23252328
<!-- YAML
@@ -3056,6 +3059,7 @@ one is included in the list below.
30563059
* `--experimental-shadow-realm`
30573060
* `--experimental-specifier-resolution`
30583061
* `--experimental-strip-types`
3062+
* `--experimental-test-isolation`
30593063
* `--experimental-top-level-await`
30603064
* `--experimental-transform-types`
30613065
* `--experimental-vm-modules`
@@ -3125,6 +3129,7 @@ one is included in the list below.
31253129
* `--test-coverage-functions`
31263130
* `--test-coverage-include`
31273131
* `--test-coverage-lines`
3132+
* `--test-isolation`
31283133
* `--test-name-pattern`
31293134
* `--test-only`
31303135
* `--test-reporter-destination`

doc/node.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ Use this flag to enable ShadowRealm support.
180180
.It Fl -experimental-test-coverage
181181
Enable code coverage in the test runner.
182182
.
183-
.It Fl -experimental-test-isolation Ns = Ns Ar mode
184-
Configures the type of test isolation used in the test runner.
185-
.
186183
.It Fl -experimental-test-module-mocks
187184
Enable module mocking in the test runner.
188185
.
@@ -455,6 +452,9 @@ Require a minimum threshold for line coverage (0 - 100).
455452
Configures the test runner to exit the process once all known tests have
456453
finished executing even if the event loop would otherwise remain active.
457454
.
455+
.It Fl -test-isolation Ns = Ns Ar mode
456+
Configures the type of test isolation used in the test runner.
457+
.
458458
.It Fl -test-name-pattern
459459
A regular expression that configures the test runner to only execute tests
460460
whose name matches the provided pattern.

lib/internal/test_runner/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function parseCommandLine() {
241241
}
242242

243243
if (isTestRunner) {
244-
isolation = getOptionValue('--experimental-test-isolation');
244+
isolation = getOptionValue('--test-isolation');
245245
timeout = getOptionValue('--test-timeout') || Infinity;
246246

247247
if (isolation === 'none') {

src/node_options.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
145145
debug_options_.allow_attaching_debugger = true;
146146
} else {
147147
if (test_isolation != "process") {
148-
errors->push_back("invalid value for --experimental-test-isolation");
148+
errors->push_back("invalid value for --test-isolation");
149149
}
150150

151151
#ifndef ALLOW_ATTACHING_DEBUGGER_IN_TEST_RUNNER
@@ -683,10 +683,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
683683
"the line coverage minimum threshold",
684684
&EnvironmentOptions::test_coverage_lines,
685685
kAllowedInEnvvar);
686-
687-
AddOption("--experimental-test-isolation",
686+
AddOption("--test-isolation",
688687
"configures the type of test isolation used in the test runner",
689-
&EnvironmentOptions::test_isolation);
688+
&EnvironmentOptions::test_isolation,
689+
kAllowedInEnvvar);
690+
// TODO(cjihrig): Remove this alias in a semver major.
691+
AddAlias("--experimental-test-isolation", "--test-isolation");
690692
AddOption("--experimental-test-module-mocks",
691693
"enable module mocking in the test runner",
692694
&EnvironmentOptions::test_runner_module_mocks);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ test('concurrency of two', async () => {
2626
});
2727

2828
test('isolation=none uses a concurrency of one', async () => {
29-
const args = ['--test', '--experimental-test-isolation=none'];
29+
const args = ['--test', '--test-isolation=none'];
3030
const cp = spawnSync(process.execPath, args, { cwd, env });
3131
assert.match(cp.stderr.toString(), /concurrency: 1,/);
3232
});
3333

3434
test('isolation=none overrides --test-concurrency', async () => {
3535
const args = [
36-
'--test', '--experimental-test-isolation=none', '--test-concurrency=2',
36+
'--test', '--test-isolation=none', '--test-concurrency=2',
3737
];
3838
const cp = spawnSync(process.execPath, args, { cwd, env });
3939
assert.match(cp.stderr.toString(), /concurrency: 1,/);

test/parallel/test-runner-cli-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('timeout of 10ms', async () => {
2121

2222
test('isolation=none uses the --test-timeout flag', async () => {
2323
const args = [
24-
'--test', '--experimental-test-isolation=none', '--test-timeout=10',
24+
'--test', '--test-isolation=none', '--test-timeout=10',
2525
];
2626
const cp = spawnSync(process.execPath, args, { cwd, env });
2727
assert.match(cp.stderr.toString(), /timeout: 10,/);

test/parallel/test-runner-cli.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ for (const isolation of ['none', 'process']) {
1212
// File not found.
1313
const args = [
1414
'--test',
15-
`--experimental-test-isolation=${isolation}`,
15+
`--test-isolation=${isolation}`,
1616
'a-random-file-that-does-not-exist.js',
1717
];
1818
const child = spawnSync(process.execPath, args);
@@ -27,7 +27,7 @@ for (const isolation of ['none', 'process']) {
2727
// Default behavior. node_modules is ignored. Files that don't match the
2828
// pattern are ignored except in test/ directories.
2929
const args = ['--test', '--test-reporter=tap',
30-
`--experimental-test-isolation=${isolation}`];
30+
`--test-isolation=${isolation}`];
3131
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });
3232

3333
assert.strictEqual(child.status, 1);
@@ -46,7 +46,7 @@ for (const isolation of ['none', 'process']) {
4646
{
4747
// Should match files with "-test.(c|m)js" suffix.
4848
const args = ['--test', '--test-reporter=tap',
49-
`--experimental-test-isolation=${isolation}`];
49+
`--test-isolation=${isolation}`];
5050
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') });
5151

5252
assert.strictEqual(child.status, 0);
@@ -64,7 +64,7 @@ for (const isolation of ['none', 'process']) {
6464
for (const type of ['strip', 'transform']) {
6565
// Should match files with "-test.(c|m)(t|j)s" suffix when typescript support is enabled
6666
const args = ['--test', '--test-reporter=tap', '--no-warnings',
67-
`--experimental-${type}-types`, `--experimental-test-isolation=${isolation}`];
67+
`--experimental-${type}-types`, `--test-isolation=${isolation}`];
6868
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'matching-patterns') });
6969

7070
if (!process.config.variables.node_use_amaro) {
@@ -91,7 +91,7 @@ for (const isolation of ['none', 'process']) {
9191
'--require', join(testFixtures, 'protoMutation.js'),
9292
'--test',
9393
'--test-reporter=tap',
94-
`--experimental-test-isolation=${isolation}`,
94+
`--test-isolation=${isolation}`,
9595
];
9696
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });
9797

@@ -112,7 +112,7 @@ for (const isolation of ['none', 'process']) {
112112
const args = [
113113
'--test',
114114
'--test-reporter=tap',
115-
`--experimental-test-isolation=${isolation}`,
115+
`--test-isolation=${isolation}`,
116116
join(testFixtures, 'index.js'),
117117
];
118118
const child = spawnSync(process.execPath, args, { cwd: testFixtures });
@@ -129,7 +129,7 @@ for (const isolation of ['none', 'process']) {
129129
const args = [
130130
'--test',
131131
'--test-reporter=tap',
132-
`--experimental-test-isolation=${isolation}`,
132+
`--test-isolation=${isolation}`,
133133
join(testFixtures, 'default-behavior/node_modules/*.js'),
134134
];
135135
const child = spawnSync(process.execPath, args);
@@ -143,7 +143,7 @@ for (const isolation of ['none', 'process']) {
143143

144144
{
145145
// The current directory is used by default.
146-
const args = ['--test', `--experimental-test-isolation=${isolation}`];
146+
const args = ['--test', `--test-isolation=${isolation}`];
147147
const options = { cwd: join(testFixtures, 'default-behavior') };
148148
const child = spawnSync(process.execPath, args, options);
149149

@@ -165,7 +165,7 @@ for (const isolation of ['none', 'process']) {
165165
const args = [
166166
'--test',
167167
'--test-reporter=tap',
168-
`--experimental-test-isolation=${isolation}`,
168+
`--test-isolation=${isolation}`,
169169
'test/fixtures/test-runner/default-behavior/index.test.js',
170170
'test/fixtures/test-runner/nested.js',
171171
'test/fixtures/test-runner/invalid-tap.js',

test/parallel/test-runner-coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ test.skip('coverage works with isolation=none', skipIfNoInspector, () => {
260260
'--experimental-test-coverage',
261261
'--test-reporter',
262262
'tap',
263-
'--experimental-test-isolation=none',
263+
'--test-isolation=none',
264264
];
265265
const result = spawnSync(process.execPath, args, {
266266
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },

test/parallel/test-runner-extraneous-async-activity.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const { spawnSync } = require('child_process');
5252
{
5353
const child = spawnSync(process.execPath, [
5454
'--test',
55-
'--experimental-test-isolation=none',
55+
'--test-isolation=none',
5656
fixtures.path('test-runner', 'async-error-in-test-hook.mjs'),
5757
]);
5858
const stdout = child.stdout.toString();

test/parallel/test-runner-force-exit-failure.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ for (const isolation of ['none', 'process']) {
1010
'--test',
1111
'--test-reporter=spec',
1212
'--test-force-exit',
13-
`--experimental-test-isolation=${isolation}`,
13+
`--test-isolation=${isolation}`,
1414
fixture,
1515
];
1616
const r = spawnSync(process.execPath, args);

test/parallel/test-runner-no-isolation-filtering.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('works with --test-only', () => {
1212
const args = [
1313
'--test',
1414
'--test-reporter=tap',
15-
'--experimental-test-isolation=none',
15+
'--test-isolation=none',
1616
'--test-only',
1717
fixture1,
1818
fixture2,
@@ -35,7 +35,7 @@ test('works without --test-only', () => {
3535
const args = [
3636
'--test',
3737
'--test-reporter=tap',
38-
'--experimental-test-isolation=none',
38+
'--test-isolation=none',
3939
fixture1,
4040
fixture2,
4141
];
@@ -57,7 +57,7 @@ test('works with --test-name-pattern', () => {
5757
const args = [
5858
'--test',
5959
'--test-reporter=tap',
60-
'--experimental-test-isolation=none',
60+
'--test-isolation=none',
6161
'--test-name-pattern=/test one/',
6262
fixture1,
6363
fixture2,
@@ -75,7 +75,7 @@ test('works with --test-skip-pattern', () => {
7575
const args = [
7676
'--test',
7777
'--test-reporter=tap',
78-
'--experimental-test-isolation=none',
78+
'--test-isolation=none',
7979
'--test-skip-pattern=/one/',
8080
fixture1,
8181
fixture2,

test/parallel/test-runner-no-isolation-hooks.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { test } from 'node:test';
44

55
const testArguments = [
66
'--test',
7-
'--experimental-test-isolation=none',
7+
'--test-isolation=none',
88
];
99

1010
const testFiles = [

test/parallel/test-runner-snapshot-tests.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ test('snapshots from multiple files (isolation=none)', async (t) => {
349349
await t.test('fails prior to snapshot generation', async (t) => {
350350
const args = [
351351
'--test',
352-
'--experimental-test-isolation=none',
352+
'--test-isolation=none',
353353
fixture,
354354
fixture2,
355355
];
@@ -370,7 +370,7 @@ test('snapshots from multiple files (isolation=none)', async (t) => {
370370
await t.test('passes when regenerating snapshots', async (t) => {
371371
const args = [
372372
'--test',
373-
'--experimental-test-isolation=none',
373+
'--test-isolation=none',
374374
'--test-update-snapshots',
375375
fixture,
376376
fixture2,
@@ -391,7 +391,7 @@ test('snapshots from multiple files (isolation=none)', async (t) => {
391391
await t.test('passes when snapshots exist', async (t) => {
392392
const args = [
393393
'--test',
394-
'--experimental-test-isolation=none',
394+
'--test-isolation=none',
395395
fixture,
396396
fixture2,
397397
];

test/parallel/test-runner-watch-mode.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function testWatch({
4747
const ran2 = Promise.withResolvers();
4848
const child = spawn(process.execPath,
4949
['--watch', '--test', '--test-reporter=spec',
50-
isolation ? `--experimental-test-isolation=${isolation}` : '',
50+
isolation ? `--test-isolation=${isolation}` : '',
5151
file ? fixturePaths[file] : undefined].filter(Boolean),
5252
{ encoding: 'utf8', stdio: 'pipe', cwd: tmpdir.path });
5353
let stdout = '';

0 commit comments

Comments
 (0)