error.js
This file
Path
test/verbose/error.js
168 lines · 9.8 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';3import {assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 4why, one step back4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 5why, one step back5import {foobarString, foobarRed} from '../helpers/input.js';Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 6why, one step back6import {nestedSubprocess} from '../helpers/nested.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 7–8why, one step back7import {8 QUOTE,Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
lines 9–10why, one step back9 runErrorSubprocess,10 runEarlyErrorSubprocess,100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 11–14why, one step back11 getErrorLine,12 getErrorLines,13 testTimestamp,14 getVerboseOption,Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
line 15why, one step back15 getStdioForFd3Option,Add more tests for the `verbose` option (#1127)ehmickybefore adoption37e0024
lines 16–27why, one step back16 stdoutNoneOption,17 stdoutShortOption,18 stdoutFullOption,19 stderrNoneOption,20 stderrShortOption,21 stderrFullOption,22 fd3NoneOption,23 fd3ShortOption,24 fd3FullOption,25 ipcNoneOption,26 ipcShortOption,27 ipcFullOption,100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–31why, one step back28} from '../helpers/verbose.js';2930setFixtureDirectory();31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–34why, one step back32const testPrintError = async (verbose, isSync) => {33 const stderr = await runErrorSubprocess(verbose, isSync, getStdioForFd3Option(verbose));34 assert.equal(getErrorLine(stderr), `${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 35–36why, one step back35};36TweaksSindre Sorhusbefore adoption698a1b8
lines 37–56why, one step back37test('Prints error, verbose "short"', () => testPrintError('short', false));38test('Prints error, verbose "full"', () => testPrintError('full', false));39test('Prints error, verbose "short", fd-specific stdout', () => testPrintError(stdoutShortOption, false));40test('Prints error, verbose "full", fd-specific stdout', () => testPrintError(stdoutFullOption, false));41test('Prints error, verbose "short", fd-specific stderr', () => testPrintError(stderrShortOption, false));42test('Prints error, verbose "full", fd-specific stderr', () => testPrintError(stderrFullOption, false));43test('Prints error, verbose "short", fd-specific fd3', () => testPrintError(fd3ShortOption, false));44test('Prints error, verbose "full", fd-specific fd3', () => testPrintError(fd3FullOption, false));45test('Prints error, verbose "short", fd-specific ipc', () => testPrintError(ipcShortOption, false));46test('Prints error, verbose "full", fd-specific ipc', () => testPrintError(ipcFullOption, false));47test('Prints error, verbose "short", sync', () => testPrintError('short', true));48test('Prints error, verbose "full", sync', () => testPrintError('full', true));49test('Prints error, verbose "short", fd-specific stdout, sync', () => testPrintError(stdoutShortOption, true));50test('Prints error, verbose "full", fd-specific stdout, sync', () => testPrintError(stdoutFullOption, true));51test('Prints error, verbose "short", fd-specific stderr, sync', () => testPrintError(stderrShortOption, true));52test('Prints error, verbose "full", fd-specific stderr, sync', () => testPrintError(stderrFullOption, true));53test('Prints error, verbose "short", fd-specific fd3, sync', () => testPrintError(fd3ShortOption, true));54test('Prints error, verbose "full", fd-specific fd3, sync', () => testPrintError(fd3FullOption, true));55test('Prints error, verbose "short", fd-specific ipc, sync', () => testPrintError(ipcShortOption, true));56test('Prints error, verbose "full", fd-specific ipc, sync', () => testPrintError(ipcFullOption, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 57why, one step back57TweaksSindre Sorhusbefore adoption698a1b8
lines 58–60why, one step back58const testNoPrintError = async (verbose, isSync) => {59 const stderr = await runErrorSubprocess(verbose, isSync, {expectExitCode: false, ...getStdioForFd3Option(verbose)});60 assert.equal(getErrorLine(stderr), undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 61–62why, one step back61};62TweaksSindre Sorhusbefore adoption698a1b8
lines 63–76why, one step back63test('Does not print error, verbose "none"', () => testNoPrintError('none', false));64test('Does not print error, verbose default', () => testNoPrintError(undefined, false));65test('Does not print error, verbose "none", fd-specific stdout', () => testNoPrintError(stdoutNoneOption, false));66test('Does not print error, verbose "none", fd-specific stderr', () => testNoPrintError(stderrNoneOption, false));67test('Does not print error, verbose "none", fd-specific fd3', () => testNoPrintError(fd3NoneOption, false));68test('Does not print error, verbose "none", fd-specific ipc', () => testNoPrintError(ipcNoneOption, false));69test('Does not print error, verbose default, fd-specific', () => testNoPrintError({}, false));70test('Does not print error, verbose "none", sync', () => testNoPrintError('none', true));71test('Does not print error, verbose default, sync', () => testNoPrintError(undefined, true));72test('Does not print error, verbose "none", fd-specific stdout, sync', () => testNoPrintError(stdoutNoneOption, true));73test('Does not print error, verbose "none", fd-specific stderr, sync', () => testNoPrintError(stderrNoneOption, true));74test('Does not print error, verbose "none", fd-specific fd3, sync', () => testNoPrintError(fd3NoneOption, true));75test('Does not print error, verbose "none", fd-specific ipc, sync', () => testNoPrintError(ipcNoneOption, true));76test('Does not print error, verbose default, fd-specific, sync', () => testNoPrintError({}, true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 77why, one step back77TweaksSindre Sorhusbefore adoption698a1b8
line 78why, one step back78const testPrintNoError = async isSync => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 79why, one step back79 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short', isSync});TweaksSindre Sorhusbefore adoption698a1b8
line 80why, one step back80 assert.equal(getErrorLine(stderr), undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 81–82why, one step back81};82TweaksSindre Sorhusbefore adoption698a1b8
lines 83–84why, one step back83test('Does not print error if none', () => testPrintNoError(false));84test('Does not print error if none, sync', () => testPrintNoError(true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 85why, one step back85TweaksSindre Sorhusbefore adoption698a1b8
lines 86–88why, one step back86const testPrintErrorEarly = async isSync => {87 const stderr = await runEarlyErrorSubprocess(isSync);88 assert.equal(getErrorLine(stderr), undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 89–90why, one step back89};90TweaksSindre Sorhusbefore adoption698a1b8
lines 91–92why, one step back91test('Prints early validation error', () => testPrintErrorEarly(false));92test('Prints early validation error, sync', () => testPrintErrorEarly(true));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 93why, one step back93TweaksSindre Sorhusbefore adoption698a1b8
lines 94–96why, one step back94test('Does not repeat stdout|stderr with error', async () => {95 const stderr = await runErrorSubprocess('short');96 assert.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 97–98why, one step back97});98TweaksSindre Sorhusbefore adoption698a1b8
line 99why, one step back99test('Prints error differently if "reject" is false', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 100why, one step back100 const {stderr} = await nestedSubprocess('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});TweaksSindre Sorhusbefore adoption698a1b8
line 101why, one step back101 assert.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] ‼ Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 102–103why, one step back102});103TweaksSindre Sorhusbefore adoption698a1b8
lines 104–105why, one step back104const testPipeError = async (parentFixture, sourceVerbose, destinationVerbose) => {105 const {stderr} = await assertRejects(nestedSubprocess('noop-fail.js', ['1'], {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
lines 106–110why, one step back106 parentFixture,107 sourceOptions: getVerboseOption(sourceVerbose),108 destinationFile: 'stdin-fail.js',109 destinationOptions: getVerboseOption(destinationVerbose),110 }));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 111–112why, one step back111112 const lines = getErrorLines(stderr);TweaksSindre Sorhusbefore adoption698a1b8
lines 113–114why, one step back113 assert.equal(lines.includes(`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1`), sourceVerbose);114 assert.equal(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] × Command failed with exit code 2: stdin-fail.js`), destinationVerbose);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 115–116why, one step back115};116TweaksSindre Sorhusbefore adoption698a1b8
lines 117–128why, one step back117test('Prints both errors piped with .pipe("file")', () => testPipeError('nested-pipe-file.js', true, true));118test('Prints both errors piped with .pipe`command`', () => testPipeError('nested-pipe-script.js', true, true));119test('Prints both errors piped with .pipe(subprocess)', () => testPipeError('nested-pipe-subprocesses.js', true, true));120test('Prints first error piped with .pipe("file")', () => testPipeError('nested-pipe-file.js', true, false));121test('Prints first error piped with .pipe`command`', () => testPipeError('nested-pipe-script.js', true, false));122test('Prints first error piped with .pipe(subprocess)', () => testPipeError('nested-pipe-subprocesses.js', true, false));123test('Prints second error piped with .pipe("file")', () => testPipeError('nested-pipe-file.js', false, true));124test('Prints second error piped with .pipe`command`', () => testPipeError('nested-pipe-script.js', false, true));125test('Prints second error piped with .pipe(subprocess)', () => testPipeError('nested-pipe-subprocesses.js', false, true));126test('Prints neither errors piped with .pipe("file")', () => testPipeError('nested-pipe-file.js', false, false));127test('Prints neither errors piped with .pipe`command`', () => testPipeError('nested-pipe-script.js', false, false));128test('Prints neither errors piped with .pipe(subprocess)', () => testPipeError('nested-pipe-subprocesses.js', false, false));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 129why, one step back129TweaksSindre Sorhusbefore adoption698a1b8
lines 130–132why, one step back130test('Quotes spaces from error', async () => {131 const {stderr} = await assertRejects(nestedSubprocess('noop-forever.js', ['foo bar'], {parentFixture: 'nested-fail.js', verbose: 'short'}));132 assert.deepEqual(getErrorLines(stderr), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 133–137why, one step back133 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}foo bar${QUOTE}`,134 `${testTimestamp} [0] × foo bar`,135 ]);136});137TweaksSindre Sorhusbefore adoption698a1b8
lines 138–140why, one step back138test('Quotes special punctuation from error', async () => {139 const {stderr} = await assertRejects(nestedSubprocess('noop-forever.js', ['%'], {parentFixture: 'nested-fail.js', verbose: 'short'}));140 assert.deepEqual(getErrorLines(stderr), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 141–145why, one step back141 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}%${QUOTE}`,142 `${testTimestamp} [0] × %`,143 ]);144});145TweaksSindre Sorhusbefore adoption698a1b8
lines 146–148why, one step back146test('Does not escape internal characters from error', async () => {147 const {stderr} = await assertRejects(nestedSubprocess('noop-forever.js', ['ã'], {parentFixture: 'nested-fail.js', verbose: 'short'}));148 assert.deepEqual(getErrorLines(stderr), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 149–153why, one step back149 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}ã${QUOTE}`,150 `${testTimestamp} [0] × ã`,151 ]);152});153TweaksSindre Sorhusbefore adoption698a1b8
lines 154–156why, one step back154test('Escapes and strips color sequences from error', async () => {155 const {stderr} = await assertRejects(nestedSubprocess('noop-forever.js', [foobarRed], {parentFixture: 'nested-fail.js', verbose: 'short'}));156 assert.deepEqual(getErrorLines(stderr), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 157–161why, one step back157 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,158 `${testTimestamp} [0] × ${foobarString}`,159 ]);160});161TweaksSindre Sorhusbefore adoption698a1b8
lines 162–164why, one step back162test('Escapes control characters from error', async () => {163 const {stderr} = await assertRejects(nestedSubprocess('noop-forever.js', ['\u{1}'], {parentFixture: 'nested-fail.js', verbose: 'short'}));164 assert.deepEqual(getErrorLines(stderr), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 165–168why, one step back165 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u0001${QUOTE}`,166 `${testTimestamp} [0] × \\u0001`,167 ]);168});