error.js
This file
Path
test/error.js
219 lines · 6.9 KiB · JavaScript
Last changed by
Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
History of this fileTake it
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 1why, one step back1import process from 'node:process';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 2why, one step back2import test from 'ava';Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 3why, one step back3import {execa, execaSync} from '../index.js';Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 4why, one step back4import {FIXTURES_DIR, setFixtureDir} from './helpers/fixtures-dir.js';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 5why, one step back5Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 6why, one step back6const isWindows = process.platform === 'win32';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 7why, one step back7Re-enable Windows in CI (#500)ehmickybefore adoption071d0a2
line 8why, one step back8setFixtureDir();Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 9why, one step back9Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 10–14why, one step back10const TIMEOUT_REGEXP = /timed out after/;1112const getExitRegExp = exitMessage => new RegExp(`failed with exit code ${exitMessage}`);1314test('stdout/stderr/all available on errors', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 15why, one step back15 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 16–20why, one step back16 t.is(typeof stdout, 'string');17 t.is(typeof stderr, 'string');18 t.is(typeof all, 'string');19});20Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 21why, one step back21const WRONG_COMMAND = isWindowsRequire Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 22–23why, one step back22 ? '\'wrong\' is not recognized as an internal or external command,\r\noperable program or batch file.'23 : '';Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 24–25why, one step back2425test('stdout/stderr/all on process errors', async t => {Add `all` option (#353)Tiago Nápolibefore adoption56b749d
line 26why, one step back26 const {stdout, stderr, all} = await t.throwsAsync(execa('wrong command', {all: true}));Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 27–33why, one step back27 t.is(stdout, '');28 t.is(stderr, WRONG_COMMAND);29 t.is(all, WRONG_COMMAND);30});3132test('stdout/stderr/all on process errors, in sync mode', t => {33 const {stdout, stderr, all} = t.throws(() => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 34why, one step back34 execaSync('wrong command');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 35–40why, one step back35 });36 t.is(stdout, '');37 t.is(stderr, WRONG_COMMAND);38 t.is(all, undefined);39});40Fix error properties (#375)ehmickybefore adoptionc1b511b
line 41why, one step back41test('exitCode is 0 on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 42why, one step back42 const {exitCode} = await execa('noop.js', ['foo']);Fix error properties (#375)ehmickybefore adoptionc1b511b
line 43why, one step back43 t.is(exitCode, 0);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 44–45why, one step back44});45Upgrade dependenciesSindre Sorhusbefore adoption5d64878
line 46why, one step back46const testExitCode = async (t, number) => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 47why, one step back47 const {exitCode} = await t.throwsAsync(execa('exit.js', [`${number}`]), {message: getExitRegExp(number)});Upgrade dependenciesSindre Sorhusbefore adoption5d64878
line 48why, one step back48 t.is(exitCode, number);Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 49–55why, one step back49};5051test('exitCode is 2', testExitCode, 2);52test('exitCode is 3', testExitCode, 3);53test('exitCode is 4', testExitCode, 4);5455test('error.message contains the command', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 56why, one step back56 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 57–59why, one step back57});5859test('error.message contains stdout/stderr if available', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 60why, one step back60 const {message} = await t.throwsAsync(execa('echo-fail.js'));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 61–65why, one step back61 t.true(message.includes('stderr'));62 t.true(message.includes('stdout'));63});6465test('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 66why, one step back66 const {message} = await t.throwsAsync(execa('echo-fail.js', {stdio: 'ignore'}));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 67–71why, one step back67 t.false(message.includes('stderr'));68 t.false(message.includes('stdout'));69});7071test('error.shortMessage does not contain stdout/stderr', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 72why, one step back72 const {shortMessage} = await t.throwsAsync(execa('echo-fail.js'));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 73–74why, one step back73 t.false(shortMessage.includes('stderr'));74 t.false(shortMessage.includes('stdout'));Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 75–77why, one step back75});7677test('Original error.message is kept', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 78why, one step back78 const {originalMessage} = await t.throwsAsync(execa('noop.js', {cwd: 1}));Drop support for Node 12 (#497)ehmickybefore adoptiona09cbc0
line 79why, one step back79 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 80–82why, one step back80});8182test('failed is false on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 83why, one step back83 const {failed} = await execa('noop.js', ['foo']);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 84–86why, one step back84 t.false(failed);85});86Fix error properties (#375)ehmickybefore adoptionc1b511b
line 87why, one step back87test('failed is true on failure', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 88why, one step back88 const {failed} = await t.throwsAsync(execa('exit.js', ['2']));Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 89–91why, one step back89 t.true(failed);90});91Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 92why, one step back92test('error.isTerminated is true if process was killed directly', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 93why, one step back93 const subprocess = execa('forever.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 94why, one step back94Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 95why, one step back95 subprocess.kill();Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 96why, one step back96Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 97–98why, one step back97 const {isTerminated} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});98 t.true(isTerminated);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 99–100why, one step back99});100Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 101why, one step back101test('error.isTerminated is true if process was killed indirectly', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 102why, one step back102 const subprocess = execa('forever.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 103why, one step back103Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 104why, one step back104 process.kill(subprocess.pid, 'SIGINT');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 105–106why, one step back105106 // `process.kill()` is emulated by Node.js on WindowsFix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 107–109why, one step back107 const message = isWindows ? /failed with exit code 1/ : /was killed with SIGINT/;108 const {isTerminated} = await t.throwsAsync(subprocess, {message});109 t.not(isTerminated, isWindows);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 110–111why, one step back110});111Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 112–114why, one step back112test('result.isTerminated is false if not killed', async t => {113 const {isTerminated} = await execa('noop.js');114 t.false(isTerminated);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 115–116why, one step back115});116Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 117–122why, one step back117test('result.isTerminated is false if not killed and childProcess.kill() was called', async t => {118 const subprocess = execa('noop.js');119 subprocess.kill(0);120 t.true(subprocess.killed);121 const {isTerminated} = await subprocess;122 t.false(isTerminated);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 123–124why, one step back123});124Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 125–127why, one step back125test('result.isTerminated is false if not killed, in sync mode', t => {126 const {isTerminated} = execaSync('noop.js');127 t.false(isTerminated);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 128–129why, one step back128});129Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 130–136why, one step back130test('result.isTerminated is false on process error', async t => {131 const {isTerminated} = await t.throwsAsync(execa('wrong command'));132 t.false(isTerminated);133});134135test('result.isTerminated is false on process error, in sync mode', t => {136 const {isTerminated} = t.throws(() => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 137why, one step back137 execaSync('wrong command');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 138why, one step back138 });Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 139why, one step back139 t.false(isTerminated);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 140–141why, one step back140});141Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 142why, one step back142if (!isWindows) {Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 143why, one step back143 test('error.signal is SIGINT', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 144why, one step back144 const subprocess = execa('forever.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 145why, one step back145Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 146why, one step back146 process.kill(subprocess.pid, 'SIGINT');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 147why, one step back147Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 148why, one step back148 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 149–151why, one step back149 t.is(signal, 'SIGINT');150 });151Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 152why, one step back152 test('error.signalDescription is defined', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 153why, one step back153 const subprocess = execa('forever.js');Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
lines 154–160why, one step back154155 process.kill(subprocess.pid, 'SIGINT');156157 const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});158 t.is(signalDescription, 'User interruption with CTRL-C');159 });160Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 161why, one step back161 test('error.signal is SIGTERM', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 162why, one step back162 const subprocess = execa('forever.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 163why, one step back163Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 164why, one step back164 process.kill(subprocess.pid, 'SIGTERM');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 165why, one step back165Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 166why, one step back166 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 167–170why, one step back167 t.is(signal, 'SIGTERM');168 });169170 test('custom error.signal', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 171why, one step back171 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 172–173why, one step back172 t.is(signal, 'SIGHUP');173 });Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 174–175why, one step back174175 test('exitCode is undefined on signal termination', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 176why, one step back176 const subprocess = execa('forever.js');Fix error properties (#375)ehmickybefore adoptionc1b511b
line 177why, one step back177Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 178why, one step back178 process.kill(subprocess.pid);Fix error properties (#375)ehmickybefore adoptionc1b511b
line 179why, one step back179Rename internal variables (#379)ehmickybefore adoption1ac56ea
line 180why, one step back180 const {exitCode} = await t.throwsAsync(subprocess);Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 181–182why, one step back181 t.is(exitCode, undefined);182 });Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 183–185why, one step back183}184185test('result.signal is undefined for successful execution', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 186why, one step back186 const {signal} = await execa('noop.js');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 187–190why, one step back187 t.is(signal, undefined);188});189190test('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 191why, one step back191 const {signal} = await t.throwsAsync(execa('exit.js', [2]), {message: getExitRegExp('2')});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 192why, one step back192 t.is(signal, undefined);Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
lines 193–195why, one step back193});194195test('result.signalDescription is undefined for successful execution', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 196why, one step back196 const {signalDescription} = await execa('noop.js');Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 197why, one step back197 t.is(signalDescription, undefined);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 198–199why, one step back198});199Fix error properties (#375)ehmickybefore adoptionc1b511b
line 200why, one step back200test('error.code is undefined on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 201why, one step back201 const {code} = await execa('noop.js');Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 202–203why, one step back202 t.is(code, undefined);203});Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 204why, one step back204Fix error properties (#375)ehmickybefore adoptionc1b511b
line 205why, one step back205test('error.code is defined on failure if applicable', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 206why, one step back206 const {code} = await t.throwsAsync(execa('noop.js', {cwd: 1}));Remove faulty emulated ENOENT error on Windows (#447)Mark Terrelbefore adoptionbdbd975
line 207why, one step back207 t.is(code, 'ERR_INVALID_ARG_TYPE');Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
lines 208–218why, one step back208});209210test('error.cwd is defined on failure if applicable', async t => {211 const {cwd} = await t.throwsAsync(execa('noop-throw.js', [], {cwd: FIXTURES_DIR}));212 t.is(cwd, FIXTURES_DIR);213});214215test('error.cwd is undefined on failure if not passed as options', async t => {216 const expectedCwd = process.cwd();217 const {cwd} = await t.throwsAsync(execa('noop-throw.js'));218 t.is(cwd, expectedCwd);Add `error.originalMessage` property (#373)ehmickybefore adoption07d2b76
line 219why, one step back219});