Skip to content
Myr

Fix inconsistency between `result.stdout` and `error.stdout` (#686)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 73f4b8c · Browse files · 3 files+54 added−47 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+54 added−47 removed

  • tests:+52 added−42 removed
  • other:+2 added−5 removed

3 files+54 added−47 removed

modified:lib/error.js-2 removed
modified:test/error.js+52 added-42 removed
8 unmodified lines
9setFixtureDir();1011const TIMEOUT_REGEXP = /timed out after/;1213test('empty error.stdout/stderr/stdio', async t => {14 const {stdout, stderr, stdio} = await t.throwsAsync(execa('fail.js'));13const testEmptyErrorStdio = async (t, execaMethod) => {14 const {failed, stdout, stderr, stdio} = await execaMethod('fail.js', {reject: false});15 t.true(failed);16 t.is(stdout, '');17 t.is(stderr, '');17 t.deepEqual(stdio, ['', '', '']);18});18 t.deepEqual(stdio, [undefined, '', '']);19};2020test('empty error.all', async t => {21 const {all} = await t.throwsAsync(execa('fail.js', {all: true}));22 t.is(all, '');23});21test('empty error.stdout/stderr/stdio', testEmptyErrorStdio, execa);22test('empty error.stdout/stderr/stdio - sync', testEmptyErrorStdio, execaSync);2325test('undefined error.all', async t => {26 const {all} = await t.throwsAsync(execa('fail.js'));27 t.is(all, undefined);28});24const testUndefinedErrorStdio = async (t, execaMethod) => {25 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});26 t.is(stdout, undefined);27 t.is(stderr, undefined);28 t.deepEqual(stdio, [undefined, undefined, undefined]);29};3031test('undefined error.stdout/stderr/stdio', testUndefinedErrorStdio, execa);32test('undefined error.stdout/stderr/stdio - sync', testUndefinedErrorStdio, execaSync);3334const testEmptyAll = async (t, options, expectedValue) => {35 const {all} = await t.throwsAsync(execa('fail.js', options));36 t.is(all, expectedValue);37};3839test('empty error.all', testEmptyAll, {all: true}, '');40test('undefined error.all', testEmptyAll, {}, undefined);41test('ignored error.all', testEmptyAll, {all: true, stdio: 'ignore'}, undefined);4243test('empty error.stdio[0] even with input', async t => {44 const {stdio} = await t.throwsAsync(execa('fail.js', {input: 'test'}));32 t.is(stdio[0], '');45 t.is(stdio[0], undefined);46});4735const WRONG_COMMAND = isWindows36 ? '\'wrong\' is not recognized as an internal or external command,\r\noperable program or batch file.'37 : '';48// `error.code` is OS-specific here49const SPAWN_ERROR_CODES = new Set(['EINVAL', 'ENOTSUP', 'EPERM']);5039test('stdout/stderr/all/stdio on process errors', async t => {40 const {stdout, stderr, all, stdio} = await t.throwsAsync(execa('wrong command', {all: true}));41 t.is(stdout, '');42 t.is(stderr, WRONG_COMMAND);43 t.is(all, WRONG_COMMAND);44 t.deepEqual(stdio, ['', '', WRONG_COMMAND]);51test('stdout/stderr/stdio on process spawning errors', async t => {52 const {code, stdout, stderr, stdio} = await t.throwsAsync(execa('noop.js', {uid: -1}));53 t.true(SPAWN_ERROR_CODES.has(code));54 t.is(stdout, undefined);55 t.is(stderr, undefined);56 t.deepEqual(stdio, [undefined, undefined, undefined]);57});5847test('stdout/stderr/all/stdio on process errors, in sync mode', t => {48 const {stdout, stderr, all, stdio} = t.throws(() => {49 execaSync('wrong command');59test('stdout/stderr/all/stdio on process spawning errors - sync', t => {60 const {code, stdout, stderr, stdio} = t.throws(() => {61 execaSync('noop.js', {uid: -1});62 });51 t.is(stdout, '');52 t.is(stderr, WRONG_COMMAND);53 t.is(all, undefined);54 t.deepEqual(stdio, ['', '', WRONG_COMMAND]);63 t.true(SPAWN_ERROR_CODES.has(code));64 t.is(stdout, undefined);65 t.is(stderr, undefined);66 t.deepEqual(stdio, [undefined, undefined, undefined]);67});6857test('error.stdout/stderr/stdio is defined', async t => {58 const {stdout, stderr, stdio} = await t.throwsAsync(execa('echo-fail.js', fullStdio));69const testErrorOutput = async (t, execaMethod) => {70 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});71 t.true(failed);72 t.is(stdout, 'stdout');73 t.is(stderr, 'stderr');61 t.deepEqual(stdio, ['', 'stdout', 'stderr', 'fd3']);62});74 t.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);75};7664test('error.stdout/stderr/stdio is defined, in sync mode', t => {65 const {stdout, stderr, stdio} = t.throws(() => {66 execaSync('echo-fail.js', fullStdio);67 });68 t.is(stdout, 'stdout');69 t.is(stderr, 'stderr');70 t.deepEqual(stdio, ['', 'stdout', 'stderr', 'fd3']);71});77test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);78test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);7980test('exitCode is 0 on success', async t => {81 const {exitCode} = await execa('noop.js', ['foo']);82 t.is(exitCode, 0);83});8485const testExitCode = async (t, number) => {79 const {exitCode} = await t.throwsAsync(execa('exit.js', [`${number}`]), {message: new RegExp(`failed with exit code ${number}`)});86 const {exitCode} = await t.throwsAsync(87 execa('exit.js', [`${number}`]),88 {message: new RegExp(`failed with exit code ${number}`)},89 );90 t.is(exitCode, number);91};9293test('exitCode is 2', testExitCode, 2);
179 unmodified lines
modified:index.js+2 added-3 removed
79 unmodified lines
80 return {file, args, command, escapedCommand, options};81};8283const handleOutput = (options, value) => {84 if (typeof value !== 'string' && !ArrayBuffer.isView(value)) {84 if (value === undefined || value === null) {85 return;86 }8788 if (Buffer.isBuffer(value)) {
17 unmodified lines
106 const dummySpawned = new childProcess.ChildProcess();107 const errorPromise = Promise.reject(makeError({108 error,109 stdio: Array.from({length: stdioLength}),110 all: options.all ? '' : undefined,110 command,111 escapedCommand,112 options,113 timedOut: false,
86 unmodified lines
200 }201202 pipeOutputSync(stdioStreams, result);203205 const output = result.output || [undefined, undefined, undefined];204 const output = result.output || Array.from({length: 3});205 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));206207 if (result.error || result.status !== 0 || result.signal !== null) {208 const error = makeError({
109 unmodified lines