Skip to content
Myr

Print errors with verbose option (#890)

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

authored by ehmicky · committed by GitHub · parent 7264bcf · Browse files · 7 files+151 added−2 removed
This commit

State

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

Diff stats

7 files+151 added−2 removed

  • tests:+137 added−0 removed
  • other:+14 added−2 removed

7 files+151 added−2 removed

modified:lib/verbose/complete.js+2 added
added:lib/verbose/error.js+10 added
modified:test/helpers/verbose.js+4 added
added:test/verbose/error.js+132 added
1import test from 'ava';2import {red} from 'yoctocolors';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {foobarString} from '../helpers/input.js';6import {7 QUOTE,8 nestedExeca,9 nestedExecaAsync,10 nestedExecaSync,11 runEarlyErrorProcess,12 getErrorLine,13 getErrorLines,14 testTimestamp,15 getVerboseOption,16} from '../helpers/verbose.js';1718setFixtureDir();1920const nestedExecaFail = nestedExeca.bind(undefined, 'nested-fail.js');2122const testPrintError = async (t, verbose, execaMethod) => {23 const {stderr} = await t.throwsAsync(execaMethod('noop-fail.js', ['1', foobarString], {verbose}));24 t.is(getErrorLine(stderr), `${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`);25};2627test('Prints error, verbose "short"', testPrintError, 'short', nestedExecaAsync);28test('Prints error, verbose "full"', testPrintError, 'full', nestedExecaAsync);29test('Prints error, verbose "short", sync', testPrintError, 'short', nestedExecaSync);30test('Prints error, verbose "full", sync', testPrintError, 'full', nestedExecaSync);3132const testNoPrintError = async (t, execaMethod) => {33 const {stderr} = await t.throwsAsync(execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'none'}));34 t.not(stderr, '');35 t.is(getErrorLine(stderr), undefined);36};3738test('Does not print error, verbose "none"', testNoPrintError, nestedExecaAsync);39test('Does not print error, verbose "none", sync', testNoPrintError, nestedExecaSync);4041const testPrintNoError = async (t, execaMethod) => {42 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});43 t.is(getErrorLine(stderr), undefined);44};4546test('Does not print error if none', testPrintNoError, nestedExecaAsync);47test('Does not print error if none, sync', testPrintNoError, nestedExecaSync);4849const testPrintErrorEarly = async (t, execaMethod) => {50 const stderr = await runEarlyErrorProcess(t, execaMethod);51 t.is(getErrorLine(stderr), `${testTimestamp} [0] × TypeError: The "cwd" option must be a string or a file URL: true.`);52};5354test('Prints early validation error', testPrintErrorEarly, nestedExecaAsync);55test('Prints early validation error, sync', testPrintErrorEarly, nestedExecaSync);5657test('Does not repeat stdout|stderr with error', async t => {58 const {stderr} = await t.throwsAsync(nestedExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short'}));59 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);60});6162test('Prints error differently if "reject" is false', async t => {63 const {stderr} = await nestedExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});64 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] ‼ Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);65});6667const testPipeError = async (t, fixtureName, sourceVerbose, destinationVerbose) => {68 const {stderr} = await t.throwsAsync(execa(`nested-pipe-${fixtureName}.js`, [69 JSON.stringify(getVerboseOption(sourceVerbose)),70 'noop-fail.js',71 '1',72 JSON.stringify(getVerboseOption(destinationVerbose)),73 'stdin-fail.js',74 ]));7576 const lines = getErrorLines(stderr);77 t.is(lines.includes(`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1`), sourceVerbose);78 t.is(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] × Command failed with exit code 2: stdin-fail.js`), destinationVerbose);79};8081test('Prints both errors piped with .pipe("file")', testPipeError, 'file', true, true);82test('Prints both errors piped with .pipe`command`', testPipeError, 'script', true, true);83test('Prints both errors piped with .pipe(childProcess)', testPipeError, 'process', true, true);84test('Prints first error piped with .pipe("file")', testPipeError, 'file', true, false);85test('Prints first error piped with .pipe`command`', testPipeError, 'script', true, false);86test('Prints first error piped with .pipe(childProcess)', testPipeError, 'process', true, false);87test('Prints second error piped with .pipe("file")', testPipeError, 'file', false, true);88test('Prints second error piped with .pipe`command`', testPipeError, 'script', false, true);89test('Prints second error piped with .pipe(childProcess)', testPipeError, 'process', false, true);90test('Prints neither errors piped with .pipe("file")', testPipeError, 'file', false, false);91test('Prints neither errors piped with .pipe`command`', testPipeError, 'script', false, false);92test('Prints neither errors piped with .pipe(childProcess)', testPipeError, 'process', false, false);9394test('Quotes spaces from error', async t => {95 const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['foo bar'], {verbose: 'short'}));96 t.deepEqual(getErrorLines(stderr), [97 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}foo bar${QUOTE}`,98 `${testTimestamp} [0] × foo bar`,99 ]);100});101102test('Quotes special punctuation from error', async t => {103 const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['%'], {verbose: 'short'}));104 t.deepEqual(getErrorLines(stderr), [105 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}%${QUOTE}`,106 `${testTimestamp} [0] × %`,107 ]);108});109110test('Does not escape internal characters from error', async t => {111 const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['ã'], {verbose: 'short'}));112 t.deepEqual(getErrorLines(stderr), [113 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}ã${QUOTE}`,114 `${testTimestamp} [0] × ã`,115 ]);116});117118test('Escapes and strips color sequences from error', async t => {119 const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));120 t.deepEqual(getErrorLines(stderr), [121 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,122 `${testTimestamp} [0] × ${foobarString}`,123 ]);124});125126test('Escapes control characters from error', async t => {127 const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['\u0001'], {verbose: 'short'}));128 t.deepEqual(getErrorLines(stderr), [129 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u0001${QUOTE}`,130 `${testTimestamp} [0] × \\u0001`,131 ]);132});
modified:test/verbose/info.js+1 added
modified:index.d.ts+1 added-1 removed
541 unmodified lines
542 */543 readonly windowsHide?: boolean;544545 /**546 If `verbose` is `'short'` or `'full'`, prints each command on `stderr` before executing it. When the command completes, prints its duration.546 If `verbose` is `'short'` or `'full'`, prints each command on `stderr` before executing it. When the command completes, prints its duration and (if it failed) its error.547548 If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:549 - the `stdout`/`stderr` option is `ignore` or `inherit`.550 - the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), a file, a file descriptor, or another child process.
835 unmodified lines
modified:readme.md+1 added-1 removed
667 unmodified lines
668669Type: `'none' | 'short' | 'full'`\670Default: `'none'`671672If `verbose` is `'short'` or `'full'`, [prints each command](#verbose-mode) on `stderr` before executing it. When the command completes, prints its duration.672If `verbose` is `'short'` or `'full'`, [prints each command](#verbose-mode) on `stderr` before executing it. When the command completes, prints its duration and (if it failed) its error.673674If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:675- the [`stdout`](#stdout-1)/[`stderr`](#stderr-1) option is `ignore` or `inherit`.676- the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), [a file](#stdout-1), a file descriptor, or [another child process](#pipefile-arguments-options).
373 unmodified lines