Skip to content

Commit 8467290

Browse files
author
John Doe
committed
refactor: add no double close test
1 parent 71efc34 commit 8467290

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,22 @@ describe('exit-process tests', () => {
246246

247247
osSpy.mockRestore();
248248
});
249+
250+
it('should call onClose only once even when close is called multiple times', () => {
251+
expect(() =>
252+
installExitHandlers({ onClose, signalExit: true }),
253+
).not.toThrow();
254+
255+
(process as any).emit('SIGINT');
256+
expect(onClose).toHaveBeenCalledTimes(1);
257+
expect(onClose).toHaveBeenCalledWith(SIGNAL_EXIT_CODES().SIGINT, {
258+
kind: 'signal',
259+
signal: 'SIGINT',
260+
});
261+
onClose.mockClear();
262+
(process as any).emit('SIGTERM');
263+
expect(onClose).not.toHaveBeenCalled();
264+
(process as any).emit('exit', 0);
265+
expect(onClose).not.toHaveBeenCalled();
266+
});
249267
});

0 commit comments

Comments
 (0)