Skip to content
Myr

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

2 files+22 added−29 removed

modified:index.d.ts+1 added-1 removed
286 unmodified lines
287 */288 forceKill?: boolean;289290 /**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`.292293 @default 5000294 */295 forceKillAfter?: number;
130 unmodified lines
modified:test.js+21 added-28 removed
114 unmodified lines
115 const {exitCode} = execa.sync('fail', {reject: false});116 t.is(exitCode, 2);117});118119test('execa() with .kill() after it with SIGKILL should kill cleanly', async t => {120 const subprocess = execa('node', ['fixtures/no-killable'], {121 stdio: ['ipc']122 });123119test('kill("SIGKILL") should terminate cleanly', async t => {120 const subprocess = execa('node', ['fixtures/no-killable'], {stdio: ['ipc']});121 await pEvent(subprocess, 'message');122123 subprocess.kill('SIGKILL');124
3 unmodified lines
128129// `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.131if (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 });139132 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');135142 subprocess.kill('SIGTERM', {143 forceKill: false,144 forceKillAfter: 50145 });136 subprocess.kill('SIGTERM', {forceKill: false, forceKillAfter: 50});137138 t.true(isRunning(subprocess.pid));139 subprocess.kill('SIGKILL');140 });141151 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 });155142 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');145158 subprocess.kill('SIGTERM', {159 forceKillAfter: 50160 });146 subprocess.kill('SIGTERM', {forceKillAfter: 50});147148 const {signal} = await t.throwsAsync(subprocess);149 t.is(signal, 'SIGKILL');150 });151166 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');155156 subprocess.kill('SIGTERM', {forceKill: true});157158 const {signal} = await t.throwsAsync(subprocess);159 t.is(signal, 'SIGKILL');160 });161162 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');165166 subprocess.kill();167168 const {signal} = await t.throwsAsync(subprocess);169 t.is(signal, 'SIGKILL');170 });171179 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 });177185 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