Skip to content

Commit

Permalink
Fix timeout validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 11, 2019
1 parent 9dad85d commit 19ae036
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ function isSigterm(signal) {
(typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
}

function getForceKillAfterTimeout({forceKillAfter}) {
if (Number.isInteger(forceKillAfter)) {
return forceKillAfter;
function getForceKillAfterTimeout({forceKillAfter = DEFAULT_FORCE_KILL_TIMEOUT}) {
if (!Number.isInteger(forceKillAfter) || forceKillAfter < 0) {
throw new TypeError(`Option 'forceKillAfter' ${forceKillAfter} should be a positive integer`);
}

return DEFAULT_FORCE_KILL_TIMEOUT;
return forceKillAfter;
}

const execa = (file, args, options) => {
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ if (process.platform !== 'win32') {
const {signal} = await t.throwsAsync(subprocess);
t.is(signal, 'SIGKILL');
});

test('.kill() `forceKillAfter` should not be a float', t => {
t.throws(() => execa('noop').kill('SIGTERM', {forceKillAfter: 0.5}), TypeError);
});

test('.kill() `forceKillAfter` should not be negative', t => {
t.throws(() => execa('noop').kill('SIGTERM', {forceKillAfter: -1}), TypeError);
});
}

test('stripFinalNewline: true', async t => {
Expand Down

0 comments on commit 19ae036

Please sign in to comment.