Skip to content

Commit

Permalink
test_runner: detect only tests when isolation is off
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and RafaelGSS committed Sep 17, 2024
1 parent 021f59b commit 3396a49
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
8 changes: 4 additions & 4 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-runner-no-isolation-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
9 changes: 0 additions & 9 deletions test/parallel/test-runner-no-isolation-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,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',
Expand Down

0 comments on commit 3396a49

Please sign in to comment.