Skip to content

Commit 896fb75

Browse files
author
John Doe
committed
refactor: rename options
1 parent fb34061 commit 896fb75

File tree

3 files changed

+78
-78
lines changed

3 files changed

+78
-78
lines changed

packages/utils/src/lib/exit-process.int.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SIGNAL_EXIT_CODES, installExitHandlers } from './exit-process.js';
44

55
describe('installExitHandlers', () => {
66
const onError = vi.fn();
7-
const onClose = vi.fn();
7+
const onExit = vi.fn();
88
const processOnSpy = vi.spyOn(process, 'on');
99
const processExitSpy = vi.spyOn(process, 'exit').mockImplementation(vi.fn());
1010

@@ -26,7 +26,7 @@ describe('installExitHandlers', () => {
2626
});
2727

2828
it('should install event listeners for all expected events', () => {
29-
expect(() => installExitHandlers({ onError, onClose })).not.toThrow();
29+
expect(() => installExitHandlers({ onError, onExit })).not.toThrow();
3030

3131
expect(processOnSpy).toHaveBeenCalledWith(
3232
'uncaughtException',
@@ -51,7 +51,7 @@ describe('installExitHandlers', () => {
5151

5252
expect(onError).toHaveBeenCalledWith(testError, 'uncaughtException');
5353
expect(onError).toHaveBeenCalledTimes(1);
54-
expect(onClose).not.toHaveBeenCalled();
54+
expect(onExit).not.toHaveBeenCalled();
5555
});
5656

5757
it('should call onError with reason and kind for unhandledRejection', () => {
@@ -63,55 +63,55 @@ describe('installExitHandlers', () => {
6363

6464
expect(onError).toHaveBeenCalledWith(testReason, 'unhandledRejection');
6565
expect(onError).toHaveBeenCalledTimes(1);
66-
expect(onClose).not.toHaveBeenCalled();
66+
expect(onExit).not.toHaveBeenCalled();
6767
});
6868

69-
it('should call onClose and exit with code 0 for SIGINT', () => {
70-
expect(() => installExitHandlers({ onClose })).not.toThrow();
69+
it('should call onExit and exit with code 0 for SIGINT', () => {
70+
expect(() => installExitHandlers({ onExit })).not.toThrow();
7171

7272
(process as any).emit('SIGINT');
7373

74-
expect(onClose).toHaveBeenCalledTimes(1);
75-
expect(onClose).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGINT, {
74+
expect(onExit).toHaveBeenCalledTimes(1);
75+
expect(onExit).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGINT, {
7676
kind: 'signal',
7777
signal: 'SIGINT',
7878
});
7979
expect(onError).not.toHaveBeenCalled();
8080
});
8181

82-
it('should call onClose and exit with code 0 for SIGTERM', () => {
83-
expect(() => installExitHandlers({ onClose })).not.toThrow();
82+
it('should call onExit and exit with code 0 for SIGTERM', () => {
83+
expect(() => installExitHandlers({ onExit })).not.toThrow();
8484

8585
(process as any).emit('SIGTERM');
8686

87-
expect(onClose).toHaveBeenCalledTimes(1);
88-
expect(onClose).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGTERM, {
87+
expect(onExit).toHaveBeenCalledTimes(1);
88+
expect(onExit).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGTERM, {
8989
kind: 'signal',
9090
signal: 'SIGTERM',
9191
});
9292
expect(onError).not.toHaveBeenCalled();
9393
});
9494

95-
it('should call onClose and exit with code 0 for SIGQUIT', () => {
96-
expect(() => installExitHandlers({ onClose })).not.toThrow();
95+
it('should call onExit and exit with code 0 for SIGQUIT', () => {
96+
expect(() => installExitHandlers({ onExit })).not.toThrow();
9797

9898
(process as any).emit('SIGQUIT');
9999

100-
expect(onClose).toHaveBeenCalledTimes(1);
101-
expect(onClose).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGQUIT, {
100+
expect(onExit).toHaveBeenCalledTimes(1);
101+
expect(onExit).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGQUIT, {
102102
kind: 'signal',
103103
signal: 'SIGQUIT',
104104
});
105105
expect(onError).not.toHaveBeenCalled();
106106
});
107107

108-
it('should call onClose for normal exit', () => {
109-
expect(() => installExitHandlers({ onClose })).not.toThrow();
108+
it('should call onExit for normal exit', () => {
109+
expect(() => installExitHandlers({ onExit })).not.toThrow();
110110

111111
(process as any).emit('exit');
112112

113-
expect(onClose).toHaveBeenCalledTimes(1);
114-
expect(onClose).toHaveBeenCalledWith(undefined, { kind: 'exit' });
113+
expect(onExit).toHaveBeenCalledTimes(1);
114+
expect(onExit).toHaveBeenCalledWith(undefined, { kind: 'exit' });
115115
expect(onError).not.toHaveBeenCalled();
116116
expect(processExitSpy).not.toHaveBeenCalled();
117117
});

packages/utils/src/lib/exit-process.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ export type CloseReason =
3131
| { kind: 'exit' };
3232

3333
export type ExitHandlerOptions = {
34-
onClose?: (code: number, reason: CloseReason) => void;
34+
onExit?: (code: number, reason: CloseReason) => void;
3535
onError?: (err: unknown, kind: FatalKind) => void;
36-
fatalExit?: boolean;
37-
signalExit?: boolean;
36+
exitOnFatal?: boolean;
37+
exitOnSignal?: boolean;
3838
fatalExitCode?: number;
3939
};
4040

4141
export function installExitHandlers(options: ExitHandlerOptions = {}): void {
4242
// eslint-disable-next-line functional/no-let
4343
let closedReason: CloseReason | undefined;
4444
const {
45-
onClose,
45+
onExit,
4646
onError,
47-
fatalExit,
48-
signalExit,
47+
exitOnFatal,
48+
exitOnSignal,
4949
fatalExitCode = DEFAULT_FATAL_EXIT_CODE,
5050
} = options;
5151

@@ -54,12 +54,12 @@ export function installExitHandlers(options: ExitHandlerOptions = {}): void {
5454
return;
5555
}
5656
closedReason = reason;
57-
onClose?.(code, reason);
57+
onExit?.(code, reason);
5858
};
5959

6060
process.on('uncaughtException', err => {
6161
onError?.(err, 'uncaughtException');
62-
if (fatalExit) {
62+
if (exitOnFatal) {
6363
close(fatalExitCode, {
6464
kind: 'fatal',
6565
fatal: 'uncaughtException',
@@ -69,7 +69,7 @@ export function installExitHandlers(options: ExitHandlerOptions = {}): void {
6969

7070
process.on('unhandledRejection', reason => {
7171
onError?.(reason, 'unhandledRejection');
72-
if (fatalExit) {
72+
if (exitOnFatal) {
7373
close(fatalExitCode, {
7474
kind: 'fatal',
7575
fatal: 'unhandledRejection',
@@ -80,7 +80,7 @@ export function installExitHandlers(options: ExitHandlerOptions = {}): void {
8080
(['SIGINT', 'SIGTERM', 'SIGQUIT'] as const).forEach(signal => {
8181
process.on(signal, () => {
8282
close(SIGNAL_EXIT_CODES()[signal], { kind: 'signal', signal });
83-
if (signalExit) {
83+
if (exitOnSignal) {
8484
// eslint-disable-next-line n/no-process-exit
8585
process.exit(SIGNAL_EXIT_CODES()[signal]);
8686
}

0 commit comments

Comments
 (0)