Skip to content

Commit f5f67ae

Browse files
committed
test_runner: detect only tests when isolation is off
This commit updates the way the test runner processes 'only' tests when process-based test isolation is disabled. The --test-only flag is no longer necessary in this scenario. The test runner will automatically detect 'only' tests and apply the appropriate filtering. PR-URL: #54832 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent e78fd8c commit f5f67ae

File tree

5 files changed

+8
-18
lines changed

5 files changed

+8
-18
lines changed

doc/api/cli.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ changes:
23362336
-->
23372337

23382338
Configures the test runner to only execute top level tests that have the `only`
2339-
option set.
2339+
option set. This flag is not necessary when test isolation is disabled.
23402340

23412341
### `--test-reporter`
23422342

doc/api/test.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ const { describe, it } = require('node:test');
229229

230230
## `only` tests
231231

232-
If Node.js is started with the [`--test-only`][] command-line option, it is
233-
possible to skip all tests except for a selected subset by passing
234-
the `only` option to the tests that should run. When a test with the `only`
235-
option is set, all subtests are also run.
232+
If Node.js is started with the [`--test-only`][] command-line option, or test
233+
isolation is disabled, it is possible to skip all tests except for a selected
234+
subset by passing the `only` option to the tests that should run. When a test
235+
with the `only` option is set, all subtests are also run.
236236
If a suite has the `only` option set, all tests within the suite are run,
237237
unless it has descendants with the `only` option set, in which case only those
238238
tests are run.

lib/internal/test_runner/harness.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function createTestTree(rootTestOptions, globalOptions) {
3838
const buildPhaseDeferred = createDeferredPromise();
3939
const isFilteringByName = globalOptions.testNamePatterns ||
4040
globalOptions.testSkipPatterns;
41-
const isFilteringByOnly = globalOptions.only;
41+
const isFilteringByOnly = globalOptions.only || (globalOptions.isTestRunner &&
42+
globalOptions.isolation === 'none');
4243
const harness = {
4344
__proto__: null,
4445
buildPromise: buildPhaseDeferred.promise,

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ test('works with --test-name-pattern', () => {
4545

4646
assert.strictEqual(child.status, 0);
4747
assert.strictEqual(child.signal, null);
48-
assert.match(stdout, /# tests 1/);
48+
assert.match(stdout, /# tests 0/);
4949
assert.match(stdout, /# suites 0/);
50-
assert.match(stdout, /# pass 1/);
51-
assert.match(stdout, /ok 1 - test one/);
5250
});
5351

5452
test('works with --test-skip-pattern', () => {

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

-9
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ const order = [
3030
'afterEach one: suite one - test',
3131
'afterEach two: suite one - test',
3232

33-
'beforeEach(): global',
34-
'beforeEach one: test one',
35-
'beforeEach two: test one',
36-
'test one',
37-
38-
'afterEach(): global',
39-
'afterEach one: test one',
40-
'afterEach two: test one',
41-
4233
'before suite two: suite two',
4334
'beforeEach(): global',
4435
'beforeEach one: suite two - test',

0 commit comments

Comments
 (0)