Skip to content
Myr

error.js

This file

Path

test/verbose/error.js

145 lines · 7.5 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 1–3why, one step back
1import test from 'ava';
2import {red} from 'yoctocolors';3import {execa} from '../../index.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 4why, one step back
4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Print errors with verbose option (#890)ehmickybefore adoption209f78f

line 5why, one step back
5import {foobarString} from '../helpers/input.js';

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 6why, one step back
6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 7–8why, one step back
7import {
8 QUOTE,

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

lines 9–12why, one step back
9 runErrorSubprocessAsync,
10 runErrorSubprocessSync,11 runEarlyErrorSubprocessAsync,12 runEarlyErrorSubprocessSync,

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 13–16why, one step back
13 getErrorLine,
14 getErrorLines,15 testTimestamp,16 getVerboseOption,

Allow setting different `verbose` values for `stdout`/`stderr` (#970)ehmickybefore adoption6f279c0

lines 17–19why, one step back
17 fdNoneOption,
18 fdShortOption,19 fdFullOption,

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 20–21why, one step back
20} from '../helpers/verbose.js';
21

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 22why, one step back
22setFixtureDirectory();

Print errors with verbose option (#890)ehmickybefore adoption209f78f

line 23why, one step back
23

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 24why, one step back
24const parentExecaFail = parentExeca.bind(undefined, 'nested-fail.js');

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 25–26why, one step back
25
26const testPrintError = async (t, verbose, execaMethod) => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 27why, one step back
27 const stderr = await execaMethod(t, verbose);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 28–30why, one step back
28 t.is(getErrorLine(stderr), `${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`);
29};30

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

lines 31–32why, one step back
31test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);
32test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);

Allow setting different `verbose` values for `stdout`/`stderr` (#970)ehmickybefore adoption6f279c0

lines 33–34why, one step back
33test('Prints error, verbose "short", fd-specific', testPrintError, fdShortOption, runErrorSubprocessAsync);
34test('Prints error, verbose "full", fd-specific', testPrintError, fdFullOption, runErrorSubprocessAsync);

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

lines 35–36why, one step back
35test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);
36test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);

Allow setting different `verbose` values for `stdout`/`stderr` (#970)ehmickybefore adoption6f279c0

lines 37–38why, one step back
37test('Prints error, verbose "short", fd-specific, sync', testPrintError, fdShortOption, runErrorSubprocessSync);
38test('Prints error, verbose "full", fd-specific, sync', testPrintError, fdFullOption, runErrorSubprocessSync);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

line 39why, one step back
39

Allow setting different `verbose` values for `stdout`/`stderr` (#970)ehmickybefore adoption6f279c0

lines 40–41why, one step back
40const testNoPrintError = async (t, verbose, execaMethod) => {
41 const stderr = await execaMethod(t, verbose, false);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 42–44why, one step back
42 t.is(getErrorLine(stderr), undefined);
43};44

Allow setting different `verbose` values for `stdout`/`stderr` (#970)ehmickybefore adoption6f279c0

lines 45–52why, one step back
45test('Does not print error, verbose "none"', testNoPrintError, 'none', runErrorSubprocessAsync);
46test('Does not print error, verbose default', testNoPrintError, undefined, runErrorSubprocessAsync);47test('Does not print error, verbose "none", fd-specific', testNoPrintError, fdNoneOption, runErrorSubprocessAsync);48test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, runErrorSubprocessAsync);49test('Does not print error, verbose "none", sync', testNoPrintError, 'none', runErrorSubprocessSync);50test('Does not print error, verbose default, sync', testNoPrintError, undefined, runErrorSubprocessSync);51test('Does not print error, verbose "none", fd-specific, sync', testNoPrintError, fdNoneOption, runErrorSubprocessSync);52test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, runErrorSubprocessSync);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 53–58why, one step back
53
54const testPrintNoError = async (t, execaMethod) => {55 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});56 t.is(getErrorLine(stderr), undefined);57};58

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

