11import os from 'node:os' ;
22import process from 'node:process' ;
33import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
4- import { SIGNAL_EXIT_CODES , installExitHandlers } from './exit-process.js' ;
4+ import { SIGNAL_EXIT_CODES , subscribeProcessExit } from './exit-process.js' ;
55
6- describe ( 'exit-process tests ' , ( ) => {
6+ describe ( 'subscribeProcessExit ' , ( ) => {
77 const onError = vi . fn ( ) ;
88 const onExit = vi . fn ( ) ;
99 const processOnSpy = vi . spyOn ( process , 'on' ) ;
@@ -27,7 +27,7 @@ describe('exit-process tests', () => {
2727 } ) ;
2828
2929 it ( 'should install event listeners for all expected events' , ( ) => {
30- expect ( ( ) => installExitHandlers ( { onError, onExit } ) ) . not . toThrow ( ) ;
30+ expect ( ( ) => subscribeProcessExit ( { onError, onExit } ) ) . not . toThrow ( ) ;
3131
3232 expect ( processOnSpy ) . toHaveBeenCalledWith (
3333 'uncaughtException' ,
@@ -44,7 +44,7 @@ describe('exit-process tests', () => {
4444 } ) ;
4545
4646 it ( 'should call onError with error and kind for uncaughtException' , ( ) => {
47- expect ( ( ) => installExitHandlers ( { onError } ) ) . not . toThrow ( ) ;
47+ expect ( ( ) => subscribeProcessExit ( { onError } ) ) . not . toThrow ( ) ;
4848
4949 const testError = new Error ( 'Test uncaught exception' ) ;
5050
@@ -56,7 +56,7 @@ describe('exit-process tests', () => {
5656 } ) ;
5757
5858 it ( 'should call onError with reason and kind for unhandledRejection' , ( ) => {
59- expect ( ( ) => installExitHandlers ( { onError } ) ) . not . toThrow ( ) ;
59+ expect ( ( ) => subscribeProcessExit ( { onError } ) ) . not . toThrow ( ) ;
6060
6161 const testReason = 'Test unhandled rejection' ;
6262
@@ -69,7 +69,7 @@ describe('exit-process tests', () => {
6969
7070 it ( 'should call onExit with correct code and reason for SIGINT' , ( ) => {
7171 expect ( ( ) =>
72- installExitHandlers ( { onExit, exitOnSignal : true } ) ,
72+ subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
7373 ) . not . toThrow ( ) ;
7474
7575 ( process as any ) . emit ( 'SIGINT' ) ;
@@ -85,7 +85,7 @@ describe('exit-process tests', () => {
8585
8686 it ( 'should call onExit with correct code and reason for SIGTERM' , ( ) => {
8787 expect ( ( ) =>
88- installExitHandlers ( { onExit, exitOnSignal : true } ) ,
88+ subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
8989 ) . not . toThrow ( ) ;
9090
9191 ( process as any ) . emit ( 'SIGTERM' ) ;
@@ -101,7 +101,7 @@ describe('exit-process tests', () => {
101101
102102 it ( 'should call onExit with correct code and reason for SIGQUIT' , ( ) => {
103103 expect ( ( ) =>
104- installExitHandlers ( { onExit, exitOnSignal : true } ) ,
104+ subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
105105 ) . not . toThrow ( ) ;
106106
107107 ( process as any ) . emit ( 'SIGQUIT' ) ;
@@ -117,7 +117,7 @@ describe('exit-process tests', () => {
117117
118118 it ( 'should not exit process when exitOnSignal is false' , ( ) => {
119119 expect ( ( ) =>
120- installExitHandlers ( { onExit, exitOnSignal : false } ) ,
120+ subscribeProcessExit ( { onExit, exitOnSignal : false } ) ,
121121 ) . not . toThrow ( ) ;
122122
123123 ( process as any ) . emit ( 'SIGINT' ) ;
@@ -132,7 +132,7 @@ describe('exit-process tests', () => {
132132 } ) ;
133133
134134 it ( 'should not exit process when exitOnSignal is not set' , ( ) => {
135- expect ( ( ) => installExitHandlers ( { onExit } ) ) . not . toThrow ( ) ;
135+ expect ( ( ) => subscribeProcessExit ( { onExit } ) ) . not . toThrow ( ) ;
136136
137137 ( process as any ) . emit ( 'SIGTERM' ) ;
138138
@@ -146,7 +146,7 @@ describe('exit-process tests', () => {
146146 } ) ;
147147
148148 it ( 'should call onExit with exit code and reason for normal exit' , ( ) => {
149- expect ( ( ) => installExitHandlers ( { onExit } ) ) . not . toThrow ( ) ;
149+ expect ( ( ) => subscribeProcessExit ( { onExit } ) ) . not . toThrow ( ) ;
150150
151151 const exitCode = 42 ;
152152 ( process as any ) . emit ( 'exit' , exitCode ) ;
@@ -159,7 +159,7 @@ describe('exit-process tests', () => {
159159
160160 it ( 'should call onExit with fatal reason when exitOnFatal is true' , ( ) => {
161161 expect ( ( ) =>
162- installExitHandlers ( { onError, onExit, exitOnFatal : true } ) ,
162+ subscribeProcessExit ( { onError, onExit, exitOnFatal : true } ) ,
163163 ) . not . toThrow ( ) ;
164164
165165 const testError = new Error ( 'Test uncaught exception' ) ;
@@ -177,7 +177,7 @@ describe('exit-process tests', () => {
177177
178178 it ( 'should use custom fatalExitCode when exitOnFatal is true' , ( ) => {
179179 expect ( ( ) =>
180- installExitHandlers ( {
180+ subscribeProcessExit ( {
181181 onError,
182182 onExit,
183183 exitOnFatal : true ,
@@ -200,7 +200,7 @@ describe('exit-process tests', () => {
200200
201201 it ( 'should call onExit with fatal reason for unhandledRejection when exitOnFatal is true' , ( ) => {
202202 expect ( ( ) =>
203- installExitHandlers ( { onError, onExit, exitOnFatal : true } ) ,
203+ subscribeProcessExit ( { onError, onExit, exitOnFatal : true } ) ,
204204 ) . not . toThrow ( ) ;
205205
206206 const testReason = 'Test unhandled rejection' ;
@@ -244,7 +244,7 @@ describe('exit-process tests', () => {
244244
245245 it ( 'should call onExit only once even when close is called multiple times' , ( ) => {
246246 expect ( ( ) =>
247- installExitHandlers ( { onExit, exitOnSignal : true } ) ,
247+ subscribeProcessExit ( { onExit, exitOnSignal : true } ) ,
248248 ) . not . toThrow ( ) ;
249249
250250 ( process as any ) . emit ( 'SIGINT' ) ;
0 commit comments