Skip to content

Commit 7cdda92

Browse files
pmarchiniRafaelGSS
authored andcommitted
test: fix test-timeout-flag after revert of auto subtest wait
PR-URL: #58282Fixes: #58227 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent dce1995 commit 7cdda92

2 files changed

Lines changed: 39 additions & 12 deletions

File tree

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
// Flags: --test-timeout=20
21
'use strict';
3-
const{ describe, test }=require('node:test');
4-
const{ setTimeout }=require('node:timers/promises');
2+
const{ describe, it, after }=require('node:test');
3+
const{ setTimeout }=require('node:timers');
4+
5+
consttimeoutRefs=[];
56

67
describe('--test-timeout is set to 20ms',()=>{
7-
test('should timeout after 20ms',async()=>{
8-
awaitsetTimeout(200000,undefined,{ref: false});
8+
it('should timeout after 20ms',async()=>{
9+
const{ promise, resolve }=Promise.withResolvers();
10+
timeoutRefs.push(setTimeout(()=>{
11+
resolve();
12+
},20000));
13+
awaitpromise;
914
});
10-
test('should timeout after 5ms',{timeout: 5},async()=>{
11-
awaitsetTimeout(200000,undefined,{ref: false});
15+
16+
it('should timeout after 5ms',{timeout: 5},async()=>{
17+
const{ promise, resolve }=Promise.withResolvers();
18+
timeoutRefs.push(setTimeout(()=>{
19+
resolve();
20+
},20000));
21+
awaitpromise;
1222
});
1323

14-
test('should not timeout',{timeout: 50000},async()=>{
15-
awaitsetTimeout(1);
24+
it('should not timeout',{timeout: 50000},async()=>{
25+
const{ promise, resolve }=Promise.withResolvers();
26+
timeoutRefs.push(setTimeout(()=>{
27+
resolve();
28+
},1));
29+
awaitpromise;
1630
});
1731

18-
test('should pass',async()=>{});
32+
it('should pass',async()=>{});
33+
34+
after(()=>{
35+
for(consttimeoutRefoftimeoutRefs){
36+
clearTimeout(timeoutRef);
37+
}
38+
});
1939
});

‎test/parallel/test-runner-output.mjs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ const tests = [
134134
},
135135
{
136136
name: 'test-runner/output/test-timeout-flag.js',
137-
flags: ['--test-reporter=tap'],
137+
flags: [
138+
'--test-reporter=tap',
139+
'--test-timeout=20',
140+
],
138141
},
139142
// --test-timeout should work with or without --test flag
140143
{
141144
name: 'test-runner/output/test-timeout-flag.js',
142-
flags: ['--test-reporter=tap','--test'],
145+
flags: [
146+
'--test-reporter=tap',
147+
'--test-timeout=20',
148+
'--test',
149+
],
143150
},
144151
{
145152
name: 'test-runner/output/hooks-with-no-global-test.js',

0 commit comments

Comments
 (0)