Improve some tests (#655)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent d78348d · Browse files · 2 files·+18 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+18 added−27 removed
- tests:+18 added−27 removed
Provenance
- Commit
6cf1c5e- Tree
81781ae- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
d78348d
2 files changed+18 added−27 removed
modified:test/kill.js+15 added-27 removed
29 unmodified lines30 subprocess.kill('SIGTERM', {forceKillAfterTimeout: false});31 32 t.true(isRunning(subprocess.pid));33 subprocess.kill('SIGKILL');34- });34 36- test('`forceKillAfterTimeout: number` should kill after a timeout', async t => {37- const subprocess = execa('no-killable.js', {stdio: ['ipc']});38- await pEvent(subprocess, 'message');39-40- subprocess.kill('SIGTERM', {forceKillAfterTimeout: 50});41-35 const {signal} = await t.throwsAsync(subprocess);36 t.is(signal, 'SIGKILL');37 });38 46- test('`forceKillAfterTimeout: true` should kill after a timeout', async t => {39+ const testForceKill = async (t, killArguments) => {40 const subprocess = execa('no-killable.js', {stdio: ['ipc']});41 await pEvent(subprocess, 'message');42 50- subprocess.kill('SIGTERM', {forceKillAfterTimeout: true});43+ subprocess.kill(...killArguments);44 45 const {signal} = await t.throwsAsync(subprocess);46 t.is(signal, 'SIGKILL');54- });47+ };48 56- test('kill() with no arguments should kill after a timeout', async t => {57- const subprocess = execa('no-killable.js', {stdio: ['ipc']});58- await pEvent(subprocess, 'message');49+ test('`forceKillAfterTimeout: number` should kill after a timeout', testForceKill, ['SIGTERM', {forceKillAfterTimeout: 50}]);50+ test('`forceKillAfterTimeout: true` should kill after a timeout', testForceKill, ['SIGTERM', {forceKillAfterTimeout: true}]);51+ test('kill("SIGTERM") should kill after a timeout', testForceKill, ['SIGTERM']);52+ test('kill() with no arguments should kill after a timeout', testForceKill, []);53 60- subprocess.kill();61-62- const {signal} = await t.throwsAsync(subprocess);63- t.is(signal, 'SIGKILL');64- });65-66- test('`forceKillAfterTimeout` should not be NaN', t => {54+ const testInvalidForceKill = async (t, forceKillAfterTimeout) => {55+ const childProcess = execa('noop.js');56 t.throws(() => {68- execa('noop.js').kill('SIGTERM', {forceKillAfterTimeout: Number.NaN});57+ childProcess.kill('SIGTERM', {forceKillAfterTimeout});58 }, {instanceOf: TypeError, message: /non-negative integer/});59+ const {signal} = await t.throwsAsync(childProcess);60+ t.is(signal, 'SIGTERM');70- });61+ };62 72- test('`forceKillAfterTimeout` should not be negative', t => {73- t.throws(() => {74- execa('noop.js').kill('SIGTERM', {forceKillAfterTimeout: -1});75- }, {instanceOf: TypeError, message: /non-negative integer/});76- });63+ test('`forceKillAfterTimeout` should not be NaN', testInvalidForceKill, Number.NaN);64+ test('`forceKillAfterTimeout` should not be negative', testInvalidForceKill, -1);65 }66 67 test('execa() returns a promise with kill()', t => {68 const {kill} = execa('noop.js', ['foo']);234 unmodified linesmodified:test/node.js+3 added
107 unmodified linesExpand all108109110111112113114115107 unmodified linesExpand all const message = await pEvent(subprocess, 'message'); t.is(message, 'pong');
subprocess.kill();
const {signal} = await t.throwsAsync(subprocess); t.is(signal, 'SIGTERM');});