From dfcfe4503ca1d2e735d8d4d4ffb2b7d8b5437ca6 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 5 Sep 2024 17:42:37 -0400 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/54832 Reviewed-By: Chemi Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Moshe Atlow --- doc/api/cli.md | 2 +- doc/api/test.md | 8 ++++---- lib/internal/test_runner/harness.js | 3 ++- test/parallel/test-runner-no-isolation-filtering.js | 4 +--- test/parallel/test-runner-no-isolation-hooks.mjs | 9 --------- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index f36429db147ab5..a58ac7365eca31 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2334,7 +2334,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 43f494c0e45bc1..02c34d9437ca1a 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 f91cc4f8592aec..50ecb290bfa65a 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 21db267d5323c6..b99b4783ddcc1c 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 2c1570d2d75514..ce7b1388e92425 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',