message.js
This file
Path
test/return/message.js
135 lines · 9.2 KiB · JavaScript
Last changed by
Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff
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
lines 4–6why, one step back4import {execa, execaSync} from '../../index.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 7why, one step back7import {foobarString, foobarObject, foobarObjectInspect} from '../helpers/input.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 8–12why, one step back8import {QUOTE} from '../helpers/verbose.js';9import {noopGenerator, outputObjectGenerator} from '../helpers/generator.js';1011setFixtureDirectory();12TweaksSindre Sorhusbefore adoption698a1b8
lines 13–14why, one step back13test('error.message contains the command', async () => {14 await assertRejects(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 15–16why, one step back15});16TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17const testStdioMessage = async (encoding, all, objectMode, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 18–23why, one step back18 const {exitCode, message} = await execaMethod('echo-fail.js', {19 ...getStdio(1, noopGenerator(objectMode, false, true), 4),20 encoding,21 all,22 reject: false,23 });TweaksSindre Sorhusbefore adoption698a1b8
line 24why, one step back24 assert.equal(exitCode, 1);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 25why, one step back25 const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';TweaksSindre Sorhusbefore adoption698a1b8
line 26why, one step back26 assert.ok(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 27–28why, one step back27};28TweaksSindre Sorhusbefore adoption698a1b8
lines 29–44why, one step back29test('error.message contains stdout/stderr/stdio if available', () => testStdioMessage('utf8', false, false, execa));30test('error.message contains stdout/stderr/stdio even with encoding "buffer"', () => testStdioMessage('buffer', false, false, execa));31test('error.message contains all if available', () => testStdioMessage('utf8', true, false, execa));32test('error.message contains all even with encoding "buffer"', () => testStdioMessage('buffer', true, false, execa));33test('error.message contains stdout/stderr/stdio if available, objectMode', () => testStdioMessage('utf8', false, true, execa));34test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', () => testStdioMessage('buffer', false, true, execa));35test('error.message contains all if available, objectMode', () => testStdioMessage('utf8', true, true, execa));36test('error.message contains all even with encoding "buffer", objectMode', () => testStdioMessage('buffer', true, true, execa));37test('error.message contains stdout/stderr/stdio if available, sync', () => testStdioMessage('utf8', false, false, execaSync));38test('error.message contains stdout/stderr/stdio even with encoding "buffer", sync', () => testStdioMessage('buffer', false, false, execaSync));39test('error.message contains all if available, sync', () => testStdioMessage('utf8', true, false, execaSync));40test('error.message contains all even with encoding "buffer", sync', () => testStdioMessage('buffer', true, false, execaSync));41test('error.message contains stdout/stderr/stdio if available, objectMode, sync', () => testStdioMessage('utf8', false, true, execaSync));42test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode, sync', () => testStdioMessage('buffer', false, true, execaSync));43test('error.message contains all if available, objectMode, sync', () => testStdioMessage('utf8', true, true, execaSync));44test('error.message contains all even with encoding "buffer", objectMode, sync', () => testStdioMessage('buffer', true, true, execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 45why, one step back45TweaksSindre Sorhusbefore adoption698a1b8
line 46why, one step back46const testLinesMessage = async (encoding, stripFinalNewline, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 47–52why, one step back47 const {failed, message} = await execaMethod('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {48 lines: true,49 encoding,50 stripFinalNewline,51 reject: false,52 });TweaksSindre Sorhusbefore adoption698a1b8
lines 53–54why, one step back53 assert.equal(failed, true);54 assert.ok(message.endsWith(`noop-fail.js 1 ${QUOTE}${foobarString}\\n${foobarString}\\n${QUOTE}\n\n${foobarString}\n${foobarString}`));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 55–56why, one step back55};56TweaksSindre Sorhusbefore adoption698a1b8
lines 57–64why, one step back57test('error.message handles "lines: true"', () => testLinesMessage('utf8', false, execa));58test('error.message handles "lines: true", stripFinalNewline', () => testLinesMessage('utf8', true, execa));59test('error.message handles "lines: true", buffer', () => testLinesMessage('buffer', false, execa));60test('error.message handles "lines: true", buffer, stripFinalNewline', () => testLinesMessage('buffer', true, execa));61test('error.message handles "lines: true", sync', () => testLinesMessage('utf8', false, execaSync));62test('error.message handles "lines: true", stripFinalNewline, sync', () => testLinesMessage('utf8', true, execaSync));63test('error.message handles "lines: true", buffer, sync', () => testLinesMessage('buffer', false, execaSync));64test('error.message handles "lines: true", buffer, stripFinalNewline, sync', () => testLinesMessage('buffer', true, execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 65why, one step back65Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff
lines 66–80why, one step back66// `lines: true` must not change `error.message`, including its empty lines67const testLinesMessageEmptyLines = async (output, stripFinalNewline, execaMethod) => {68 const options = {stripFinalNewline, reject: false};69 const {message} = await execaMethod('noop-fail.js', ['1', output], options);70 const {message: linesMessage} = await execaMethod('noop-fail.js', ['1', output], {...options, lines: true});71 assert.equal(linesMessage, message);72};7374test('error.message keeps empty lines with "lines: true"', () => testLinesMessageEmptyLines(`${foobarString}\n\n${foobarString}\n`, true, execa));75test('error.message keeps empty lines with "lines: true", stripFinalNewline false', () => testLinesMessageEmptyLines(`${foobarString}\n\n${foobarString}\n`, false, execa));76test('error.message keeps several empty lines with "lines: true"', () => testLinesMessageEmptyLines(`${foobarString}\n\n\n\n${foobarString}`, true, execa));77test('error.message keeps leading empty lines with "lines: true"', () => testLinesMessageEmptyLines(`\n\n${foobarString}`, true, execa));78test('error.message keeps empty lines with "lines: true", sync', () => testLinesMessageEmptyLines(`${foobarString}\n\n${foobarString}\n`, true, execaSync));79test('error.message keeps empty lines with "lines: true", stripFinalNewline false, sync', () => testLinesMessageEmptyLines(`${foobarString}\n\n${foobarString}\n`, false, execaSync));80TweaksSindre Sorhusbefore adoption698a1b8
lines 81–83why, one step back81const testPartialIgnoreMessage = async (fdNumber, stdioOption, output) => {82 const {message} = await assertRejects(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));83 assert.ok(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 84–85why, one step back84};85TweaksSindre Sorhusbefore adoption698a1b8
lines 86–89why, one step back86test('error.message does not contain stdout if not available', () => testPartialIgnoreMessage(1, 'ignore', 'stderr'));87test('error.message does not contain stderr if not available', () => testPartialIgnoreMessage(2, 'ignore', 'stdout'));88test('error.message does not contain stdout if it is an object', () => testPartialIgnoreMessage(1, outputObjectGenerator(), 'stderr'));89test('error.message does not contain stderr if it is an object', () => testPartialIgnoreMessage(2, outputObjectGenerator(), 'stdout'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 90why, one step back90TweaksSindre Sorhusbefore adoption698a1b8
lines 91–92why, one step back91const testFullIgnoreMessage = async (options, resultProperty) => {92 const result = await assertRejects(execa('echo-fail.js', options));Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 93why, one step back93 const message = result[resultProperty];TweaksSindre Sorhusbefore adoption698a1b8
lines 94–96why, one step back94 assert.ok(!message.includes('stderr'));95 assert.ok(!message.includes('stdout'));96 assert.ok(!message.includes('fd3'));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 97–98why, one step back97};98TweaksSindre Sorhusbefore adoption698a1b8
lines 99–100why, one step back99test('error.message does not contain stdout/stderr/stdio if not available', () => testFullIgnoreMessage({stdio: 'ignore'}, 'message'));100test('error.shortMessage does not contain stdout/stderr/stdio', () => testFullIgnoreMessage(fullStdio, 'shortMessage'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 101why, one step back101TweaksSindre Sorhusbefore adoption698a1b8
lines 102–104why, one step back102const testErrorMessageConsistent = async stdout => {103 const {message} = await assertRejects(execa('noop-both-fail-strict.js', [stdout, 'stderr']));104 assert.ok(message.endsWith(' stderr\n\nstderr\n\nstdout'));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 105–106why, one step back105};106TweaksSindre Sorhusbefore adoption698a1b8
lines 107–108why, one step back107test('error.message newlines are consistent - no newline', () => testErrorMessageConsistent('stdout'));108test('error.message newlines are consistent - newline', () => testErrorMessageConsistent('stdout\n'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 109why, one step back109TweaksSindre Sorhusbefore adoption698a1b8
lines 110–112why, one step back110test('Original error.message is kept', async () => {111 const {originalMessage} = await assertRejects(execa('noop.js', {windowsHide: 'true'}));112 assert.equal(originalMessage, 'The "options.windowsHide" property must be of type boolean. Received type string (\'true\')');Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 113–114why, one step back113});114TweaksSindre Sorhusbefore adoption698a1b8
line 115why, one step back115const testIpcOutput = async (doubles, ipcInput, returnedMessage) => {Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 116why, one step back116 const fixtureName = doubles ? 'ipc-echo-twice-fail.js' : 'ipc-echo-fail.js';TweaksSindre Sorhusbefore adoption698a1b8
lines 117–120why, one step back117 const {exitCode, message, ipcOutput} = await assertRejects(execa(fixtureName, {ipcInput}));118 assert.equal(exitCode, 1);119 assert.ok(message.endsWith(`\n\n${doubles ? `${returnedMessage}\n${returnedMessage}` : returnedMessage}`));120 assert.deepEqual(ipcOutput, doubles ? [ipcInput, ipcInput] : [ipcInput]);Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 121–122why, one step back121};122TweaksSindre Sorhusbefore adoption698a1b8
lines 123–128why, one step back123test('error.message contains IPC messages, single string', () => testIpcOutput(false, foobarString, foobarString));124test('error.message contains IPC messages, two strings', () => testIpcOutput(true, foobarString, foobarString));125test('error.message contains IPC messages, single object', () => testIpcOutput(false, foobarObject, foobarObjectInspect));126test('error.message contains IPC messages, two objects', () => testIpcOutput(true, foobarObject, foobarObjectInspect));127test('error.message contains IPC messages, multiline string', () => testIpcOutput(false, `${foobarString}\n${foobarString}`, `${foobarString}\n${foobarString}`));128test('error.message contains IPC messages, control characters', () => testIpcOutput(false, '\0', '\\u0000'));Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 129why, one step back129TweaksSindre Sorhusbefore adoption698a1b8
lines 130–134why, one step back130test('error.message does not contain IPC messages, buffer false', async () => {131 const {exitCode, message, ipcOutput} = await assertRejects(execa('ipc-echo-fail.js', {ipcInput: foobarString, buffer: false}));132 assert.equal(exitCode, 1);133 assert.ok(message.endsWith('ipc-echo-fail.js'));134 assert.deepEqual(ipcOutput, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 135why, one step back135});