Skip to content
Myr

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 file

Take 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 back
1import process from 'node:process';

3.2.0ehmickybefore adoptione003f9c

line 2why, one step back
2import test from 'ava';

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 3why, one step back
3import {execa, execaSync} from '../index.js';

Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec

line 4why, one step back
4import {FIXTURES_DIR, setFixtureDir} from './helpers/fixtures-dir.js';

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 5why, one step back
5import {fullStdio} from './helpers/stdio.js';

3.2.0ehmickybefore adoptione003f9c

line 6why, one step back
6

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 7why, one step back
7const isWindows = process.platform === 'win32';

3.2.0ehmickybefore adoptione003f9c

line 8why, one step back
8

Re-enable Windows in CI (#500)ehmickybefore adoption071d0a2

line 9why, one step back
9setFixtureDir();

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 10why, one step back
10

3.2.0ehmickybefore adoptione003f9c

lines 11–12why, one step back
11const TIMEOUT_REGEXP = /timed out after/;
12

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 13–15why, one step back
13const 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 back
16 t.is(stdout, '');
17 t.is(stderr, '');

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 18–19why, one step back
18 t.deepEqual(stdio, [undefined, '', '']);
19};

3.2.0ehmickybefore adoptione003f9c

line 20why, one step back
20

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 21–22why, one step back
21test('empty error.stdout/stderr/stdio', testEmptyErrorStdio, execa);
22test('empty error.stdout/stderr/stdio - sync', testEmptyErrorStdio, execaSync);

3.2.0ehmickybefore adoptione003f9c

line 23why, one step back
23

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 24–29why, one step back
24const 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 back
30

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 31–42why, one step back
31test('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);42

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

lines 43–44why, one step back
43test('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 back
45 t.is(stdio[0], undefined);

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

lines 46–47why, one step back
46});
47

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 48–49why, one step back
48// `error.code` is OS-specific here
49const SPAWN_ERROR_CODES = new Set(['EINVAL', 'ENOTSUP', 'EPERM']);

3.2.0ehmickybefore adoptione003f9c

line 50why, one step back
50

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 51–56why, one step back
51test('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 back
57});
58

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 59–61why, one step back
59test('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 back
62 });

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 63–66why, one step back
63 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 back
67});
68

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 69–71why, one step back
69const 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 back
72 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 back
74 t.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);
75};

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 76why, one step back
76

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 77–78why, one step back
77test('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 back
79

3.2.0ehmickybefore adoptione003f9c

line 80why, one step back
80test('exitCode is 0 on success', async t => {

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 81why, one step back
81 const {exitCode} = await execa('noop.js', ['foo']);

3.2.0ehmickybefore adoptione003f9c

lines 82–84why, one step back
82 t.is(exitCode, 0);
83});84

Upgrade dependenciesSindre Sorhusbefore adoption5d64878

line 85why, one step back
85const testExitCode = async (t, number) => {

Fix inconsistency between `result.stdout` and `error.stdout` (#686)ehmickybefore adoptionec383fe

lines 86–89why, one step back
86 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 back
90 t.is(exitCode, number);

3.2.0ehmickybefore adoptione003f9c

lines 91–97why, one step back
91};
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 back
98 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 back
99});
100

Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55

lines 101–102why, one step back
101const 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 back
103 t.true(message.endsWith('stderr\nstdout\nfd3'));

Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55

lines 104–107why, one step back
104};
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 back
108

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

lines 109–119why, one step back
109test('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 back
120 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 back
121 t.false(message.includes('stderr'));
122 t.false(message.includes('stdout'));

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 123why, one step back
123 t.false(message.includes('fd3'));

Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9

lines 124–125why, one step back
124});
125

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

lines 126–127why, one step back
126test('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 back
128 t.false(shortMessage.includes('stderr'));
129 t.false(shortMessage.includes('stdout'));

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 130why, one step back
130 t.false(shortMessage.includes('fd3'));

3.2.0ehmickybefore adoptione003f9c

lines 131–133why, one step back
131});
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 back
134 const {originalMessage} = await t.throwsAsync(execa('noop.js', {cwd: 1}));

