error.js
This file
Path
test/error.js
215 lines · 6.7 KiB · JavaScript
Last changed by
Drop support for Node 12 (#497)ehmickybefore adoptiona09cbc0
History of this fileTake it
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 1–5why, one step back1import path from 'node:path';2import process from 'node:process';3import childProcess from 'node:child_process';4import {fileURLToPath} from 'node:url';5import {promisify} from 'node:util';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 6why, one step back6import test from 'ava';Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 7why, one step back7import {execa, execaSync} from '../index.js';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 8why, one step back8Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 9why, one step back9const pExec = promisify(childProcess.exec);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 10why, one step back10Meta tweaksSindre Sorhusbefore adoption5bac052
line 11why, one step back11process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 12why, one step back12Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 13–17why, one step back13const TIMEOUT_REGEXP = /timed out after/;1415const getExitRegExp = exitMessage => new RegExp(`failed with exit code ${exitMessage}`);1617test('stdout/stderr/all available on errors', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 18why, one step back18 const {stdout, stderr, all} = await t.throwsAsync(execa('exit.js', ['2'], {all: true}), {message: getExitRegExp('2')});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 19–23why, one step back19 t.is(typeof stdout, 'string');20 t.is(typeof stderr, 'string');21 t.is(typeof all, 'string');22});23Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 24–26why, one step back24const WRONG_COMMAND = process.platform === 'win32'25 ? '\'wrong\' is not recognized as an internal or external command,\r\noperable program or batch file.'26 : '';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 27–28why, one step back2728test('stdout/stderr/all on process errors', async t => {Add `all` option (#353)Tiago Nápolibefore adoption56b749d
line 29why, one step back29 const {stdout, stderr, all} = await t.throwsAsync(execa('wrong command', {all: true}));Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 30–36why, one step back30 t.is(stdout, '');31 t.is(stderr, WRONG_COMMAND);32 t.is(all, WRONG_COMMAND);33});3435test('stdout/stderr/all on process errors, in sync mode', t => {36 const {stdout, stderr, all} = t.throws(() => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 37why, one step back37 execaSync('wrong command');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 38–43why, one step back38 });39 t.is(stdout, '');40 t.is(stderr, WRONG_COMMAND);41 t.is(all, undefined);42});43Fix error properties (#375)ehmickybefore adoptionc1b511b
line 44why, one step back44test('exitCode is 0 on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 45why, one step back45 const {exitCode} = await execa('noop.js', ['foo']);Fix error properties (#375)ehmickybefore adoptionc1b511b
line 46why, one step back46 t.is(exitCode, 0);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 47–48why, one step back47});48Upgrade dependenciesSindre Sorhusbefore adoption5d64878
line 49why, one step back49const testExitCode = async (t, number) => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 50why, one step back50 const {exitCode} = await t.throwsAsync(execa('exit.js', [`${number}`]), {message: getExitRegExp(number)});Upgrade dependenciesSindre Sorhusbefore adoption5d64878
line 51why, one step back51 t.is(exitCode, number);Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 52–58why, one step back52};5354test('exitCode is 2', testExitCode, 2);55test('exitCode is 3', testExitCode, 3);56test('exitCode is 4', testExitCode, 4);5758test('error.message contains the command', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 59why, one step back59 await t.throwsAsync(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 60–62why, one step back60});6162test('error.message contains stdout/stderr if available', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 63why, one step back63 const {message} = await t.throwsAsync(execa('echo-fail.js'));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 64–68why, one step back64 t.true(message.includes('stderr'));65 t.true(message.includes('stdout'));66});6768test('error.message does not contain stdout/stderr if not available', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 69why, one step back69 const {message} = await t.throwsAsync(execa('echo-fail.js', {stdio: 'ignore'}));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 70–74why, one step back70 t.false(message.includes('stderr'));71 t.false(message.includes('stdout'));72});7374test('error.shortMessage does not contain stdout/stderr', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 75why, one step back75 const {shortMessage} = await t.throwsAsync(execa('echo-fail.js'));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 76–77why, one step back76 t.false(shortMessage.includes('stderr'));77 t.false(shortMessage.includes('stdout'));Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 78–80why, one step back78});7980test('Original error.message is kept', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 81why, one step back81 const {originalMessage} = await t.throwsAsync(execa('noop.js', {cwd: 1}));Drop support for Node 12 (#497)ehmickybefore adoptiona09cbc0
line 82why, one step back82 t.true(originalMessage.startsWith('The "options.cwd" property must be of type string or an instance of Buffer or URL. Received type number'));Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 83–85why, one step back83});8485test('failed is false on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 86why, one step back86 const {failed} = await execa('noop.js', ['foo']);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 87–89why, one step back87 t.false(failed);88});89Fix error properties (#375)ehmickybefore adoptionc1b511b
line 90why, one step back90test('failed is true on failure', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 91why, one step back91 const {failed} = await t.throwsAsync(execa('exit.js', ['2']));Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 92–95why, one step back92 t.true(failed);93});9495test('error.killed is true if process was killed directly', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 96why, one step back96 const subprocess = execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 97why, one step back97Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 98why, one step back98 subprocess.kill();Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 99why, one step back99Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 100why, one step back100 const {killed} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 101–104why, one step back101 t.true(killed);102});103104test('error.killed is false if process was killed indirectly', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 105why, one step back105 const subprocess = execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 106why, one step back106Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 107why, one step back107 process.kill(subprocess.pid, 'SIGINT');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 108–110why, one step back108109 // `process.kill()` is emulated by Node.js on Windows110 const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/;Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 111why, one step back111 const {killed} = await t.throwsAsync(subprocess, {message});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 112–115why, one step back112 t.false(killed);113});114115test('result.killed is false if not killed', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 116why, one step back116 const {killed} = await execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 117–120why, one step back117 t.false(killed);118});119120test('result.killed is false if not killed, in sync mode', t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 121why, one step back121 const {killed} = execaSync('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 122–131why, one step back122 t.false(killed);123});124125test('result.killed is false on process error', async t => {126 const {killed} = await t.throwsAsync(execa('wrong command'));127 t.false(killed);128});129130test('result.killed is false on process error, in sync mode', t => {131 const {killed} = t.throws(() => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 132why, one step back132 execaSync('wrong command');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 133–137why, one step back133 });134 t.false(killed);135});136137if (process.platform === 'darwin') {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 138–139why, one step back138 test('sanity check: child_process.exec also has killed.false if killed indirectly', async t => {139 const promise = pExec('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 140why, one step back140Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 141–145why, one step back141 process.kill(promise.child.pid, 'SIGINT');142143 const error = await t.throwsAsync(promise);144 t.truthy(error);145 t.false(error.killed);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 146–150why, one step back146 });147}148149if (process.platform !== 'win32') {150 test('error.signal is SIGINT', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 151why, one step back151 const subprocess = execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 152why, one step back152Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 153why, one step back153 process.kill(subprocess.pid, 'SIGINT');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 154why, one step back154Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 155why, one step back155 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 156–158why, one step back156 t.is(signal, 'SIGINT');157 });158Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 159why, one step back159 test('error.signalDescription is defined', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 160why, one step back160 const subprocess = execa('noop.js');Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
lines 161–167why, one step back161162 process.kill(subprocess.pid, 'SIGINT');163164 const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});165 t.is(signalDescription, 'User interruption with CTRL-C');166 });167Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 168why, one step back168 test('error.signal is SIGTERM', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 169why, one step back169 const subprocess = execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 170why, one step back170Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 171why, one step back171 process.kill(subprocess.pid, 'SIGTERM');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 172why, one step back172Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 173why, one step back173 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 174–177why, one step back174 t.is(signal, 'SIGTERM');175 });176177 test('custom error.signal', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 178why, one step back178 const {signal} = await t.throwsAsync(execa('noop.js', {killSignal: 'SIGHUP', timeout: 1, message: TIMEOUT_REGEXP}));Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 179–180why, one step back179 t.is(signal, 'SIGHUP');180 });Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 181–182why, one step back181182 test('exitCode is undefined on signal termination', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 183why, one step back183 const subprocess = execa('noop.js');Fix error properties (#375)ehmickybefore adoptionc1b511b
line 184why, one step back184Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 185why, one step back185 process.kill(subprocess.pid);Fix error properties (#375)ehmickybefore adoptionc1b511b
line 186why, one step back186Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 187why, one step back187 const {exitCode} = await t.throwsAsync(subprocess);Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 188–189why, one step back188 t.is(exitCode, undefined);189 });Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 190–192why, one step back190}191192test('result.signal is undefined for successful execution', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 193why, one step back193 const {signal} = await execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 194–197why, one step back194 t.is(signal, undefined);195});196197test('result.signal is undefined if process failed, but was not killed', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 198why, one step back198 const {signal} = await t.throwsAsync(execa('exit.js', [2]), {message: getExitRegExp('2')});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 199why, one step back199 t.is(signal, undefined);Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
lines 200–202why, one step back200});201202test('result.signalDescription is undefined for successful execution', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 203why, one step back203 const {signalDescription} = await execa('noop.js');Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 204why, one step back204 t.is(signalDescription, undefined);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 205–206why, one step back205});206Fix error properties (#375)ehmickybefore adoptionc1b511b
line 207why, one step back207test('error.code is undefined on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 208why, one step back208 const {code} = await execa('noop.js');Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 209–210why, one step back209 t.is(code, undefined);210});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 211why, one step back211Fix error properties (#375)ehmickybefore adoptionc1b511b
line 212why, one step back212test('error.code is defined on failure if applicable', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 213why, one step back213 const {code} = await t.throwsAsync(execa('noop.js', {cwd: 1}));Remove faulty emulated ENOENT error on Windows (#447)Mark Terrelbefore adoptionbdbd975
line 214why, one step back214 t.is(code, 'ERR_INVALID_ARG_TYPE');Add `error.originalMessage` property (#373)ehmickybefore adoption07d2b76
line 215why, one step back215});