lines 59–60why, one step back
59test('Does not print error if none', testPrintNoError, parentExecaAsync);
60test('Does not print error if none, sync', testPrintNoError, parentExecaSync);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 61–62why, one step back
61
62const testPrintErrorEarly = async (t, execaMethod) => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

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

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 64–66why, one step back
64 t.is(getErrorLine(stderr), `${testTimestamp} [0] × TypeError: The "cwd" option must be a string or a file URL: true.`);
65};66

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

lines 67–68why, one step back
67test('Prints early validation error', testPrintErrorEarly, runEarlyErrorSubprocessAsync);
68test('Prints early validation error, sync', testPrintErrorEarly, runEarlyErrorSubprocessSync);

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 69–70why, one step back
69
70test('Does not repeat stdout|stderr with error', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 71why, one step back
71 const stderr = await runErrorSubprocessAsync(t, 'short');

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 72–75why, one step back
72 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);
73});7475test('Prints error differently if "reject" is false', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 76why, one step back
76 const {stderr} = await parentExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 77–95why, one step back
77 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] ‼ Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);
78});7980const testPipeError = async (t, fixtureName, sourceVerbose, destinationVerbose) => {81 const {stderr} = await t.throwsAsync(execa(`nested-pipe-${fixtureName}.js`, [82 JSON.stringify(getVerboseOption(sourceVerbose)),83 'noop-fail.js',84 '1',85 JSON.stringify(getVerboseOption(destinationVerbose)),86 'stdin-fail.js',87 ]));8889 const lines = getErrorLines(stderr);90 t.is(lines.includes(`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1`), sourceVerbose);91 t.is(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] × Command failed with exit code 2: stdin-fail.js`), destinationVerbose);92};9394test('Prints both errors piped with .pipe("file")', testPipeError, 'file', true, true);95test('Prints both errors piped with .pipe`command`', testPipeError, 'script', true, true);

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

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

Print errors with verbose option (#890)ehmickybefore adoption209f78f

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

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

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

Print errors with verbose option (#890)ehmickybefore adoption209f78f

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

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

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

Print errors with verbose option (#890)ehmickybefore adoption209f78f

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

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

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

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 106–107why, one step back
106
107test('Quotes spaces from error', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 108why, one step back
108 const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['foo bar'], {verbose: 'short'}));

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 109–115why, one step back
109 t.deepEqual(getErrorLines(stderr), [
110 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}foo bar${QUOTE}`,111 `${testTimestamp} [0] × foo bar`,112 ]);113});114115test('Quotes special punctuation from error', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 116why, one step back
116 const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['%'], {verbose: 'short'}));

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 117–123why, one step back
117 t.deepEqual(getErrorLines(stderr), [
118 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}%${QUOTE}`,119 `${testTimestamp} [0] × %`,120 ]);121});122123test('Does not escape internal characters from error', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 124why, one step back
124 const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['ã'], {verbose: 'short'}));

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 125–131why, one step back
125 t.deepEqual(getErrorLines(stderr), [
126 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}ã${QUOTE}`,127 `${testTimestamp} [0] × ã`,128 ]);129});130131test('Escapes and strips color sequences from error', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 132why, one step back
132 const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 133–139why, one step back
133 t.deepEqual(getErrorLines(stderr), [
134 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,135 `${testTimestamp} [0] × ${foobarString}`,136 ]);137});138139test('Escapes control characters from error', async t => {

Add tests for `node:worker_threads` (#964)ehmickybefore adoptiona1cd3cf

line 140why, one step back
140 const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['\u0001'], {verbose: 'short'}));

Print errors with verbose option (#890)ehmickybefore adoption209f78f

lines 141–145why, one step back
141 t.deepEqual(getErrorLines(stderr), [
142 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u0001${QUOTE}`,143 `${testTimestamp} [0] × \\u0001`,144 ]);145});