@@ -56,124 +56,116 @@ test.serial('wait for async onError() before exiting', async (t) => {
5656 unStubProcessClock ( clock )
5757} )
5858
59- test . serial ( 'exit process if "exit: true"' , async ( t ) => {
59+ const startExitLogging = function ( opts ) {
6060 stubProcessExit ( )
61- const { stopLogging } = startLogging ( { exit : true } )
61+ return startLogging ( opts ) . stopLogging
62+ }
63+
64+ const stopExitLogging = function ( stopLogging ) {
65+ stopLogging ( )
66+ unStubProcessExit ( )
67+ }
68+
69+ test . serial ( 'exit process if "exit: true"' , async ( t ) => {
70+ const stopLogging = startExitLogging ( { exit : true } )
6271
6372 await emit ( 'uncaughtException' )
6473 t . is ( process . exitCode , EXIT_CODE )
6574
66- stopLogging ( )
67- unStubProcessExit ( )
75+ stopExitLogging ( stopLogging )
6876} )
6977
7078test . serial ( 'does not exit process if "exit: false"' , async ( t ) => {
71- stubProcessExit ( )
72- const { stopLogging } = startLogging ( { exit : false } )
79+ const stopLogging = startExitLogging ( { exit : false } )
7380
7481 await emit ( 'uncaughtException' )
7582 t . is ( process . exitCode , undefined )
7683
77- stopLogging ( )
78- unStubProcessExit ( )
84+ stopExitLogging ( stopLogging )
7985} )
8086
8187test . serial ( 'does not exit process if not an exit event' , async ( t ) => {
82- stubProcessExit ( )
83- const { stopLogging } = startLogging ( { exit : true } )
88+ const stopLogging = startExitLogging ( { exit : true } )
8489
8590 await emit ( 'warning' )
8691 t . is ( process . exitCode , undefined )
8792
88- stopLogging ( )
89- unStubProcessExit ( )
93+ stopExitLogging ( stopLogging )
9094} )
9195
9296test . serial (
9397 'does not exit process if unhandledRejection on Node 14' ,
9498 async ( t ) => {
95- stubProcessExit ( )
96- const { stopLogging } = startLogging ( { exit : true } )
99+ const stopLogging = startExitLogging ( { exit : true } )
97100
98101 await emit ( 'unhandledRejection' )
99102 t . is ( process . exit . exitCode === EXIT_CODE , version . startsWith ( 'v14.' ) )
100103
101- stopLogging ( )
102- unStubProcessExit ( )
104+ stopExitLogging ( stopLogging )
103105 } ,
104106)
105107
106108test . serial ( 'exit process by default' , async ( t ) => {
107- stubProcessExit ( )
108- const { stopLogging } = startLogging ( { exit : undefined } )
109+ const stopLogging = startExitLogging ( { exit : undefined } )
109110
110111 await emit ( 'uncaughtException' )
111112 t . is ( process . exitCode , EXIT_CODE )
112113
113- stopLogging ( )
114- unStubProcessExit ( )
114+ stopExitLogging ( stopLogging )
115115} )
116116
117117test . serial (
118118 'does not exit process by default if there are other listeners' ,
119119 async ( t ) => {
120- stubProcessExit ( )
121120 const processHandler = setProcessEvent ( 'uncaughtException' )
122- const { stopLogging } = startLogging ( { exit : undefined } )
121+ const stopLogging = startExitLogging ( { exit : undefined } )
123122
124123 await emit ( 'uncaughtException' )
125124 t . is ( process . exitCode , undefined )
126125
126+ stopExitLogging ( stopLogging )
127127 unsetProcessEvent ( 'uncaughtException' , processHandler )
128- stopLogging ( )
129- unStubProcessExit ( )
130128 } ,
131129)
132130
133131test . serial (
134132 'exits process if there are other listeners but "exit: true"' ,
135133 async ( t ) => {
136- stubProcessExit ( )
137134 const processHandler = setProcessEvent ( 'uncaughtException' )
138- const { stopLogging } = startLogging ( { exit : true } )
135+ const stopLogging = startExitLogging ( { exit : true } )
139136
140137 await emit ( 'uncaughtException' )
141138 t . is ( process . exitCode , EXIT_CODE )
142139
140+ stopExitLogging ( stopLogging )
143141 unsetProcessEvent ( 'uncaughtException' , processHandler )
144- stopLogging ( )
145- unStubProcessExit ( )
146142 } ,
147143)
148144
149145test . serial (
150146 'exits process by default if there are other listeners for other events' ,
151147 async ( t ) => {
152- stubProcessExit ( )
153148 const processHandler = setProcessEvent ( 'unhandledRejection' )
154- const { stopLogging } = startLogging ( { exit : undefined } )
149+ const stopLogging = startExitLogging ( { exit : undefined } )
155150
156151 await emit ( 'uncaughtException' )
157152 t . is ( process . exitCode , EXIT_CODE )
158153
154+ stopExitLogging ( stopLogging )
159155 unsetProcessEvent ( 'unhandledRejection' , processHandler )
160- stopLogging ( )
161- unStubProcessExit ( )
162156 } ,
163157)
164158
165159test . serial (
166160 'does not exit process by default if there are other listeners for other events but "exit: false"' ,
167161 async ( t ) => {
168- stubProcessExit ( )
169162 const processHandler = setProcessEvent ( 'unhandledRejection' )
170- const { stopLogging } = startLogging ( { exit : false } )
163+ const stopLogging = startExitLogging ( { exit : false } )
171164
172165 await emit ( 'uncaughtException' )
173166 t . is ( process . exitCode , undefined )
174167
168+ stopExitLogging ( stopLogging )
175169 unsetProcessEvent ( 'unhandledRejection' , processHandler )
176- stopLogging ( )
177- unStubProcessExit ( )
178170 } ,
179171)
0 commit comments