Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors being thrown when detached: true or cleanup: false is used #360

Merged
merged 5 commits into from Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kill.js
Expand Up @@ -85,7 +85,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise
// `cleanup` option handling
const setExitHandler = (spawned, {cleanup, detached}, timedPromise) => {
if (!cleanup || detached) {
return;
return timedPromise;
}

const removeExitHandler = onExit(() => {
Expand Down
12 changes: 11 additions & 1 deletion test/fixtures/sub-process-exit
Expand Up @@ -4,4 +4,14 @@ const execa = require('../..');

const cleanup = process.argv[2] === 'true';
const detached = process.argv[3] === 'true';
execa('node', ['./test/fixtures/noop'], {cleanup, detached});

const runChild = async () => {
try {
await execa('node', ['./test/fixtures/noop'], {cleanup, detached});
} catch (error) {
console.error(error);
process.exit(1);
}
};

runChild();
25 changes: 14 additions & 11 deletions test/stream.js
Expand Up @@ -172,15 +172,18 @@ test('buffer: false > promise rejects when process returns non-zero', async t =>

const BUFFER_TIMEOUT = 1e3;

test.serial('buffer: false > promise does not resolve when output is big and is not read', async t => {
const {timedOut} = await t.throwsAsync(execa('max-buffer', {buffer: false, timeout: BUFFER_TIMEOUT}));
t.true(timedOut);
});
// On Unix (not Windows), a process won't exit if stdout has not been read.
if (process.platform !== 'win32') {
test.serial('buffer: false > promise does not resolve when output is big and is not read', async t => {
const {timedOut} = await t.throwsAsync(execa('max-buffer', {buffer: false, timeout: BUFFER_TIMEOUT}));
t.true(timedOut);
});

test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => {
const cp = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});
cp.stdout.resume();
cp.stderr.resume();
const {timedOut} = await t.throwsAsync(cp);
t.true(timedOut);
});
test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => {
const cp = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});
cp.stdout.resume();
cp.stderr.resume();
const {timedOut} = await t.throwsAsync(cp);
t.true(timedOut);
});
}
12 changes: 5 additions & 7 deletions test/test.js
Expand Up @@ -74,24 +74,22 @@ test('stripFinalNewline in sync mode on failure', t => {
});

test('preferLocal: true', async t => {
await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {PATH: ''}}));
await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {Path: '', PATH: ''}}));
});

test('preferLocal: false', async t => {
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), ENOENT_REGEXP);
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {Path: '', PATH: ''}}), ENOENT_REGEXP);
});

test('preferLocal: undefined', async t => {
await t.throwsAsync(execa('ava', ['--version'], {env: {PATH: ''}}), ENOENT_REGEXP);
await t.throwsAsync(execa('ava', ['--version'], {env: {Path: '', PATH: ''}}), ENOENT_REGEXP);
});

test('localDir option', async t => {
const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';
const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});
const envPaths = stdout.split(path.delimiter).map(envPath =>
envPath.replace(/\\/g, '/').replace(/^[^/]+/, '')
);
t.true(envPaths.some(envPath => envPath === '/test/node_modules/.bin'));
const envPaths = stdout.split(path.delimiter);
t.true(envPaths.some(envPath => envPath.endsWith('.bin')));
});

test('stdin errors are handled', async t => {
Expand Down