Skip to content

Commit

Permalink
Fix use of floating number for the timeout and `forceKillAfterTimeo…
Browse files Browse the repository at this point in the history
…ut` options (#431)

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: ehmicky <ehmicky@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 6, 2020
1 parent a827d82 commit 9a157b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/kill.js
Expand Up @@ -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})`);
}

Expand All @@ -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})`);
}

Expand Down
4 changes: 2 additions & 2 deletions test/kill.js
Expand Up @@ -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/});
});

Expand Down

0 comments on commit 9a157b3

Please sign in to comment.