Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of floating number for the timeout and forceKillAfterTimeout options #431

Merged
merged 7 commits into from Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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