Fix errors being thrown when `detached: true` or `cleanup: false` is used (#360)
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 56b749d · Browse files · 4 files·+31 added−20 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+31 added−20 removed
- tests:+30 added−19 removed
- other:+1 added−1 removed
Provenance
- Commit
c3526cd- Tree
1cd14ef- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
56b749d
4 files changed+31 added−20 removed
modified:lib/kill.js+1 added-1 removed
83 unmodified lines8485868788888990919212 unmodified lines83 unmodified lines
// `cleanup` option handlingconst setExitHandler = (spawned, {cleanup, detached}, timedPromise) => { if (!cleanup || detached) { return; return timedPromise; }
const removeExitHandler = onExit(() => { spawned.kill();12 unmodified linesmodified:test/fixtures/sub-process-exit+11 added-1 removed
2 unmodified lines3 const execa = require('../..');4 5 const cleanup = process.argv[2] === 'true';6 const detached = process.argv[3] === 'true';7+8+const runChild = async () => {9+ try {7-execa('node', ['./test/fixtures/noop'], {cleanup, detached});10+ await execa('node', ['./test/fixtures/noop'], {cleanup, detached});11+ } catch (error) {12+ console.error(error);13+ process.exit(1);14+ }15+};16+17+runChild();modified:test/stream.js+14 added-11 removed
170 unmodified lines171 });172 173 const BUFFER_TIMEOUT = 1e3;174 175+// On Unix (not Windows), a process won't exit if stdout has not been read.176+if (process.platform !== 'win32') {175-test.serial('buffer: false > promise does not resolve when output is big and is not read', async t => {176- const {timedOut} = await t.throwsAsync(execa('max-buffer', {buffer: false, timeout: BUFFER_TIMEOUT}));177- t.true(timedOut);178-});177+ test.serial('buffer: false > promise does not resolve when output is big and is not read', async t => {178+ const {timedOut} = await t.throwsAsync(execa('max-buffer', {buffer: false, timeout: BUFFER_TIMEOUT}));179+ t.true(timedOut);180+ });181 180-test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => {181- const cp = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});182- cp.stdout.resume();183- cp.stderr.resume();184- const {timedOut} = await t.throwsAsync(cp);185- t.true(timedOut);186-});182+ test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => {183+ const cp = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});184+ cp.stdout.resume();185+ cp.stderr.resume();186+ const {timedOut} = await t.throwsAsync(cp);187+ t.true(timedOut);188+ });189+}modified:test/test.js+5 added-7 removed
72 unmodified lines73 t.is(stderr, 'foo');74 });75 76 test('preferLocal: true', async t => {77- await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {PATH: ''}}));77+ await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {Path: '', PATH: ''}}));78 });79 80 test('preferLocal: false', async t => {81- await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), ENOENT_REGEXP);81+ await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {Path: '', PATH: ''}}), ENOENT_REGEXP);82 });83 84 test('preferLocal: undefined', async t => {85- await t.throwsAsync(execa('ava', ['--version'], {env: {PATH: ''}}), ENOENT_REGEXP);85+ await t.throwsAsync(execa('ava', ['--version'], {env: {Path: '', PATH: ''}}), ENOENT_REGEXP);86 });87 88 test('localDir option', async t => {89 const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';90 const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});91- const envPaths = stdout.split(path.delimiter).map(envPath =>92- envPath.replace(/\\/g, '/').replace(/^[^/]+/, '')93- );94- t.true(envPaths.some(envPath => envPath === '/test/node_modules/.bin'));91+ const envPaths = stdout.split(path.delimiter);92+ t.true(envPaths.some(envPath => envPath.endsWith('.bin')));93 });94 95 test('stdin errors are handled', async t => {96 const child = execa('noop');122 unmodified lines