@@ -149,13 +149,11 @@ export default testSuite(({ describe }, node: NodeApis) => {
149149 const signals = ${ JSON . stringify ( signals ) } ;
150150
151151 for (const name of signals) {
152- process.on(name, () => {
153- console.log(name);
154-
155- setTimeout(() => {
156- console.log(name, 'HANDLER COMPLETED');
152+ process.once(name, () => {
153+ console.log(name, 'PRESS AGAIN');
154+ process.once(name, () => {
157155 process.exit(200);
158- }, 200 );
156+ });
159157 });
160158 }
161159
@@ -203,6 +201,12 @@ export default testSuite(({ describe }, node: NodeApis) => {
203201 tsxProcess . kill ( signal , {
204202 forceKillAfterTimeout : false ,
205203 } ) ;
204+
205+ tsxProcess . stdout ! . once ( 'data' , ( ) => {
206+ tsxProcess . kill ( signal , {
207+ forceKillAfterTimeout : false ,
208+ } ) ;
209+ } ) ;
206210 } ) ;
207211
208212 const tsxProcessResolved = await tsxProcess ;
@@ -225,8 +229,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
225229 expect ( tsxProcessResolved . exitCode ) . toBe ( 200 ) ;
226230 expectMatchInOrder ( tsxProcessResolved . stdout , [
227231 'READY\n' ,
228- `${ signal } \n` ,
229- `${ signal } HANDLER COMPLETED` ,
232+ `${ signal } PRESS AGAIN` ,
230233 ] ) ;
231234 }
232235 } , {
@@ -306,53 +309,80 @@ export default testSuite(({ describe }, node: NodeApis) => {
306309 describe ( 'Ctrl + C' , ( { test } ) => {
307310 const CtrlC = '\u0003' ;
308311
309- test ( 'Exit code' , async ( ) => {
310- const output = await ptyShell (
311- [
312- // Windows doesn't support shebangs
313- `${ node . path } ${ tsxPath } ${ fixture . getPath ( 'keep-alive.js' ) } \r` ,
314- stdout => stdout . includes ( 'READY' ) && CtrlC ,
315- `echo EXIT_CODE: ${ isWindows ? '$LastExitCode' : '$?' } \r` ,
316- ] ,
317- ) ;
318- expect ( output ) . toMatch ( / E X I T _ C O D E : \s + 1 3 0 / ) ;
312+ test ( 'Exit code' , async ( { onTestFail } ) => {
313+ const p = ptyShell ( async ( shell ) => {
314+ await shell . waitForPrompt ( ) ;
315+ // Windows doesn't support shebangs
316+ shell . type ( `${ node . path } ${ tsxPath } ${ fixture . getPath ( 'keep-alive.js' ) } ` ) ;
317+
318+ await shell . waitForLine ( / R E A D Y / ) ;
319+ shell . press ( CtrlC ) ;
320+
321+ await shell . waitForPrompt ( ) ;
322+ shell . type ( `echo EXIT_CODE: ${ isWindows ? '$LastExitCode' : '$?' } ` ) ;
323+
324+ await shell . waitForPrompt ( ) ;
325+ } ) ;
326+
327+ onTestFail ( ( ) => {
328+ p . kill ( ) ;
329+ } ) ;
330+
331+ expect ( await p . output ) . toMatch ( / E X I T _ C O D E : \s + 1 3 0 / ) ;
319332 } , 10_000 ) ;
320333
321- test ( 'Catchable' , async ( ) => {
322- const output = await ptyShell (
323- [
324- // Windows doesn't support shebangs
325- `${ node . path } ${ tsxPath } ${ fixture . getPath ( 'catch-signals.js' ) } \r` ,
326- stdout => stdout . includes ( 'READY' ) && CtrlC ,
327- `echo EXIT_CODE: ${ isWindows ? '$LastExitCode' : '$?' } \r` ,
328- ] ,
329- 9000 ,
330- ) ;
331-
332- expectMatchInOrder ( output , [
334+ test ( 'Catchable' , async ( { onTestFail } ) => {
335+ const p = ptyShell ( async ( shell ) => {
336+ await shell . waitForPrompt ( ) ;
337+ shell . type ( `${ node . path } ${ tsxPath } ${ fixture . getPath ( 'catch-signals.js' ) } ` ) ;
338+
339+ await shell . waitForLine ( / R E A D Y / ) ;
340+ shell . press ( CtrlC ) ;
341+
342+ await shell . waitForLine ( / P R E S S A G A I N / ) ;
343+ shell . press ( CtrlC ) ;
344+
345+ await shell . waitForPrompt ( ) ;
346+ shell . type ( `echo EXIT_CODE: ${ isWindows ? '$LastExitCode' : '$?' } ` ) ;
347+
348+ await shell . waitForPrompt ( ) ;
349+ } ) ;
350+
351+ onTestFail ( ( ) => {
352+ p . kill ( ) ;
353+ } ) ;
354+
355+ expectMatchInOrder ( await p . output , [
333356 'READY\r\n' ,
334357 process . platform === 'win32' ? '' : '^C' ,
335- 'SIGINT\r\n' ,
336- 'SIGINT HANDLER COMPLETED\r\n' ,
358+ 'SIGINT PRESS AGAIN\r\n' ,
337359 / E X I T _ C O D E : \s + 2 0 0 / ,
338360 ] ) ;
339361 } , {
340362 timeout : 10_000 ,
341363 retry : 3 ,
342364 } ) ;
343365
344- test ( 'Infinite loop' , async ( ) => {
345- const output = await ptyShell (
346- [
347- // Windows doesn't support shebangs
348- `${ node . path } ${ tsxPath } ${ fixture . getPath ( 'infinite-loop.js' ) } \r` ,
349- stdout => / ^ \r ? \d + $ / . test ( stdout ) && CtrlC ,
350- `echo EXIT_CODE: ${ isWindows ? '$LastExitCode' : '$?' } \r` ,
351- ] ,
352- 9000 ,
353- ) ;
354-
355- expect ( output ) . toMatch ( / E X I T _ C O D E : \s + 1 3 0 / ) ;
366+ test ( 'Infinite loop' , async ( { onTestFail } ) => {
367+ const p = ptyShell ( async ( shell ) => {
368+ await shell . waitForPrompt ( ) ;
369+ // Windows doesn't support shebangs
370+ shell . type ( `${ node . path } ${ tsxPath } ${ fixture . getPath ( 'infinite-loop.js' ) } ` ) ;
371+
372+ await shell . waitForLine ( / ^ \r ? \d + $ / ) ;
373+ shell . press ( CtrlC ) ;
374+
375+ await shell . waitForPrompt ( ) ;
376+ shell . type ( `echo EXIT_CODE: ${ isWindows ? '$LastExitCode' : '$?' } ` ) ;
377+
378+ await shell . waitForPrompt ( ) ;
379+ } ) ;
380+
381+ onTestFail ( ( ) => {
382+ p . kill ( ) ;
383+ } ) ;
384+
385+ expect ( await p . output ) . toMatch ( / E X I T _ C O D E : \s + 1 3 0 / ) ;
356386 } , 10_000 ) ;
357387 } ) ;
358388 } ) ;
0 commit comments