message.js
This file
Path
test/return/message.js
96 lines · 5.9 KiB · JavaScript
Last changed by
Upgrade xo (#980)ehmickybefore adoptionccfa412
History of this fileTake it
Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 1–2why, one step back1import test from 'ava';2import {execa, execaSync} from '../../index.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
line 3why, one step back3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 4–8why, one step back4import {fullStdio, getStdio} from '../helpers/stdio.js';5import {foobarString} from '../helpers/input.js';6import {QUOTE} from '../helpers/verbose.js';7import {noopGenerator, outputObjectGenerator} from '../helpers/generator.js';8Upgrade xo (#980)ehmickybefore adoptionccfa412
line 9why, one step back9setFixtureDirectory();Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 10–16why, one step back1011test('error.message contains the command', async t => {12 await t.throwsAsync(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});13});1415// eslint-disable-next-line max-params16const testStdioMessage = async (t, encoding, all, objectMode, execaMethod) => {Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 17–22why, one step back17 const {exitCode, message} = await execaMethod('echo-fail.js', {18 ...getStdio(1, noopGenerator(objectMode, false, true), 4),19 encoding,20 all,21 reject: false,22 });Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 23–96why, one step back23 t.is(exitCode, 1);24 const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';25 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));26};2728test('error.message contains stdout/stderr/stdio if available', testStdioMessage, 'utf8', false, false, execa);29test('error.message contains stdout/stderr/stdio even with encoding "buffer"', testStdioMessage, 'buffer', false, false, execa);30test('error.message contains all if available', testStdioMessage, 'utf8', true, false, execa);31test('error.message contains all even with encoding "buffer"', testStdioMessage, 'buffer', true, false, execa);32test('error.message contains stdout/stderr/stdio if available, objectMode', testStdioMessage, 'utf8', false, true, execa);33test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true, execa);34test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true, execa);35test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true, execa);36test('error.message contains stdout/stderr/stdio if available, sync', testStdioMessage, 'utf8', false, false, execaSync);37test('error.message contains stdout/stderr/stdio even with encoding "buffer", sync', testStdioMessage, 'buffer', false, false, execaSync);38test('error.message contains all if available, sync', testStdioMessage, 'utf8', true, false, execaSync);39test('error.message contains all even with encoding "buffer", sync', testStdioMessage, 'buffer', true, false, execaSync);40test('error.message contains stdout/stderr/stdio if available, objectMode, sync', testStdioMessage, 'utf8', false, true, execaSync);41test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', false, true, execaSync);42test('error.message contains all if available, objectMode, sync', testStdioMessage, 'utf8', true, true, execaSync);43test('error.message contains all even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', true, true, execaSync);4445const testLinesMessage = async (t, encoding, stripFinalNewline, execaMethod) => {46 const {failed, message} = await execaMethod('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {47 lines: true,48 encoding,49 stripFinalNewline,50 reject: false,51 });52 t.true(failed);53 t.true(message.endsWith(`noop-fail.js 1 ${QUOTE}${foobarString}\\n${foobarString}\\n${QUOTE}\n\n${foobarString}\n${foobarString}`));54};5556test('error.message handles "lines: true"', testLinesMessage, 'utf8', false, execa);57test('error.message handles "lines: true", stripFinalNewline', testLinesMessage, 'utf8', true, execa);58test('error.message handles "lines: true", buffer', testLinesMessage, 'buffer', false, execa);59test('error.message handles "lines: true", buffer, stripFinalNewline', testLinesMessage, 'buffer', true, execa);60test('error.message handles "lines: true", sync', testLinesMessage, 'utf8', false, execaSync);61test('error.message handles "lines: true", stripFinalNewline, sync', testLinesMessage, 'utf8', true, execaSync);62test('error.message handles "lines: true", buffer, sync', testLinesMessage, 'buffer', false, execaSync);63test('error.message handles "lines: true", buffer, stripFinalNewline, sync', testLinesMessage, 'buffer', true, execaSync);6465const testPartialIgnoreMessage = async (t, fdNumber, stdioOption, output) => {66 const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));67 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));68};6970test('error.message does not contain stdout if not available', testPartialIgnoreMessage, 1, 'ignore', 'stderr');71test('error.message does not contain stderr if not available', testPartialIgnoreMessage, 2, 'ignore', 'stdout');72test('error.message does not contain stdout if it is an object', testPartialIgnoreMessage, 1, outputObjectGenerator(), 'stderr');73test('error.message does not contain stderr if it is an object', testPartialIgnoreMessage, 2, outputObjectGenerator(), 'stdout');7475const testFullIgnoreMessage = async (t, options, resultProperty) => {76 const {[resultProperty]: message} = await t.throwsAsync(execa('echo-fail.js', options));77 t.false(message.includes('stderr'));78 t.false(message.includes('stdout'));79 t.false(message.includes('fd3'));80};8182test('error.message does not contain stdout/stderr/stdio if not available', testFullIgnoreMessage, {stdio: 'ignore'}, 'message');83test('error.shortMessage does not contain stdout/stderr/stdio', testFullIgnoreMessage, fullStdio, 'shortMessage');8485const testErrorMessageConsistent = async (t, stdout) => {86 const {message} = await t.throwsAsync(execa('noop-both-fail-strict.js', [stdout, 'stderr']));87 t.true(message.endsWith(' stderr\n\nstderr\n\nstdout'));88};8990test('error.message newlines are consistent - no newline', testErrorMessageConsistent, 'stdout');91test('error.message newlines are consistent - newline', testErrorMessageConsistent, 'stdout\n');9293test('Original error.message is kept', async t => {94 const {originalMessage} = await t.throwsAsync(execa('noop.js', {uid: true}));95 t.is(originalMessage, 'The "options.uid" property must be int32. Received type boolean (true)');96});