Skip to content
Myr

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

3 files+36 added−10 removed

added:fixtures/noop-throw+4 added
1#!/usr/bin/env node2'use strict';3console.error(process.argv[2]);4process.exit(2);
modified:index.js+11 added-9 removed
348 unmodified lines
349350 const finalize = async () => {351 const results = await processComplete;352353 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);357358 if (result.error || result.code !== 0 || result.signal !== null) {359 const error = makeError(result, {360 joinedCommand,
10 unmodified lines
371 throw error;372 }373374 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 lines
424 }425426 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);430431 if (result.error || result.status !== 0 || result.signal !== null) {432 const error = makeError(result, {433 joinedCommand,
9 unmodified lines
443 throw error;444 }445446 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 lines
modified:test.js+21 added-1 removed
118 unmodified lines
119 const error = execa.sync('fail', {reject: false});120 t.is(error.exitCode, 2);121});122123test('stripFinalNewline option', async t => {123test('stripFinalNewline: true', async t => {124 const {stdout} = await execa('noop', ['foo']);125 t.is(stdout, 'foo');126});127128test('stripFinalNewline: false', async t => {129 const {stdout} = await execa('noop', ['foo'], {stripFinalNewline: false});130 t.is(stdout, 'foo\n');131});132133test('stripFinalNewline on failure', async t => {134 const {stderr} = await t.throwsAsync(execa('noop-throw', ['foo'], {stripFinalNewline: true}));135 t.is(stderr, 'foo');136});137138test('stripFinalNewline in sync mode', t => {139 const {stdout} = execa.sync('noop', ['foo'], {stripFinalNewline: true});140 t.is(stdout, 'foo');141});142143test('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});147148test('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