1
1
'use strict' ;
2
- require ( '../common' ) ;
2
+ const common = require ( '../common' ) ;
3
3
const assert = require ( 'assert' ) ;
4
4
const { spawnSync } = require ( 'child_process' ) ;
5
+ const { setTimeout } = require ( 'timers/promises' ) ;
5
6
6
7
if ( process . argv [ 2 ] === 'child' ) {
7
8
const test = require ( 'node:test' ) ;
@@ -10,12 +11,18 @@ if (process.argv[2] === 'child') {
10
11
test ( 'passing test' , ( ) => {
11
12
assert . strictEqual ( true , true ) ;
12
13
} ) ;
13
- } else {
14
+ } else if ( process . argv [ 3 ] === 'fail' ) {
14
15
assert . strictEqual ( process . argv [ 3 ] , 'fail' ) ;
15
16
test ( 'failing test' , ( ) => {
16
17
assert . strictEqual ( true , false ) ;
17
18
} ) ;
18
- }
19
+ } else if ( process . argv [ 3 ] === 'never_ends' ) {
20
+ assert . strictEqual ( process . argv [ 3 ] , 'never_ends' ) ;
21
+ test ( 'never ending test' , ( ) => {
22
+ return setTimeout ( 100_000_000 ) ;
23
+ } ) ;
24
+ process . kill ( process . pid , 'SIGINT' ) ;
25
+ } else assert . fail ( 'unreachable' ) ;
19
26
} else {
20
27
let child = spawnSync ( process . execPath , [ __filename , 'child' , 'pass' ] ) ;
21
28
assert . strictEqual ( child . status , 0 ) ;
@@ -24,4 +31,15 @@ if (process.argv[2] === 'child') {
24
31
child = spawnSync ( process . execPath , [ __filename , 'child' , 'fail' ] ) ;
25
32
assert . strictEqual ( child . status , 1 ) ;
26
33
assert . strictEqual ( child . signal , null ) ;
34
+
35
+ child = spawnSync ( process . execPath , [ __filename , 'child' , 'never_ends' ] ) ;
36
+ assert . strictEqual ( child . status , 1 ) ;
37
+ assert . strictEqual ( child . signal , null ) ;
38
+ if ( common . isWindows ) {
39
+ common . printSkipMessage ( 'signals are not supported in windows' ) ;
40
+ } else {
41
+ const stdout = child . stdout . toString ( ) ;
42
+ assert . match ( stdout , / n o t o k 1 - n e v e r e n d i n g t e s t / ) ;
43
+ assert . match ( stdout , / # c a n c e l l e d 1 / ) ;
44
+ }
27
45
}
0 commit comments