Skip to content

Commit 04bba8d

Browse files
semimikohaduh95
authored andcommitted
test_runner: wait for filtered suite build
Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #64208 Fixes: #64203 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
1 parent 6eb33c2 commit 04bba8d

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

lib/internal/test_runner/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,11 @@ class Suite extends Test {
18541854
return { __proto__: null, ctx, args: [ctx] };
18551855
}
18561856

1857+
async filteredRun() {
1858+
await this.buildSuite;
1859+
return super.filteredRun();
1860+
}
1861+
18571862
async run() {
18581863
this.computeInheritedHooks();
18591864
const hookArgs = this.getRunArgs();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import test from 'node:test';
2+
import { setTimeout as delay } from 'node:timers/promises';
3+
4+
test.suite('Outer', async () => {
5+
await delay(1);
6+
7+
// This suite is filtered out by name. Its build is still pending when the
8+
// filtered run starts, so the subtest below is registered late.
9+
test.suite('Nested A', async () => {
10+
await delay(1);
11+
test('Nested A test', async () => {});
12+
});
13+
14+
test.suite('Nested C', async () => {
15+
test('Nested C test', async () => {});
16+
});
17+
});

test/parallel/test-runner-no-isolation-filtering.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const { test } = require('node:test');
77

88
const fixture1 = fixtures.path('test-runner', 'no-isolation', 'one.test.js');
99
const fixture2 = fixtures.path('test-runner', 'no-isolation', 'two.test.js');
10+
const asyncBuildFilteredSuite =
11+
fixtures.path('test-runner', 'filtered-suite-async-build.mjs');
1012

1113
test('works with --test-only', () => {
1214
const args = [
@@ -71,6 +73,27 @@ test('works with --test-name-pattern', () => {
7173
assert.match(stdout, /# suites 0/);
7274
});
7375

76+
test('filtered suites with an async build do not leave cancelled tests', () => {
77+
const args = [
78+
'--test',
79+
'--test-reporter=tap',
80+
'--test-isolation=none',
81+
'--test-name-pattern=C',
82+
asyncBuildFilteredSuite,
83+
];
84+
const child = spawnSync(process.execPath, args);
85+
const stdout = child.stdout.toString();
86+
87+
assert.strictEqual(child.status, 0);
88+
assert.strictEqual(child.signal, null);
89+
assert.match(stdout, /# tests 1/);
90+
assert.match(stdout, /# suites 2/);
91+
assert.match(stdout, /# pass 1/);
92+
assert.match(stdout, /# fail 0/);
93+
assert.match(stdout, /# cancelled 0/);
94+
assert.doesNotMatch(stdout, /parentAlreadyFinished/);
95+
});
96+
7497
test('works with --test-skip-pattern', () => {
7598
const args = [
7699
'--test',

0 commit comments

Comments
 (0)