Skip to content

Commit 4368303

Browse files
semimikohaduh95
authored andcommitted
test_runner: wait for filtered suite build
Signed-off-by: semimikoh <ejffjeosms@gmail.com> PR-URL: #64208Fixes: #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 d7266cd commit 4368303

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+
asyncfilteredRun(){
1858+
awaitthis.buildSuite;
1859+
returnsuper.filteredRun();
1860+
}
1861+
18571862
asyncrun(){
18581863
this.computeInheritedHooks();
18591864
consthookArgs=this.getRunArgs();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
importtestfrom'node:test';
2+
import{setTimeoutasdelay}from'node:timers/promises';
3+
4+
test.suite('Outer',async()=>{
5+
awaitdelay(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+
awaitdelay(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
constfixture1=fixtures.path('test-runner','no-isolation','one.test.js');
99
constfixture2=fixtures.path('test-runner','no-isolation','two.test.js');
10+
constasyncBuildFilteredSuite=
11+
fixtures.path('test-runner','filtered-suite-async-build.mjs');
1012

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

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

0 commit comments

Comments
 (0)