@@ -62,23 +62,25 @@ function getTestCases(isWorker = false) {
62
62
cases . push ( { func : changeCodeInsideExit , result : 99 } ) ;
63
63
64
64
function zeroExitWithUncaughtHandler ( ) {
65
+ const noop = ( ) => { } ;
65
66
process . on ( 'exit' , ( code ) => {
66
- assert . strictEqual ( process . exitCode , 0 ) ;
67
+ process . off ( 'uncaughtException' , noop ) ;
68
+ assert . strictEqual ( process . exitCode , undefined ) ;
67
69
assert . strictEqual ( code , 0 ) ;
68
70
} ) ;
69
- process . on ( 'uncaughtException' , ( ) => { } ) ;
71
+ process . on ( 'uncaughtException' , noop ) ;
70
72
throw new Error ( 'ok' ) ;
71
73
}
72
74
cases . push ( { func : zeroExitWithUncaughtHandler , result : 0 } ) ;
73
75
74
76
function changeCodeInUncaughtHandler ( ) {
77
+ const modifyExitCode = ( ) => { process . exitCode = 97 ; } ;
75
78
process . on ( 'exit' , ( code ) => {
79
+ process . off ( 'uncaughtException' , modifyExitCode ) ;
76
80
assert . strictEqual ( process . exitCode , 97 ) ;
77
81
assert . strictEqual ( code , 97 ) ;
78
82
} ) ;
79
- process . on ( 'uncaughtException' , ( ) => {
80
- process . exitCode = 97 ;
81
- } ) ;
83
+ process . on ( 'uncaughtException' , modifyExitCode ) ;
82
84
throw new Error ( 'ok' ) ;
83
85
}
84
86
cases . push ( { func : changeCodeInUncaughtHandler , result : 97 } ) ;
0 commit comments