Skip to content
Myr

Fix return value being re-used between multiple calls (#796)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 45475e7 · Browse files · 2 files+75 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+75 added−8 removed

  • tests:+64 added−0 removed
  • other:+11 added−8 removed

2 files+75 added−8 removed

modified:lib/error.js+11 added-8 removed
modified:test/error.js+64 added
2 unmodified lines
3import {execa, execaSync} from '../index.js';4import {FIXTURES_DIR, setFixtureDir} from './helpers/fixtures-dir.js';5import {fullStdio, getStdio} from './helpers/stdio.js';6import {noopGenerator, outputObjectGenerator} from './helpers/generator.js';7import {foobarString} from './helpers/input.js';89const isWindows = process.platform === 'win32';1011setFixtureDir();
280 unmodified lines
292 const expectedCwd = process.cwd();293 const {cwd} = await t.throwsAsync(execa('fail.js'));294 t.is(cwd, expectedCwd);295});296297const testUnusualError = async (t, error) => {298 const childProcess = execa('empty.js');299 childProcess.emit('error', error);300 const {message, originalMessage} = await t.throwsAsync(childProcess);301 t.true(message.includes(String(error)));302 t.is(originalMessage, String(error));303};304305test('error instance can be null', testUnusualError, null);306test('error instance can be false', testUnusualError, false);307test('error instance can be a string', testUnusualError, 'test');308test('error instance can be a number', testUnusualError, 0);309test('error instance can be a BigInt', testUnusualError, 0n);310test('error instance can be a symbol', testUnusualError, Symbol('test'));311test('error instance can be a function', testUnusualError, () => {});312test('error instance can be an array', testUnusualError, ['test', 'test']);313314test('error instance can be undefined', async t => {315 const childProcess = execa('empty.js');316 childProcess.emit('error');317 await t.throwsAsync(childProcess, {message: 'Command failed: empty.js'});318});319320test('error instance can be a plain object', async t => {321 const childProcess = execa('empty.js');322 childProcess.emit('error', {message: foobarString});323 await t.throwsAsync(childProcess, {message: new RegExp(foobarString)});324});325326test('error instance can be shared', async t => {327 const originalMessage = foobarString;328 const error = new Error(originalMessage);329 const fixtureName = 'noop.js';330331 const firstArgument = 'one';332 const childProcess = execa(fixtureName, [firstArgument]);333 childProcess.emit('error', error);334 const firstError = await t.throwsAsync(childProcess);335336 const secondArgument = 'two';337 const secondChildProcess = execa(fixtureName, [secondArgument]);338 secondChildProcess.emit('error', error);339 const secondError = await t.throwsAsync(secondChildProcess);340341 const firstCommand = `${fixtureName} ${firstArgument}`;342 const firstMessage = `Command failed: ${firstCommand}\n${foobarString}`;343 t.is(firstError, error);344 t.is(firstError.command, firstCommand);345 t.is(firstError.message, firstMessage);346 t.true(firstError.stack.includes(firstMessage));347 t.is(firstError.shortMessage, firstMessage);348 t.is(firstError.originalMessage, originalMessage);349350 const secondCommand = `${fixtureName} ${secondArgument}`;351 const secondMessage = `Command failed: ${secondCommand}\n${foobarString}`;352 t.not(secondError, error);353 t.is(secondError.command, secondCommand);354 t.is(secondError.message, secondMessage);355 t.true(secondError.stack.includes(secondMessage));356 t.is(secondError.shortMessage, secondMessage);357 t.is(secondError.originalMessage, originalMessage);358});