@@ -62,23 +62,25 @@ function getTestCases(isWorker = false){
6262cases . push ( { func : changeCodeInsideExit , result : 99 } ) ;
6363
6464function zeroExitWithUncaughtHandler ( ) {
65+ const noop = ( ) => { } ;
6566process . on ( 'exit' , ( code ) => {
66- assert . strictEqual ( process . exitCode , 0 ) ;
67+ process . off ( 'uncaughtException' , noop ) ;
68+ assert . strictEqual ( process . exitCode , undefined ) ;
6769assert . strictEqual ( code , 0 ) ;
6870} ) ;
69- process . on ( 'uncaughtException' , ( ) => { } ) ;
71+ process . on ( 'uncaughtException' , noop ) ;
7072throw new Error ( 'ok' ) ;
7173}
7274cases . push ( { func : zeroExitWithUncaughtHandler , result : 0 } ) ;
7375
7476function changeCodeInUncaughtHandler ( ) {
77+ const modifyExitCode = ( ) => { process . exitCode = 97 ; } ;
7578process . on ( 'exit' , ( code ) => {
79+ process . off ( 'uncaughtException' , modifyExitCode ) ;
7680assert . strictEqual ( process . exitCode , 97 ) ;
7781assert . strictEqual ( code , 97 ) ;
7882} ) ;
79- process . on ( 'uncaughtException' , ( ) => {
80- process . exitCode = 97 ;
81- } ) ;
83+ process . on ( 'uncaughtException' , modifyExitCode ) ;
8284throw new Error ( 'ok' ) ;
8385}
8486cases . push ( { func : changeCodeInUncaughtHandler , result : 97 } ) ;
0 commit comments