Fix `stripFinalNewline` not applied on `error.stdout|stderr|all` (#240)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 7c96b58 · Browse files · 3 files·+36 added−10 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+36 added−10 removed
- other:+36 added−10 removed
Provenance
- Commit
943f040- Tree
3933986- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
7c96b58
3 files changed+36 added−10 removed
added:fixtures/noop-throw+4 added
1+#!/usr/bin/env node2+'use strict';3+console.error(process.argv[2]);4+process.exit(2);modified:index.js+11 added-9 removed
348 unmodified lines349 350 const finalize = async () => {351 const results = await processComplete;352 353- const result = results[0];354- result.stdout = results[1];355- result.stderr = results[2];356- result.all = results[3];353+ const [result, stdout, stderr, all] = results;354+ result.stdout = handleOutput(parsed.options, stdout);355+ result.stderr = handleOutput(parsed.options, stderr);356+ result.all = handleOutput(parsed.options, all);357 358 if (result.error || result.code !== 0 || result.signal !== null) {359 const error = makeError(result, {360 joinedCommand,10 unmodified lines371 throw error;372 }373 374 return {375- stdout: handleOutput(parsed.options, result.stdout),376- stderr: handleOutput(parsed.options, result.stderr),377- all: handleOutput(parsed.options, result.all),375+ stdout: result.stdout,376+ stderr: result.stderr,377+ all: result.all,378 code: 0,379 exitCode: 0,380 exitCodeName: 'SUCCESS',381 failed: false,42 unmodified lines424 }425 426 const result = childProcess.spawnSync(parsed.command, parsed.args, parsed.options);427 result.code = result.status;428+ result.stdout = handleOutput(parsed.options, result.stdout);429+ result.stderr = handleOutput(parsed.options, result.stderr);430 431 if (result.error || result.status !== 0 || result.signal !== null) {432 const error = makeError(result, {433 joinedCommand,9 unmodified lines443 throw error;444 }445 446 return {445- stdout: handleOutput(parsed.options, result.stdout),446- stderr: handleOutput(parsed.options, result.stderr),447+ stdout: result.stdout,448+ stderr: result.stderr,449 code: 0,450 exitCode: 0,451 exitCodeName: 'SUCCESS',452 failed: false,6 unmodified linesmodified:test.js+21 added-1 removed
118 unmodified lines119 const error = execa.sync('fail', {reject: false});120 t.is(error.exitCode, 2);121 });122 123-test('stripFinalNewline option', async t => {123+test('stripFinalNewline: true', async t => {124+ const {stdout} = await execa('noop', ['foo']);125+ t.is(stdout, 'foo');126+});127+128+test('stripFinalNewline: false', async t => {129 const {stdout} = await execa('noop', ['foo'], {stripFinalNewline: false});130 t.is(stdout, 'foo\n');131 });132 133+test('stripFinalNewline on failure', async t => {134+ const {stderr} = await t.throwsAsync(execa('noop-throw', ['foo'], {stripFinalNewline: true}));135+ t.is(stderr, 'foo');136+});137+138+test('stripFinalNewline in sync mode', t => {139+ const {stdout} = execa.sync('noop', ['foo'], {stripFinalNewline: true});140+ t.is(stdout, 'foo');141+});142+143+test('stripFinalNewline in sync mode on failure', t => {144+ const {stderr} = t.throws(() => execa.sync('noop-throw', ['foo'], {stripFinalNewline: true}));145+ t.is(stderr, 'foo');146+});147+148 test('preferLocal option', async t => {149 await execa('ava', ['--version'], {env: {PATH: ''}});150 const errorRegExp = process.platform === 'win32' ? /failed with exit code 1/ : /spawn ava ENOENT/;151 await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), errorRegExp);510 unmodified lines