Skip to content

Commit 3396a49

Browse files
cjihrigRafaelGSS
authored andcommitted
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 <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 021f59b commit 3396a49

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
@@ -2334,7 +2334,7 @@ changes:
23342334
-->
23352335

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

23392339
### `--test-reporter`
23402340

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
@@ -31,15 +31,6 @@ const order = [
3131
'afterEach one: suite one - test',
3232
'afterEach two: suite one - test',
3333

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

0 commit comments

Comments
 (0)