Fix `all` option combined with `ignore` (#703)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent b8c1f55 · Browse files · 3 files·+30 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+30 added−18 removed
- tests:+27 added−3 removed
- other:+3 added−15 removed
Provenance
- Commit
7707fc7- Tree
e59359b- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
b8c1f55
3 files changed+30 added−18 removed
modified:lib/stream.js+3 added-15 removed
4 unmodified lines567891011129101112141516171819202122232413141516106 unmodified linesExpand all4 unmodified linesimport {throwOnTimeout, cleanupOnExit} from './kill.js';import {STANDARD_STREAMS} from './stdio/native.js';
// `all` interleaves `stdout` and `stderr`export const makeAllStream = (spawned, {all}) => { if (!all) { return; }export const makeAllStream = ({stdout, stderr}, {all}) => all && (stdout || stderr) ? mergeStreams([stdout, stderr].filter(Boolean)) : undefined;
if (!spawned.stdout) { return spawned.stderr; }
if (!spawned.stderr) { return spawned.stdout; }
return mergeStreams([spawned.stdout, spawned.stderr]);};
// On failure, `result.stdout|stderr|all` should contain the currently buffered stream// They are automatically closed and flushed by Node.js when the child process exits// We guarantee this by calling `childProcess.kill()`// When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve106 unmodified linesExpand alladded:test/fixtures/noop-both.js+6 added
123456#!/usr/bin/env nodeimport process from 'node:process';
const text = process.argv[2] || 'foobar';console.log(text);console.error(text);modified:test/stream.js+21 added-3 removed
24 unmodified lines25 t.is(all, undefined);26 });27 28 const testAllIgnore = async (t, streamName, otherStreamName) => {29- const childProcess = execa('noop.js', {[otherStreamName]: 'ignore', all: true});30- t.is(childProcess.all, childProcess[streamName]);31- await childProcess;29+ const childProcess = execa('noop-both.js', {[otherStreamName]: 'ignore', all: true});30+ t.is(childProcess[otherStreamName], null);31+ t.not(childProcess[streamName], null);32+ t.not(childProcess.all, null);33+34+ const result = await childProcess;35+ t.is(result[otherStreamName], undefined);36+ t.is(result[streamName], 'foobar');37+ t.is(result.all, 'foobar');38 };39 40 test('can use all: true with stdout: ignore', testAllIgnore, 'stderr', 'stdout');41 test('can use all: true with stderr: ignore', testAllIgnore, 'stdout', 'stderr');42 43+test('can use all: true with stdout: ignore + stderr: ignore', async t => {44+ const childProcess = execa('noop-both.js', {stdout: 'ignore', stderr: 'ignore', all: true});45+ t.is(childProcess.stdout, null);46+ t.is(childProcess.stderr, null);47+ t.is(childProcess.all, undefined);48+49+ const {stdout, stderr, all} = await childProcess;50+ t.is(stdout, undefined);51+ t.is(stderr, undefined);52+ t.is(all, undefined);53+});54+55 const testIgnore = async (t, index, execaMethod) => {56 const result = await execaMethod('noop.js', getStdio(index, 'ignore'));57 t.is(result.stdio[index], undefined);58 };264 unmodified lines