@@ -6,7 +6,7 @@ const { spawnSync, spawn } = require('child_process');
66const { once } = require ( 'events' ) ;
77const { finished } = require ( 'stream/promises' ) ;
88
9- async function runAndKill ( file , expectedTestName ) {
9+ async function runAndKill ( file , expectedTestName , killSignal , expectedCode ) {
1010 if ( common . isWindows ) {
1111 common . printSkipMessage ( `signals are not supported in windows, skipping ${ file } ` ) ;
1212 return ;
@@ -15,17 +15,17 @@ async function runAndKill(file, expectedTestName) {
1515 const child = spawn ( process . execPath , [ '--test' , '--test-reporter=tap' , file ] ) ;
1616 child . stdout . setEncoding ( 'utf8' ) ;
1717 child . stdout . on ( 'data' , ( chunk ) => {
18- if ( ! stdout . length ) child . kill ( 'SIGINT' ) ;
18+ if ( ! stdout . length ) child . kill ( killSignal ) ;
1919 stdout += chunk ;
2020 } ) ;
21- const [ code , signal ] = await once ( child , 'exit' ) ;
21+ const [ code , exitSignal ] = await once ( child , 'exit' ) ;
2222 await finished ( child . stdout ) ;
2323 assert ( stdout . startsWith ( 'TAP version 13\n' ) ) ;
2424 // Verify interrupted test message
2525 assert ( stdout . includes ( `Interrupted while running: ${ expectedTestName } ` ) ,
2626 `Expected output to contain interrupted test name` ) ;
27- assert . strictEqual ( signal , null ) ;
28- assert . strictEqual ( code , 1 ) ;
27+ assert . strictEqual ( exitSignal , null ) ;
28+ assert . strictEqual ( code , expectedCode ) ;
2929}
3030
3131if ( process . argv [ 2 ] === 'child' ) {
@@ -82,6 +82,6 @@ if (process.argv[2] === 'child') {
8282 // because the parent runner only knows about file-level tests
8383 const neverEndingSync = fixtures . path ( 'test-runner' , 'never_ending_sync.js' ) ;
8484 const neverEndingAsync = fixtures . path ( 'test-runner' , 'never_ending_async.js' ) ;
85- runAndKill ( neverEndingSync , neverEndingSync ) . then ( common . mustCall ( ) ) ;
86- runAndKill ( neverEndingAsync , neverEndingAsync ) . then ( common . mustCall ( ) ) ;
85+ runAndKill ( neverEndingSync , neverEndingSync , 'SIGINT' , 130 ) . then ( common . mustCall ( ) ) ;
86+ runAndKill ( neverEndingAsync , neverEndingAsync , 'SIGTERM' , 143 ) . then ( common . mustCall ( ) ) ;
8787}
0 commit comments