Drop support for Node 12 (#497)ehmickybefore adoptiona09cbc0

line 135why, one step back
135 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 back
136});
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 back
139 const {failed} = await execa('noop.js', ['foo']);

3.2.0ehmickybefore adoptione003f9c

lines 140–143why, one step back
140 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 back
144 const {failed} = await t.throwsAsync(execa('fail.js'));

3.2.0ehmickybefore adoptione003f9c

lines 145–147why, one step back
145 t.true(failed);
146});147

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 148why, one step back
148test('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 back
149 const subprocess = execa('forever.js');

3.2.0ehmickybefore adoptione003f9c

lines 150–152why, one step back
150
151 subprocess.kill();152

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

lines 153–154why, one step back
153 const {isTerminated} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});
154 t.true(isTerminated);

3.2.0ehmickybefore adoptione003f9c

lines 155–156why, one step back
155});
156

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 157why, one step back
157test('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 back
158 const subprocess = execa('forever.js');

3.2.0ehmickybefore adoptione003f9c

lines 159–162why, one step back
159
160 process.kill(subprocess.pid, 'SIGINT');161162 // `process.kill()` is emulated by Node.js on Windows

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

lines 163–165why, one step back
163 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 back
166});
167

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

lines 168–170why, one step back
168test('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 back
171});
172

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

lines 173–178why, one step back
173test('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 back
179});
180

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

lines 181–183why, one step back
181test('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 back
184});
185

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

lines 186–192why, one step back
186test('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 back
193 execaSync('wrong command');

3.2.0ehmickybefore adoptione003f9c

line 194why, one step back
194 });

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 195why, one step back
195 t.false(isTerminated);

3.2.0ehmickybefore adoptione003f9c

lines 196–197why, one step back
196});
197

Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c

line 198why, one step back
198if (!isWindows) {

3.2.0ehmickybefore adoptione003f9c

line 199why, one step back
199 test('error.signal is SIGINT', async t => {

Fix randomly failing tests for `spawned.kill()` (#613)ehmickybefore adoption43c30ac

line 200why, one step back
200 const subprocess = execa('forever.js');

3.2.0ehmickybefore adoptione003f9c

lines 201–208why, one step back
201
202 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 back
209 const subprocess = execa('forever.js');

3.2.0ehmickybefore adoptione003f9c

lines 210–217why, one step back
210
211 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 back
218 const subprocess = execa('forever.js');

3.2.0ehmickybefore adoptione003f9c

lines 219–226why, one step back
219
220 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 back
227 const {signal} = await t.throwsAsync(execa('noop.js', {killSignal: 'SIGHUP', timeout: 1, message: TIMEOUT_REGEXP}));

3.2.0ehmickybefore adoptione003f9c

lines 228–231why, one step back
228 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 back
232 const subprocess = execa('forever.js');

3.2.0ehmickybefore adoptione003f9c

lines 233–241why, one step back
233
234 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 back
242 const {signal} = await execa('noop.js');

3.2.0ehmickybefore adoptione003f9c

lines 243–246why, one step back
243 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 back
247 const {signal} = await t.throwsAsync(execa('fail.js'));

3.2.0ehmickybefore adoptione003f9c

lines 248–251why, one step back
248 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 back
252 const {signalDescription} = await execa('noop.js');

3.2.0ehmickybefore adoptione003f9c

lines 253–256why, one step back
253 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 back
257 const {code} = await execa('noop.js');

3.2.0ehmickybefore adoptione003f9c

lines 258–261why, one step back
258 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 back
262 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 back
263 t.is(code, 'ERR_INVALID_ARG_TYPE');

Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec

lines 264–266why, one step back
264});
265266test('error.cwd is defined on failure if applicable', async t => {

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 267why, one step back
267 const {cwd} = await t.throwsAsync(execa('fail.js', [], {cwd: FIXTURES_DIR}));

Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec

lines 268–272why, one step back
268 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 back
273 const {cwd} = await t.throwsAsync(execa('fail.js'));

Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec

line 274why, one step back
274 t.is(cwd, expectedCwd);

3.2.0ehmickybefore adoptione003f9c

line 275why, one step back
275});