Skip to content
Myr

error.js

This file

Path

test/verbose/error.js

132 lines · 6.4 KiB · JavaScript

Last changed by

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

History of this file

Take it

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 1–10why, one step back
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,

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 11why, one step back
11 runEarlyErrorSubprocess,

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 12–49why, one step back
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) => {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 50why, one step back
50 const stderr = await runEarlyErrorSubprocess(t, execaMethod);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 51–82why, one step back
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);

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 83why, one step back
83test('Prints both errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', true, true);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 84–85why, one step back
84test('Prints first error piped with .pipe("file")', testPipeError, 'file', true, false);
85test('Prints first error piped with .pipe`command`', testPipeError, 'script', true, false);

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 86why, one step back
86test('Prints first error piped with .pipe(subprocess)', testPipeError, 'subprocesses', true, false);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 87–88why, one step back
87test('Prints second error piped with .pipe("file")', testPipeError, 'file', false, true);
88test('Prints second error piped with .pipe`command`', testPipeError, 'script', false, true);

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 89why, one step back
89test('Prints second error piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, true);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 90–91why, one step back
90test('Prints neither errors piped with .pipe("file")', testPipeError, 'file', false, false);
91test('Prints neither errors piped with .pipe`command`', testPipeError, 'script', false, false);

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 92why, one step back
92test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, false);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 93–132why, one step back
93
94test('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});