diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index d19d6349f104bf..ce493dbef6fe53 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -1839,6 +1839,11 @@ class Suite extends Test { return { __proto__: null, ctx, args: [ctx] }; } + async filteredRun() { + await this.buildSuite; + return super.filteredRun(); + } + async run() { this.computeInheritedHooks(); const hookArgs = this.getRunArgs(); diff --git a/test/fixtures/test-runner/awaited-filtered-suite.mjs b/test/fixtures/test-runner/awaited-filtered-suite.mjs new file mode 100644 index 00000000000000..8af8d191d787cf --- /dev/null +++ b/test/fixtures/test-runner/awaited-filtered-suite.mjs @@ -0,0 +1,12 @@ +import test from 'node:test'; + +await test.suite('Suite A', async () => {}); + +await test.suite('Suite B', async () => { + await test('Test 1', async () => {}); + await test('Test 2', async () => {}); +}); + +await test.suite('Suite C', async () => { + await test('Test 3', async () => {}); +}); diff --git a/test/parallel/test-runner-no-isolation-filtering.js b/test/parallel/test-runner-no-isolation-filtering.js index e26130c56b196d..6b9b29bfef1ee2 100644 --- a/test/parallel/test-runner-no-isolation-filtering.js +++ b/test/parallel/test-runner-no-isolation-filtering.js @@ -7,6 +7,8 @@ const { test } = require('node:test'); const fixture1 = fixtures.path('test-runner', 'no-isolation', 'one.test.js'); const fixture2 = fixtures.path('test-runner', 'no-isolation', 'two.test.js'); +const awaitedFilteredSuite = + fixtures.path('test-runner', 'awaited-filtered-suite.mjs'); test('works with --test-only', () => { const args = [ @@ -71,6 +73,26 @@ test('works with --test-name-pattern', () => { assert.match(stdout, /# suites 0/); }); +test('awaited filtered suites do not leave cancelled tests', () => { + const args = [ + '--test', + '--test-reporter=tap', + '--test-isolation=none', + '--test-name-pattern=C', + awaitedFilteredSuite, + ]; + const child = spawnSync(process.execPath, args); + const stdout = child.stdout.toString(); + + assert.strictEqual(child.status, 0); + assert.strictEqual(child.signal, null); + assert.match(stdout, /# tests 2/); + assert.match(stdout, /# suites 1/); + assert.match(stdout, /# pass 1/); + assert.match(stdout, /# fail 0/); + assert.match(stdout, /# cancelled 0/); +}); + test('works with --test-skip-pattern', () => { const args = [ '--test',