diff --git a/doc/api/cli.md b/doc/api/cli.md index 01efb97e31b..4028e0d374b 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2336,7 +2336,7 @@ changes: --> Configures the test runner to only execute top level tests that have the `only` -option set. +option set. This flag is not necessary when test isolation is disabled. ### `--test-reporter` diff --git a/doc/api/test.md b/doc/api/test.md index 19819202d1d..82cba9842aa 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -229,10 +229,10 @@ const { describe, it } = require('node:test'); ## `only` tests -If Node.js is started with the [`--test-only`][] command-line option, it is -possible to skip all tests except for a selected subset by passing -the `only` option to the tests that should run. When a test with the `only` -option is set, all subtests are also run. +If Node.js is started with the [`--test-only`][] command-line option, or test +isolation is disabled, it is possible to skip all tests except for a selected +subset by passing the `only` option to the tests that should run. When a test +with the `only` option is set, all subtests are also run. If a suite has the `only` option set, all tests within the suite are run, unless it has descendants with the `only` option set, in which case only those tests are run. diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index f91cc4f8592..50ecb290bfa 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -38,7 +38,8 @@ function createTestTree(rootTestOptions, globalOptions) { const buildPhaseDeferred = createDeferredPromise(); const isFilteringByName = globalOptions.testNamePatterns || globalOptions.testSkipPatterns; - const isFilteringByOnly = globalOptions.only; + const isFilteringByOnly = globalOptions.only || (globalOptions.isTestRunner && + globalOptions.isolation === 'none'); const harness = { __proto__: null, buildPromise: buildPhaseDeferred.promise, diff --git a/test/parallel/test-runner-no-isolation-filtering.js b/test/parallel/test-runner-no-isolation-filtering.js index 21db267d532..b99b4783ddc 100644 --- a/test/parallel/test-runner-no-isolation-filtering.js +++ b/test/parallel/test-runner-no-isolation-filtering.js @@ -45,10 +45,8 @@ test('works with --test-name-pattern', () => { assert.strictEqual(child.status, 0); assert.strictEqual(child.signal, null); - assert.match(stdout, /# tests 1/); + assert.match(stdout, /# tests 0/); assert.match(stdout, /# suites 0/); - assert.match(stdout, /# pass 1/); - assert.match(stdout, /ok 1 - test one/); }); test('works with --test-skip-pattern', () => { diff --git a/test/parallel/test-runner-no-isolation-hooks.mjs b/test/parallel/test-runner-no-isolation-hooks.mjs index 2c1570d2d75..ce7b1388e92 100644 --- a/test/parallel/test-runner-no-isolation-hooks.mjs +++ b/test/parallel/test-runner-no-isolation-hooks.mjs @@ -30,15 +30,6 @@ const order = [ 'afterEach one: suite one - test', 'afterEach two: suite one - test', - 'beforeEach(): global', - 'beforeEach one: test one', - 'beforeEach two: test one', - 'test one', - - 'afterEach(): global', - 'afterEach one: test one', - 'afterEach two: test one', - 'before suite two: suite two', 'beforeEach(): global', 'beforeEach one: suite two - test',