Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 211febe

Browse files
ehmickysindresorhus
authored andcommittedAug 15, 2019
Fix errors being thrown when detached: true or cleanup: false is used (#360)
# Conflicts: # test/stream.js
1 parent 0cdc62c commit 211febe

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed
 

‎lib/kill.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise
8585
// `cleanup` option handling
8686
const setExitHandler = (spawned, {cleanup, detached}, timedPromise) => {
8787
if (!cleanup || detached) {
88-
return;
88+
return timedPromise;
8989
}
9090

9191
const removeExitHandler = onExit(() => {

‎test/fixtures/sub-process-exit

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ const execa = require('../..');
44

55
const cleanup = process.argv[2] === 'true';
66
const detached = process.argv[3] === 'true';
7-
execa('node', ['./test/fixtures/noop'], {cleanup, detached});
7+
8+
const runChild = async () => {
9+
try {
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();

‎test/test.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,22 @@ test('stripFinalNewline in sync mode on failure', t => {
7474
});
7575

7676
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: ''}}));
7878
});
7979

8080
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);
8282
});
8383

8484
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);
8686
});
8787

8888
test('localDir option', async t => {
8989
const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';
9090
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')));
9593
});
9694

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

0 commit comments

Comments
 (0)
Please sign in to comment.