@@ -26,7 +26,7 @@ describe('subscribeProcessExit', () => {
2626 } ) ;
2727
2828 it ( 'should install event listeners for all expected events' , ( ) => {
29- expect ( ( ) => subscribeProcessExit ( { onError, onExit } ) ) . not . toThrow ( ) ;
29+ expect ( ( ) => subscribeProcessExit ( { onError, onExit } ) ) . not . toThrowError ( ) ;
3030
3131 expect ( processOnSpy ) . toHaveBeenCalledWith (
3232 'uncaughtException' ,
@@ -43,38 +43,35 @@ describe('subscribeProcessExit', () => {
4343 } ) ;
4444
4545 it ( 'should call onError with error and kind for uncaughtException' , ( ) => {
46- expect ( ( ) => subscribeProcessExit ( { onError } ) ) . not . toThrow ( ) ;
46+ expect ( ( ) => subscribeProcessExit ( { onError } ) ) . not . toThrowError ( ) ;
4747
4848 const testError = new Error ( 'Test uncaught exception' ) ;
4949
5050 ( process as any ) . emit ( 'uncaughtException' , testError ) ;
5151
52- expect ( onError ) . toHaveBeenCalledWith ( testError , 'uncaughtException' ) ;
53- expect ( onError ) . toHaveBeenCalledOnce ( ) ;
52+ expect ( onError ) . toHaveBeenCalledExactlyOnceWith ( testError , 'uncaughtException' ) ;
5453 expect ( onExit ) . not . toHaveBeenCalled ( ) ;
5554 } ) ;
5655
5756 it ( 'should call onError with reason and kind for unhandledRejection' , ( ) => {
58- expect ( ( ) => subscribeProcessExit ( { onError } ) ) . not . toThrow ( ) ;
57+ expect ( ( ) => subscribeProcessExit ( { onError } ) ) . not . toThrowError ( ) ;
5958
6059 const testReason = 'Test unhandled rejection' ;
6160
6261 ( process as any ) . emit ( 'unhandledRejection' , testReason ) ;
6362
64- expect ( onError ) . toHaveBeenCalledWith ( testReason , 'unhandledRejection' ) ;
65- expect ( onError ) . toHaveBeenCalledOnce ( ) ;
63+ expect ( onError ) . toHaveBeenCalledExactlyOnceWith ( testReason , 'unhandledRejection' ) ;
6664 expect ( onExit ) . not . toHaveBeenCalled ( ) ;
6765 } ) ;
6866
6967 it ( 'should call onExit with correct code and reason for SIGINT' , ( ) => {
7068 expect ( ( ) =>
7169 subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
72- ) . not . toThrow ( ) ;
70+ ) . not . toThrowError ( ) ;
7371
7472 ( process as any ) . emit ( 'SIGINT' ) ;
7573
76- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
77- expect ( onExit ) . toHaveBeenCalledWith ( SIGNAL_EXIT_CODES ( ) . SIGINT , {
74+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( SIGNAL_EXIT_CODES ( ) . SIGINT , {
7875 kind : 'signal' ,
7976 signal : 'SIGINT' ,
8077 } ) ;
@@ -85,12 +82,11 @@ describe('subscribeProcessExit', () => {
8582 it ( 'should call onExit with correct code and reason for SIGTERM' , ( ) => {
8683 expect ( ( ) =>
8784 subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
88- ) . not . toThrow ( ) ;
85+ ) . not . toThrowError ( ) ;
8986
9087 ( process as any ) . emit ( 'SIGTERM' ) ;
9188
92- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
93- expect ( onExit ) . toHaveBeenCalledWith ( SIGNAL_EXIT_CODES ( ) . SIGTERM , {
89+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( SIGNAL_EXIT_CODES ( ) . SIGTERM , {
9490 kind : 'signal' ,
9591 signal : 'SIGTERM' ,
9692 } ) ;
@@ -101,12 +97,11 @@ describe('subscribeProcessExit', () => {
10197 it ( 'should call onExit with correct code and reason for SIGQUIT' , ( ) => {
10298 expect ( ( ) =>
10399 subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
104- ) . not . toThrow ( ) ;
100+ ) . not . toThrowError ( ) ;
105101
106102 ( process as any ) . emit ( 'SIGQUIT' ) ;
107103
108- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
109- expect ( onExit ) . toHaveBeenCalledWith ( SIGNAL_EXIT_CODES ( ) . SIGQUIT , {
104+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( SIGNAL_EXIT_CODES ( ) . SIGQUIT , {
110105 kind : 'signal' ,
111106 signal : 'SIGQUIT' ,
112107 } ) ;
@@ -117,12 +112,11 @@ describe('subscribeProcessExit', () => {
117112 it ( 'should not exit process when exitOnSignal is false' , ( ) => {
118113 expect ( ( ) =>
119114 subscribeProcessExit ( { onExit, exitOnSignal : false } ) ,
120- ) . not . toThrow ( ) ;
115+ ) . not . toThrowError ( ) ;
121116
122117 ( process as any ) . emit ( 'SIGINT' ) ;
123118
124- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
125- expect ( onExit ) . toHaveBeenCalledWith ( SIGNAL_EXIT_CODES ( ) . SIGINT , {
119+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( SIGNAL_EXIT_CODES ( ) . SIGINT , {
126120 kind : 'signal' ,
127121 signal : 'SIGINT' ,
128122 } ) ;
@@ -131,12 +125,11 @@ describe('subscribeProcessExit', () => {
131125 } ) ;
132126
133127 it ( 'should not exit process when exitOnSignal is not set' , ( ) => {
134- expect ( ( ) => subscribeProcessExit ( { onExit } ) ) . not . toThrow ( ) ;
128+ expect ( ( ) => subscribeProcessExit ( { onExit } ) ) . not . toThrowError ( ) ;
135129
136130 ( process as any ) . emit ( 'SIGTERM' ) ;
137131
138- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
139- expect ( onExit ) . toHaveBeenCalledWith ( SIGNAL_EXIT_CODES ( ) . SIGTERM , {
132+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( SIGNAL_EXIT_CODES ( ) . SIGTERM , {
140133 kind : 'signal' ,
141134 signal : 'SIGTERM' ,
142135 } ) ;
@@ -145,33 +138,30 @@ describe('subscribeProcessExit', () => {
145138 } ) ;
146139
147140 it ( 'should call onExit with exit code and reason for normal exit' , ( ) => {
148- expect ( ( ) => subscribeProcessExit ( { onExit } ) ) . not . toThrow ( ) ;
141+ expect ( ( ) => subscribeProcessExit ( { onExit } ) ) . not . toThrowError ( ) ;
149142
150143 const exitCode = 42 ;
151144 ( process as any ) . emit ( 'exit' , exitCode ) ;
152145
153- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
154- expect ( onExit ) . toHaveBeenCalledWith ( exitCode , { kind : 'exit' } ) ;
146+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( exitCode , { kind : 'exit' } ) ;
155147 expect ( onError ) . not . toHaveBeenCalled ( ) ;
156148 expect ( processExitSpy ) . not . toHaveBeenCalled ( ) ;
157149 } ) ;
158150
159151 it ( 'should call onExit with fatal reason when exitOnFatal is true' , ( ) => {
160152 expect ( ( ) =>
161153 subscribeProcessExit ( { onError, onExit, exitOnFatal : true } ) ,
162- ) . not . toThrow ( ) ;
154+ ) . not . toThrowError ( ) ;
163155
164156 const testError = new Error ( 'Test uncaught exception' ) ;
165157
166158 ( process as any ) . emit ( 'uncaughtException' , testError ) ;
167159
168- expect ( onError ) . toHaveBeenCalledWith ( testError , 'uncaughtException' ) ;
169- expect ( onError ) . toHaveBeenCalledOnce ( ) ;
170- expect ( onExit ) . toHaveBeenCalledWith ( 1 , {
160+ expect ( onError ) . toHaveBeenCalledExactlyOnceWith ( testError , 'uncaughtException' ) ;
161+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( 1 , {
171162 kind : 'fatal' ,
172163 fatal : 'uncaughtException' ,
173164 } ) ;
174- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
175165 } ) ;
176166
177167 it ( 'should use custom fatalExitCode when exitOnFatal is true' , ( ) => {
@@ -182,37 +172,33 @@ describe('subscribeProcessExit', () => {
182172 exitOnFatal : true ,
183173 fatalExitCode : 42 ,
184174 } ) ,
185- ) . not . toThrow ( ) ;
175+ ) . not . toThrowError ( ) ;
186176
187177 const testError = new Error ( 'Test uncaught exception' ) ;
188178
189179 ( process as any ) . emit ( 'uncaughtException' , testError ) ;
190180
191- expect ( onError ) . toHaveBeenCalledWith ( testError , 'uncaughtException' ) ;
192- expect ( onError ) . toHaveBeenCalledOnce ( ) ;
193- expect ( onExit ) . toHaveBeenCalledWith ( 42 , {
181+ expect ( onError ) . toHaveBeenCalledExactlyOnceWith ( testError , 'uncaughtException' ) ;
182+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( 42 , {
194183 kind : 'fatal' ,
195184 fatal : 'uncaughtException' ,
196185 } ) ;
197- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
198186 } ) ;
199187
200188 it ( 'should call onExit with fatal reason for unhandledRejection when exitOnFatal is true' , ( ) => {
201189 expect ( ( ) =>
202190 subscribeProcessExit ( { onError, onExit, exitOnFatal : true } ) ,
203- ) . not . toThrow ( ) ;
191+ ) . not . toThrowError ( ) ;
204192
205193 const testReason = 'Test unhandled rejection' ;
206194
207195 ( process as any ) . emit ( 'unhandledRejection' , testReason ) ;
208196
209- expect ( onError ) . toHaveBeenCalledWith ( testReason , 'unhandledRejection' ) ;
210- expect ( onError ) . toHaveBeenCalledOnce ( ) ;
211- expect ( onExit ) . toHaveBeenCalledWith ( 1 , {
197+ expect ( onError ) . toHaveBeenCalledExactlyOnceWith ( testReason , 'unhandledRejection' ) ;
198+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( 1 , {
212199 kind : 'fatal' ,
213200 fatal : 'unhandledRejection' ,
214201 } ) ;
215- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
216202 } ) ;
217203
218204 it ( 'should have correct SIGINT exit code on Windows' , ( ) => {
@@ -244,11 +230,10 @@ describe('subscribeProcessExit', () => {
244230 it ( 'should call onExit only once even when close is called multiple times' , ( ) => {
245231 expect ( ( ) =>
246232 subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
247- ) . not . toThrow ( ) ;
233+ ) . not . toThrowError ( ) ;
248234
249235 ( process as any ) . emit ( 'SIGINT' ) ;
250- expect ( onExit ) . toHaveBeenCalledOnce ( ) ;
251- expect ( onExit ) . toHaveBeenCalledWith ( SIGNAL_EXIT_CODES ( ) . SIGINT , {
236+ expect ( onExit ) . toHaveBeenCalledExactlyOnceWith ( SIGNAL_EXIT_CODES ( ) . SIGINT , {
252237 kind : 'signal' ,
253238 signal : 'SIGINT' ,
254239 } ) ;
0 commit comments