Add more tests for `result.all` and `childProcess.all` (#704)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 6dd804f · Browse files · 1 file·+39 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+39 added−25 removed
- tests:+39 added−25 removed
Provenance
- Commit
6bbd265- Tree
28cbf10- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
6dd804f
1 file changed+39 added−25 removed
modified:test/stream.js+39 added-25 removed
8 unmodified lines9 import {fullStdio, getStdio} from './helpers/stdio.js';10 11 setFixtureDir();12 13+const foobarString = 'foobar';14+15 test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {16 const {all} = await execa('noop-132.js', {all: true});17 t.is(all, '132');18 });46 unmodified lines65 test('stdout is undefined if ignored - sync', testIgnore, 1, execaSync);66 test('stderr is undefined if ignored - sync', testIgnore, 2, execaSync);67 test('stdio[*] is undefined if ignored - sync', testIgnore, 3, execaSync);68 67-const testIterationBuffer = async (t, index, buffer, expectedValue) => {68- const subprocess = execa('noop-fd.js', [`${index}`], {...fullStdio, buffer});69- const [output] = await Promise.all([70- getStream(subprocess.stdio[index]),71- subprocess,72- ]);73- t.is(output, expectedValue);69+const getFirstDataEvent = async stream => {70+ const [output] = await once(stream, 'data');71+ return output.toString();72 };73 76-test('Can iterate stdout when `buffer` set to `false`', testIterationBuffer, 1, false, 'foobar');77-test('Can iterate stderr when `buffer` set to `false`', testIterationBuffer, 2, false, 'foobar');78-test('Can iterate stdio[*] when `buffer` set to `false`', testIterationBuffer, 3, false, 'foobar');79-test('Cannot iterate stdout when `buffer` set to `true`', testIterationBuffer, 1, true, '');80-test('Cannot iterate stderr when `buffer` set to `true`', testIterationBuffer, 2, true, '');81-test('Cannot iterate stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, '');82-83-const testDataEventsBuffer = async (t, index, buffer) => {84- const subprocess = execa('noop-fd.js', [`${index}`], {...fullStdio, buffer});85- const [[output]] = await Promise.all([86- once(subprocess.stdio[index], 'data'),74+// eslint-disable-next-line max-params75+const testIterationBuffer = async (t, index, buffer, useDataEvents, all) => {76+ const subprocess = execa('noop-fd.js', [`${index}`, foobarString], {...fullStdio, buffer, all});77+ const getOutput = useDataEvents ? getFirstDataEvent : getStream;78+ const [result, output, allOutput] = await Promise.all([79 subprocess,80+ getOutput(subprocess.stdio[index]),81+ all ? getOutput(subprocess.all) : undefined,82 ]);89- t.is(output.toString(), 'foobar');83+84+ const expectedProcessResult = buffer ? foobarString : undefined;85+ const expectedOutput = !buffer || useDataEvents ? foobarString : '';86+87+ t.is(result.stdio[index], expectedProcessResult);88+ t.is(output, expectedOutput);89+90+ if (all) {91+ t.is(result.all, expectedProcessResult);92+ t.is(allOutput, expectedOutput);93+ }94 };95 92-test('Can listen to `data` events on stdout when `buffer` set to `false`', testDataEventsBuffer, 1, false);93-test('Can listen to `data` events on stderr when `buffer` set to `false`', testDataEventsBuffer, 2, false);94-test('Can listen to `data` events on stdio[*] when `buffer` set to `false`', testDataEventsBuffer, 3, false);95-test('Can listen to `data` events on stdout when `buffer` set to `true`', testDataEventsBuffer, 1, true);96-test('Can listen to `data` events on stderr when `buffer` set to `true`', testDataEventsBuffer, 2, true);97-test('Can listen to `data` events on stdio[*] when `buffer` set to `true`', testDataEventsBuffer, 3, true);96+test('Can iterate stdout when `buffer` set to `false`', testIterationBuffer, 1, false, false, false);97+test('Can iterate stderr when `buffer` set to `false`', testIterationBuffer, 2, false, false, false);98+test('Can iterate stdio[*] when `buffer` set to `false`', testIterationBuffer, 3, false, false, false);99+test('Can iterate all when `buffer` set to `false`', testIterationBuffer, 1, false, false, true);100+test('Cannot iterate stdout when `buffer` set to `true`', testIterationBuffer, 1, true, false, false);101+test('Cannot iterate stderr when `buffer` set to `true`', testIterationBuffer, 2, true, false, false);102+test('Cannot iterate stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, false, false);103+test('Cannot iterate all when `buffer` set to `true`', testIterationBuffer, 1, true, false, true);104+test('Can listen to `data` events on stdout when `buffer` set to `false`', testIterationBuffer, 1, false, true, false);105+test('Can listen to `data` events on stderr when `buffer` set to `false`', testIterationBuffer, 2, false, true, false);106+test('Can listen to `data` events on stdio[*] when `buffer` set to `false`', testIterationBuffer, 3, false, true, false);107+test('Can listen to `data` events on all when `buffer` set to `false`', testIterationBuffer, 1, false, true, true);108+test('Can listen to `data` events on stdout when `buffer` set to `true`', testIterationBuffer, 1, true, true, false);109+test('Can listen to `data` events on stderr when `buffer` set to `true`', testIterationBuffer, 2, true, true, false);110+test('Can listen to `data` events on stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, true, false);111+test('Can listen to `data` events on all when `buffer` set to `true`', testIterationBuffer, 1, true, true, true);112 113 const maxBuffer = 10;114 115 const testMaxBufferSuccess = async (t, index, all) => {221 unmodified lines