From 9a157b3bc247b19d55cc6fbec77800a5ac348d19 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Mon, 6 Jul 2020 19:11:53 +0200 Subject: [PATCH] Fix use of floating number for the `timeout` and `forceKillAfterTimeout` options (#431) Co-authored-by: Sindre Sorhus Co-authored-by: ehmicky --- lib/kill.js | 4 ++-- test/kill.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/kill.js b/lib/kill.js index a684e2c043..7f6f8dd7f2 100644 --- a/lib/kill.js +++ b/lib/kill.js @@ -44,7 +44,7 @@ const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { return DEFAULT_FORCE_KILL_TIMEOUT; } - if (!Number.isInteger(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { + if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`); } @@ -71,7 +71,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise return spawnedPromise; } - if (!Number.isInteger(timeout) || timeout < 0) { + if (!Number.isFinite(timeout) || timeout < 0) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } diff --git a/test/kill.js b/test/kill.js index b402c42d12..6ca54a4a56 100644 --- a/test/kill.js +++ b/test/kill.js @@ -61,9 +61,9 @@ if (process.platform !== 'win32') { t.is(signal, 'SIGKILL'); }); - test('`forceKillAfterTimeout` should not be a float', t => { + test('`forceKillAfterTimeout` should not be NaN', t => { t.throws(() => { - execa('noop').kill('SIGTERM', {forceKillAfterTimeout: 0.5}); + execa('noop').kill('SIGTERM', {forceKillAfterTimeout: NaN}); }, {instanceOf: TypeError, message: /non-negative integer/}); });