Skip to content
Myr

Properly clean up child processes created during tests (#349)

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 0cdc62c · Browse files · 4 files+11 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+11 added−11 removed

  • tests:+11 added−11 removed

4 files+11 added−11 removed

modified:test/fixtures/detach+1 added-1 removed
1 unmodified line
2'use strict';34const execa = require('../..');56const subprocess = execa('node', ['./test/fixtures/forever'], {detached: true});6const subprocess = execa('node', ['./test/fixtures/noop'], {detached: true});7console.log(subprocess.pid);8process.exit();
modified:test/error.js+6 added-6 removed
modified:test/kill.js+3 added-3 removed
78 unmodified lines
79 t.is(typeof kill, 'function');80});8182test('timeout kills the process if it times out', async t => {83 const {killed, timedOut} = await t.throwsAsync(execa('forever', {timeout: 1}), TIMEOUT_REGEXP);83 const {killed, timedOut} = await t.throwsAsync(execa('noop', {timeout: 1}), TIMEOUT_REGEXP);84 t.false(killed);85 t.true(timedOut);86});8788test('timeout kills the process if it times out, in sync mode', async t => {89 const {killed, timedOut} = await t.throws(() => {90 execa.sync('forever', {timeout: 1, message: TIMEOUT_REGEXP});90 execa.sync('noop', {timeout: 1, message: TIMEOUT_REGEXP});91 });92 t.false(killed);93 t.true(timedOut);94});
56 unmodified lines
151152 t.false(isRunning(subprocess.pid));153 t.is(isRunning(pid), !isKilled);154155 if (!isKilled) {155 if (isRunning(pid)) {156 process.kill(pid, 'SIGKILL');157 }158};159
103 unmodified lines
modified:test/test.js+1 added-1 removed
105 unmodified lines
106 await t.throwsAsync(child, /test/);107});108109test('child process errors rejects promise right away', async t => {110 const child = execa('forever');110 const child = execa('noop');111 child.emit('error', new Error('test'));112 await t.throwsAsync(child, /test/);113});114
106 unmodified lines