From bc942236740134c8b54f8d43ce4fe32eeeecb56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A8r=20Kessels?= Date: Tue, 15 Feb 2022 17:40:57 +0100 Subject: [PATCH 1/2] fix: returning "true" instead of "void" Apparently process.kill() returns a Boolean, so the early return will return a true||false rather than the void as per the func sig. This patch ensures we return void regardless of what process.kill() and process.exit() return. What they return may be dependent on node version and/or platform. --- src/signal-termination.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/signal-termination.ts b/src/signal-termination.ts index db8b6fc..84c2c26 100644 --- a/src/signal-termination.ts +++ b/src/signal-termination.ts @@ -89,10 +89,11 @@ export class TermSignals { */ public _terminateProcess (code?: number, signal?: NodeJS.Signals): void { if (signal !== undefined) { - return process.kill(process.pid, signal) + process.kill(process.pid, signal) + return } if (code !== undefined) { - return process.exit(code) + process.exit(code) } throw new Error('Unable to terminate parent process successfully') } From 33b3367cff88a236b9e79e4fd2990bdcd06ae47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A8r=20Kessels?= Date: Wed, 16 Feb 2022 10:38:46 +0100 Subject: [PATCH 2/2] fix: add an unreachable return, to test signal termination --- src/signal-termination.ts | 1 + test/signal-termination.spec.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/signal-termination.ts b/src/signal-termination.ts index 84c2c26..5e4120f 100644 --- a/src/signal-termination.ts +++ b/src/signal-termination.ts @@ -94,6 +94,7 @@ export class TermSignals { } if (code !== undefined) { process.exit(code) + return // eslint-disable-line no-unreachable } throw new Error('Unable to terminate parent process successfully') } diff --git a/test/signal-termination.spec.ts b/test/signal-termination.spec.ts index f203ff9..96ad89c 100644 --- a/test/signal-termination.spec.ts +++ b/test/signal-termination.spec.ts @@ -71,6 +71,7 @@ describe('signal-termination', (): void => { it('should call exit method on parent process if no signal provided', (): void => { term._terminateProcess(0) + // We here test code that in reality is unreachable. assert.equal(exitStub.callCount, 1) })