|
1 | | -// Flags: --test-timeout=20 |
2 | 1 | '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=[]; |
5 | 6 |
|
6 | 7 | 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; |
9 | 14 | }); |
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; |
12 | 22 | }); |
13 | 23 |
|
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; |
16 | 30 | }); |
17 | 31 |
|
18 | | -test('should pass',async()=>{}); |
| 32 | +it('should pass',async()=>{}); |
| 33 | + |
| 34 | +after(()=>{ |
| 35 | +for(consttimeoutRefoftimeoutRefs){ |
| 36 | +clearTimeout(timeoutRef); |
| 37 | +} |
| 38 | +}); |
19 | 39 | }); |
0 commit comments