Skip to content
Myr

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

4 files+31 added−20 removed

modified:lib/kill.js+1 added-1 removed
modified:test/fixtures/sub-process-exit+11 added-1 removed
2 unmodified lines
3const execa = require('../..');45const cleanup = process.argv[2] === 'true';6const detached = process.argv[3] === 'true';78const runChild = async () => {9 try {7execa('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};1617runChild();
modified:test/stream.js+14 added-11 removed
170 unmodified lines
171});172173const BUFFER_TIMEOUT = 1e3;174175// On Unix (not Windows), a process won't exit if stdout has not been read.176if (process.platform !== 'win32') {175test.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 });181180test.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 lines
73 t.is(stderr, 'foo');74});7576test('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});7980test('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});8384test('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});8788test('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});9495test('stdin errors are handled', async t => {96 const child = execa('noop');
122 unmodified lines