File tree Expand file tree Collapse file tree 3 files changed +27
-23
lines changed Expand file tree Collapse file tree 3 files changed +27
-23
lines changed Original file line number Diff line number Diff line change 11import { join } from 'node:path' ;
2- import { expect , it } from '@rstest/core' ;
2+ import { it } from '@rstest/core' ;
33import { runRstestCli } from '../../scripts/' ;
44
5- it ( 'should exit correctly when signal listener exists' , async ( ) => {
6- const { cli, expectExecSuccess } = await runRstestCli ( {
7- command : 'rstest' ,
8- args : [ 'run' , 'signalListener.test.ts' ] ,
9- options : {
10- nodeOptions : {
11- cwd : join ( __dirname , 'fixtures' ) ,
5+ it . skipIf ( process . platform === 'win32' ) (
6+ 'should catch signal exit correctly when signal listener exists' ,
7+ async ( ) => {
8+ const { expectExecFailed, expectLog } = await runRstestCli ( {
9+ command : 'rstest' ,
10+ args : [ 'run' , 'signalListener.test.ts' ] ,
11+ options : {
12+ nodeOptions : {
13+ cwd : join ( __dirname , 'fixtures' ) ,
14+ } ,
1215 } ,
13- } ,
14- } ) ;
15- await expectExecSuccess ( ) ;
16+ } ) ;
17+ await expectExecFailed ( ) ;
1618
17- const logs = cli . stdout . split ( '\n' ) . filter ( Boolean ) ;
18-
19- expect ( logs . find ( ( log ) => log . includes ( 'Test Files 1 passed' ) ) ) . toBeDefined ( ) ;
20- } ) ;
19+ expectLog ( / R s t e s t e x i t e d u n e x p e c t e d l y w i t h c o d e 0 / ) ;
20+ } ,
21+ ) ;
Original file line number Diff line number Diff line change @@ -448,8 +448,19 @@ export async function runTests(context: Rstest): Promise<void> {
448448 afterTestsWatchRun ( ) ;
449449 } ) ;
450450 } else {
451+ const unExpectedExit = ( code ?: number ) => {
452+ logger . log (
453+ color . red (
454+ `Rstest exited unexpectedly with code ${ code } , terminating test run.` ,
455+ ) ,
456+ ) ;
457+ process . exitCode = 1 ;
458+ } ;
459+ process . on ( 'exit' , unExpectedExit ) ;
460+
451461 await run ( ) ;
452462 await pool . close ( ) ;
453463 await closeServer ( ) ;
464+ process . off ( 'exit' , unExpectedExit ) ;
454465 }
455466}
Original file line number Diff line number Diff line change @@ -247,10 +247,6 @@ const loadFiles = async ({
247247 } ) ;
248248} ;
249249
250- const onExit = ( ) => {
251- process . exit ( ) ;
252- } ;
253-
254250const runInPool = async (
255251 options : RunWorkerOptions [ 'options' ] ,
256252) : Promise <
@@ -294,15 +290,11 @@ const runInPool = async (
294290 process . exit = exit ;
295291 } ) ;
296292
297- process . off ( 'SIGTERM' , onExit ) ;
298-
299293 const teardown = async ( ) => {
300294 await new Promise ( ( resolve ) => getRealTimers ( ) . setTimeout ! ( resolve ) ) ;
301295
302296 await Promise . all ( cleanups . map ( ( fn ) => fn ( ) ) ) ;
303297 isTeardown = true ;
304- // should exit correctly when user's signal listener exists
305- process . once ( 'SIGTERM' , onExit ) ;
306298 } ;
307299
308300 if ( type === 'collect' ) {
You can’t perform that action at this time.
0 commit comments