@@ -21,6 +21,16 @@ import { startLogging } from './helpers/start.js'
2121const pNextTick = promisify ( nextTick )
2222removeProcessListeners ( )
2323
24+ const startExitLogging = function ( opts ) {
25+ stubProcessExit ( )
26+ return stopExitLogging . bind ( undefined , startLogging ( opts ) . stopLogging )
27+ }
28+
29+ const stopExitLogging = function ( stopLogging ) {
30+ stopLogging ( )
31+ unStubProcessExit ( )
32+ }
33+
2434test . serial ( 'call process.exit() after a timeout' , async ( t ) => {
2535 const clock = stubProcessClock ( )
2636 const { stopLogging } = startLogging ( { exit : true } )
@@ -56,23 +66,13 @@ test.serial('wait for async onError() before exiting', async (t) => {
5666 unStubProcessClock ( clock )
5767} )
5868
59- const startExitLogging = function ( opts ) {
60- stubProcessExit ( )
61- return startLogging ( opts ) . stopLogging
62- }
63-
64- const stopExitLogging = function ( stopLogging ) {
65- stopLogging ( )
66- unStubProcessExit ( )
67- }
68-
6969test . serial ( 'exit process if "exit: true"' , async ( t ) => {
7070 const stopLogging = startExitLogging ( { exit : true } )
7171
7272 await emit ( 'uncaughtException' )
7373 t . is ( process . exitCode , EXIT_CODE )
7474
75- stopExitLogging ( stopLogging )
75+ stopLogging ( )
7676} )
7777
7878test . serial ( 'does not exit process if "exit: false"' , async ( t ) => {
@@ -81,7 +81,7 @@ test.serial('does not exit process if "exit: false"', async (t) => {
8181 await emit ( 'uncaughtException' )
8282 t . is ( process . exitCode , undefined )
8383
84- stopExitLogging ( stopLogging )
84+ stopLogging ( )
8585} )
8686
8787test . serial ( 'does not exit process if not an exit event' , async ( t ) => {
@@ -90,7 +90,7 @@ test.serial('does not exit process if not an exit event', async (t) => {
9090 await emit ( 'warning' )
9191 t . is ( process . exitCode , undefined )
9292
93- stopExitLogging ( stopLogging )
93+ stopLogging ( )
9494} )
9595
9696test . serial (
@@ -101,7 +101,7 @@ test.serial(
101101 await emit ( 'unhandledRejection' )
102102 t . is ( process . exit . exitCode === EXIT_CODE , version . startsWith ( 'v14.' ) )
103103
104- stopExitLogging ( stopLogging )
104+ stopLogging ( )
105105 } ,
106106)
107107
@@ -111,7 +111,7 @@ test.serial('exit process by default', async (t) => {
111111 await emit ( 'uncaughtException' )
112112 t . is ( process . exitCode , EXIT_CODE )
113113
114- stopExitLogging ( stopLogging )
114+ stopLogging ( )
115115} )
116116
117117test . serial (
@@ -123,7 +123,7 @@ test.serial(
123123 await emit ( 'uncaughtException' )
124124 t . is ( process . exitCode , undefined )
125125
126- stopExitLogging ( stopLogging )
126+ stopLogging ( )
127127 unsetProcessEvent ( 'uncaughtException' , processHandler )
128128 } ,
129129)
@@ -137,7 +137,7 @@ test.serial(
137137 await emit ( 'uncaughtException' )
138138 t . is ( process . exitCode , EXIT_CODE )
139139
140- stopExitLogging ( stopLogging )
140+ stopLogging ( )
141141 unsetProcessEvent ( 'uncaughtException' , processHandler )
142142 } ,
143143)
@@ -151,7 +151,7 @@ test.serial(
151151 await emit ( 'uncaughtException' )
152152 t . is ( process . exitCode , EXIT_CODE )
153153
154- stopExitLogging ( stopLogging )
154+ stopLogging ( )
155155 unsetProcessEvent ( 'unhandledRejection' , processHandler )
156156 } ,
157157)
@@ -165,7 +165,7 @@ test.serial(
165165 await emit ( 'uncaughtException' )
166166 t . is ( process . exitCode , undefined )
167167
168- stopExitLogging ( stopLogging )
168+ stopLogging ( )
169169 unsetProcessEvent ( 'unhandledRejection' , processHandler )
170170 } ,
171171)
0 commit comments