Refactor tests of `kill()` (#284)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 1b38dc9 · Browse files · 2 files·+22 added−29 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+22 added−29 removed
- other:+22 added−29 removed
Provenance
- Commit
7e2c835- Tree
558ecdd- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
1b38dc9
2 files changed+22 added−29 removed
modified:index.d.ts+1 added-1 removed
286 unmodified lines287 */288 forceKill?: boolean;289 290 /**291- Milliseconds to wait for the child process to terminate before sending a `SIGKILL` signal.291+ Milliseconds to wait for the child process to terminate before sending `SIGKILL`.292 293 @default 5000294 */295 forceKillAfter?: number;130 unmodified linesmodified:test.js+21 added-28 removed
114 unmodified lines115 const {exitCode} = execa.sync('fail', {reject: false});116 t.is(exitCode, 2);117 });118 119-test('execa() with .kill() after it with SIGKILL should kill cleanly', async t => {120- const subprocess = execa('node', ['fixtures/no-killable'], {121- stdio: ['ipc']122- });123-119+test('kill("SIGKILL") should terminate cleanly', async t => {120+ const subprocess = execa('node', ['fixtures/no-killable'], {stdio: ['ipc']});121 await pEvent(subprocess, 'message');122 123 subprocess.kill('SIGKILL');124 3 unmodified lines128 129 // `SIGTERM` cannot be caught on Windows, and it always aborts the process (like `SIGKILL` on Unix).130 // Therefore, this feature and those tests do not make sense on Windows.131 if (process.platform !== 'win32') {135- test('execa() with .kill() after it with SIGTERM should not kill (no retry)', async t => {136- const subprocess = execa('node', ['fixtures/no-killable'], {137- stdio: ['ipc']138- });139-132+ test('`forceKill: false` should not kill after a timeout', async t => {133+ const subprocess = execa('node', ['fixtures/no-killable'], {stdio: ['ipc']});134 await pEvent(subprocess, 'message');135 142- subprocess.kill('SIGTERM', {143- forceKill: false,144- forceKillAfter: 50145- });136+ subprocess.kill('SIGTERM', {forceKill: false, forceKillAfter: 50});137 138 t.true(isRunning(subprocess.pid));139 subprocess.kill('SIGKILL');140 });141 151- test('execa() with .kill() after it with SIGTERM should kill after 50 ms with SIGKILL', async t => {152- const subprocess = execa('node', ['fixtures/no-killable'], {153- stdio: ['ipc']154- });155-142+ test('`forceKillAfter: number` should kill after a timeout', async t => {143+ const subprocess = execa('node', ['fixtures/no-killable'], {stdio: ['ipc']});144 await pEvent(subprocess, 'message');145 158- subprocess.kill('SIGTERM', {159- forceKillAfter: 50160- });146+ subprocess.kill('SIGTERM', {forceKillAfter: 50});147 148 const {signal} = await t.throwsAsync(subprocess);149 t.is(signal, 'SIGKILL');150 });151 166- test('execa() with .kill() after it with nothing (undefined) should kill after 50 ms with SIGKILL', async t => {167- const subprocess = execa('node', ['fixtures/no-killable'], {168- stdio: ['ipc']169- });152+ test('`forceKill: true` should kill after a timeout', async t => {153+ const subprocess = execa('node', ['fixtures/no-killable'], {stdio: ['ipc']});154+ await pEvent(subprocess, 'message');155 156+ subprocess.kill('SIGTERM', {forceKill: true});157+158+ const {signal} = await t.throwsAsync(subprocess);159+ t.is(signal, 'SIGKILL');160+ });161+162+ test('kill() with no arguments should kill after a timeout', async t => {163+ const subprocess = execa('node', ['fixtures/no-killable'], {stdio: ['ipc']});164 await pEvent(subprocess, 'message');165 166 subprocess.kill();167 168 const {signal} = await t.throwsAsync(subprocess);169 t.is(signal, 'SIGKILL');170 });171 179- test('.kill() `forceKillAfter` should not be a float', t => {172+ test('`forceKillAfter` should not be a float', t => {173 t.throws(() => {174 execa('noop').kill('SIGTERM', {forceKillAfter: 0.5});175 }, {instanceOf: TypeError, message: /non-negative integer/});176 });177 185- test('.kill() `forceKillAfter` should not be negative', t => {178+ test('`forceKillAfter` should not be negative', t => {179 t.throws(() => {180 execa('noop').kill('SIGTERM', {forceKillAfter: -1});181 }, {instanceOf: TypeError, message: /non-negative integer/});182 });623 unmodified lines