error.js
This file
Path
test/error.js
275 lines · 9.2 KiB · JavaScript
Last changed by
Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
History of this fileTake it
The walk stopped after 200 commits: lines older than e003f9c point at it.
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 1why, one step back1import process from 'node:process';3.2.0ehmickybefore adoptione003f9c
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';Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 5why, one step back5import {fullStdio} from './helpers/stdio.js';3.2.0ehmickybefore adoptione003f9c
line 6why, one step back6Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 7why, one step back7const isWindows = process.platform === 'win32';3.2.0ehmickybefore adoptione003f9c
line 8why, one step back8Re-enable Windows in CI (#500)ehmickybefore adoption071d0a2
line 9why, one step back9setFixtureDir();Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 10why, one step back103.2.0ehmickybefore adoptione003f9c
lines 11–12why, one step back11const TIMEOUT_REGEXP = /timed out after/;12Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 13–15why, one step back13const testEmptyErrorStdio = async (t, execaMethod) => {14 const {failed, stdout, stderr, stdio} = await execaMethod('fail.js', {reject: false});15 t.true(failed);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 16–17why, one step back16 t.is(stdout, '');17 t.is(stderr, '');Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 18–19why, one step back18 t.deepEqual(stdio, [undefined, '', '']);19};3.2.0ehmickybefore adoptione003f9c
line 20why, one step back20Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 21–22why, one step back21test('empty error.stdout/stderr/stdio', testEmptyErrorStdio, execa);22test('empty error.stdout/stderr/stdio - sync', testEmptyErrorStdio, execaSync);3.2.0ehmickybefore adoptione003f9c
line 23why, one step back23Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 24–29why, one step back24const testUndefinedErrorStdio = async (t, execaMethod) => {25 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});26 t.is(stdout, undefined);27 t.is(stderr, undefined);28 t.deepEqual(stdio, [undefined, undefined, undefined]);29};Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 30why, one step back30Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 31–42why, one step back31test('undefined error.stdout/stderr/stdio', testUndefinedErrorStdio, execa);32test('undefined error.stdout/stderr/stdio - sync', testUndefinedErrorStdio, execaSync);3334const testEmptyAll = async (t, options, expectedValue) => {35 const {all} = await t.throwsAsync(execa('fail.js', options));36 t.is(all, expectedValue);37};3839test('empty error.all', testEmptyAll, {all: true}, '');40test('undefined error.all', testEmptyAll, {}, undefined);41test('ignored error.all', testEmptyAll, {all: true, stdio: 'ignore'}, undefined);42Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 43–44why, one step back43test('empty error.stdio[0] even with input', async t => {44 const {stdio} = await t.throwsAsync(execa('fail.js', {input: 'test'}));Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
line 45why, one step back45 t.is(stdio[0], undefined);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 46–47why, one step back46});47Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 48–49why, one step back48// `error.code` is OS-specific here49const SPAWN_ERROR_CODES = new Set(['EINVAL', 'ENOTSUP', 'EPERM']);3.2.0ehmickybefore adoptione003f9c
line 50why, one step back50Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 51–56why, one step back51test('stdout/stderr/stdio on process spawning errors', async t => {52 const {code, stdout, stderr, stdio} = await t.throwsAsync(execa('noop.js', {uid: -1}));53 t.true(SPAWN_ERROR_CODES.has(code));54 t.is(stdout, undefined);55 t.is(stderr, undefined);56 t.deepEqual(stdio, [undefined, undefined, undefined]);3.2.0ehmickybefore adoptione003f9c
lines 57–58why, one step back57});58Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 59–61why, one step back59test('stdout/stderr/all/stdio on process spawning errors - sync', t => {60 const {code, stdout, stderr, stdio} = t.throws(() => {61 execaSync('noop.js', {uid: -1});3.2.0ehmickybefore adoptione003f9c
line 62why, one step back62 });Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 63–66why, one step back63 t.true(SPAWN_ERROR_CODES.has(code));64 t.is(stdout, undefined);65 t.is(stderr, undefined);66 t.deepEqual(stdio, [undefined, undefined, undefined]);3.2.0ehmickybefore adoptione003f9c
lines 67–68why, one step back67});68Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 69–71why, one step back69const testErrorOutput = async (t, execaMethod) => {70 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});71 t.true(failed);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 72–73why, one step back72 t.is(stdout, 'stdout');73 t.is(stderr, 'stderr');Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 74–75why, one step back74 t.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);75};Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 76why, one step back76Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 77–78why, one step back77test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);78test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 79why, one step back793.2.0ehmickybefore adoptione003f9c
line 80why, one step back80test('exitCode is 0 on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 81why, one step back81 const {exitCode} = await execa('noop.js', ['foo']);3.2.0ehmickybefore adoptione003f9c
lines 82–84why, one step back82 t.is(exitCode, 0);83});84Upgrade dependenciesSindre Sorhusbefore adoption5d64878
line 85why, one step back85const testExitCode = async (t, number) => {Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe
lines 86–89why, one step back86 const {exitCode} = await t.throwsAsync(87 execa('exit.js', [`${number}`]),88 {message: new RegExp(`failed with exit code ${number}`)},89 );Upgrade dependenciesSindre Sorhusbefore adoption5d64878
line 90why, one step back90 t.is(exitCode, number);3.2.0ehmickybefore adoptione003f9c
lines 91–97why, one step back91};9293test('exitCode is 2', testExitCode, 2);94test('exitCode is 3', testExitCode, 3);95test('exitCode is 4', testExitCode, 4);9697test('error.message contains the command', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 98why, one step back98 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 99–100why, one step back99});100Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
lines 101–102why, one step back101const testStdioMessage = async (t, encoding) => {102 const {message} = await t.throwsAsync(execa('echo-fail.js', {...fullStdio, encoding}));Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 103why, one step back103 t.true(message.endsWith('stderr\nstdout\nfd3'));Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
lines 104–107why, one step back104};105106test('error.message contains stdout/stderr/stdio if available', testStdioMessage, 'utf8');107test('error.message contains stdout/stderr/stdio even with encoding "buffer"', testStdioMessage, 'buffer');Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 108why, one step back108Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 109–119why, one step back109test('error.message does not contain stdout if not available', async t => {110 const {message} = await t.throwsAsync(execa('echo-fail.js', {stdio: ['pipe', 'ignore', 'pipe', 'pipe']}));111 t.true(message.endsWith('stderr\nfd3'));112});113114test('error.message does not contain stderr if not available', async t => {115 const {message} = await t.throwsAsync(execa('echo-fail.js', {stdio: ['pipe', 'pipe', 'ignore', 'pipe']}));116 t.true(message.endsWith('stdout\nfd3'));117});118119test('error.message does not contain stdout/stderr/stdio if not available', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 120why, one step back120 const {message} = await t.throwsAsync(execa('echo-fail.js', {stdio: 'ignore'}));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 121–122why, one step back121 t.false(message.includes('stderr'));122 t.false(message.includes('stdout'));Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 123why, one step back123 t.false(message.includes('fd3'));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 124–125why, one step back124});125Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 126–127why, one step back126test('error.shortMessage does not contain stdout/stderr/stdio', async t => {127 const {shortMessage} = await t.throwsAsync(execa('echo-fail.js', fullStdio));Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
lines 128–129why, one step back128 t.false(shortMessage.includes('stderr'));129 t.false(shortMessage.includes('stdout'));Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 130why, one step back130 t.false(shortMessage.includes('fd3'));3.2.0ehmickybefore adoptione003f9c
lines 131–133why, one step back131});132133test('Original error.message is kept', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 134why, one step back134 const {originalMessage} = await t.throwsAsync(execa('noop.js', {cwd: 1}));Drop support for Node 12 (#497)ehmickybefore adoptiona09cbc0
line 135why, one step back135 t.true(originalMessage.startsWith('The "options.cwd" property must be of type string or an instance of Buffer or URL. Received type number'));3.2.0ehmickybefore adoptione003f9c
lines 136–138why, one step back136});137138test('failed is false on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 139why, one step back139 const {failed} = await execa('noop.js', ['foo']);3.2.0ehmickybefore adoptione003f9c
lines 140–143why, one step back140 t.false(failed);141});142143test('failed is true on failure', async t => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 144why, one step back144 const {failed} = await t.throwsAsync(execa('fail.js'));3.2.0ehmickybefore adoptione003f9c
lines 145–147why, one step back145 t.true(failed);146});147Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 148why, one step back148test('error.isTerminated is true if process was killed directly', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 149why, one step back149 const subprocess = execa('forever.js');3.2.0ehmickybefore adoptione003f9c
lines 150–152why, one step back150151 subprocess.kill();152Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 153–154why, one step back153 const {isTerminated} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});154 t.true(isTerminated);3.2.0ehmickybefore adoptione003f9c
lines 155–156why, one step back155});156Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 157why, one step back157test('error.isTerminated is true if process was killed indirectly', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 158why, one step back158 const subprocess = execa('forever.js');3.2.0ehmickybefore adoptione003f9c
lines 159–162why, one step back159160 process.kill(subprocess.pid, 'SIGINT');161162 // `process.kill()` is emulated by Node.js on WindowsFix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 163–165why, one step back163 const message = isWindows ? /failed with exit code 1/ : /was killed with SIGINT/;164 const {isTerminated} = await t.throwsAsync(subprocess, {message});165 t.not(isTerminated, isWindows);3.2.0ehmickybefore adoptione003f9c
lines 166–167why, one step back166});167Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 168–170why, one step back168test('result.isTerminated is false if not killed', async t => {169 const {isTerminated} = await execa('noop.js');170 t.false(isTerminated);3.2.0ehmickybefore adoptione003f9c
lines 171–172why, one step back171});172Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 173–178why, one step back173test('result.isTerminated is false if not killed and childProcess.kill() was called', async t => {174 const subprocess = execa('noop.js');175 subprocess.kill(0);176 t.true(subprocess.killed);177 const {isTerminated} = await subprocess;178 t.false(isTerminated);3.2.0ehmickybefore adoptione003f9c
lines 179–180why, one step back179});180Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 181–183why, one step back181test('result.isTerminated is false if not killed, in sync mode', t => {182 const {isTerminated} = execaSync('noop.js');183 t.false(isTerminated);3.2.0ehmickybefore adoptione003f9c
lines 184–185why, one step back184});185Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
lines 186–192why, one step back186test('result.isTerminated is false on process error', async t => {187 const {isTerminated} = await t.throwsAsync(execa('wrong command'));188 t.false(isTerminated);189});190191test('result.isTerminated is false on process error, in sync mode', t => {192 const {isTerminated} = t.throws(() => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 193why, one step back193 execaSync('wrong command');3.2.0ehmickybefore adoptione003f9c
line 194why, one step back194 });Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 195why, one step back195 t.false(isTerminated);3.2.0ehmickybefore adoptione003f9c
lines 196–197why, one step back196});197Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 198why, one step back198if (!isWindows) {3.2.0ehmickybefore adoptione003f9c
line 199why, one step back199 test('error.signal is SIGINT', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 200why, one step back200 const subprocess = execa('forever.js');3.2.0ehmickybefore adoptione003f9c
lines 201–208why, one step back201202 process.kill(subprocess.pid, 'SIGINT');203204 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});205 t.is(signal, 'SIGINT');206 });207208 test('error.signalDescription is defined', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 209why, one step back209 const subprocess = execa('forever.js');3.2.0ehmickybefore adoptione003f9c
lines 210–217why, one step back210211 process.kill(subprocess.pid, 'SIGINT');212213 const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});214 t.is(signalDescription, 'User interruption with CTRL-C');215 });216217 test('error.signal is SIGTERM', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 218why, one step back218 const subprocess = execa('forever.js');3.2.0ehmickybefore adoptione003f9c
lines 219–226why, one step back219220 process.kill(subprocess.pid, 'SIGTERM');221222 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});223 t.is(signal, 'SIGTERM');224 });225226 test('custom error.signal', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 227why, one step back227 const {signal} = await t.throwsAsync(execa('noop.js', {killSignal: 'SIGHUP', timeout: 1, message: TIMEOUT_REGEXP}));3.2.0ehmickybefore adoptione003f9c
lines 228–231why, one step back228 t.is(signal, 'SIGHUP');229 });230231 test('exitCode is undefined on signal termination', async t => {Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac
line 232why, one step back232 const subprocess = execa('forever.js');3.2.0ehmickybefore adoptione003f9c
lines 233–241why, one step back233234 process.kill(subprocess.pid);235236 const {exitCode} = await t.throwsAsync(subprocess);237 t.is(exitCode, undefined);238 });239}240241test('result.signal is undefined for successful execution', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 242why, one step back242 const {signal} = await execa('noop.js');3.2.0ehmickybefore adoptione003f9c
lines 243–246why, one step back243 t.is(signal, undefined);244});245246test('result.signal is undefined if process failed, but was not killed', async t => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 247why, one step back247 const {signal} = await t.throwsAsync(execa('fail.js'));3.2.0ehmickybefore adoptione003f9c
lines 248–251why, one step back248 t.is(signal, undefined);249});250251test('result.signalDescription is undefined for successful execution', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 252why, one step back252 const {signalDescription} = await execa('noop.js');3.2.0ehmickybefore adoptione003f9c
lines 253–256why, one step back253 t.is(signalDescription, undefined);254});255256test('error.code is undefined on success', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 257why, one step back257 const {code} = await execa('noop.js');3.2.0ehmickybefore adoptione003f9c
lines 258–261why, one step back258 t.is(code, undefined);259});260261test('error.code is defined on failure if applicable', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 262why, one step back262 const {code} = await t.throwsAsync(execa('noop.js', {cwd: 1}));Remove faulty emulated ENOENT error on Windows (#447)Mark Terrelbefore adoptionbdbd975
line 263why, one step back263 t.is(code, 'ERR_INVALID_ARG_TYPE');Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
lines 264–266why, one step back264});265266test('error.cwd is defined on failure if applicable', async t => {Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 267why, one step back267 const {cwd} = await t.throwsAsync(execa('fail.js', [], {cwd: FIXTURES_DIR}));Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
lines 268–272why, one step back268 t.is(cwd, FIXTURES_DIR);269});270271test('error.cwd is undefined on failure if not passed as options', async t => {272 const expectedCwd = process.cwd();Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 273why, one step back273 const {cwd} = await t.throwsAsync(execa('fail.js'));Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 274why, one step back274 t.is(cwd, expectedCwd);3.2.0ehmickybefore adoptione003f9c
line 275why, one step back275});