Skip to content
Myr

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 file

Take it

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

line 1why, one step back
1import process from 'node:process';

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

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';

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 5why, one step back
5

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 7why, one step back
7

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

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

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

line 9why, one step back
9

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 10–14why, one step back
10const 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 back
15 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 back
16 t.is(typeof stdout, 'string');
17 t.is(typeof stderr, 'string');18 t.is(typeof all, 'string');19});20

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

line 21why, one step back
21const WRONG_COMMAND = isWindows

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

lines 22–23why, one step back
22 ? '\'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 back
24
25test('stdout/stderr/all on process errors', async t => {

Add `all` option (#353)Tiago Nápolibefore adoption56b749d

line 26why, one step back
26 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 back
27 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 back
34 execaSync('wrong command');

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 35–40why, one step back
35 });
36 t.is(stdout, '');37 t.is(stderr, WRONG_COMMAND);38 t.is(all, undefined);39});40

Fix error properties (#375)ehmickybefore adoptionc1b511b

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

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

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

Fix error properties (#375)ehmickybefore adoptionc1b511b

line 43why, one step back
43 t.is(exitCode, 0);

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 44–45why, one step back
44});
45

Upgrade dependenciesSindre Sorhusbefore adoption5d64878

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

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

line 47why, one step back
47 const {exitCode} = await t.throwsAsync(execa('exit.js', [`${number}`]), {message: getExitRegExp(number)});

Upgrade dependenciesSindre Sorhusbefore adoption5d64878

line 48why, one step back
48 t.is(exitCode, number);

Fix error properties (#375)ehmickybefore adoptionc1b511b

lines 49–55why, one step back
49};
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 back
56 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 back
57});
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 back
60 const {message} = await t.throwsAsync(execa('echo-fail.js'));

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

lines 61–65why, one step back
61 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 back
66 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 back
67 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 back
72 const {shortMessage} = await t.throwsAsync(execa('echo-fail.js'));

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

lines 73–74why, one step back
73 t.false(shortMessage.includes('stderr'));
74 t.false(shortMessage.includes('stdout'));

Fix error properties (#375)ehmickybefore adoptionc1b511b

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

Drop support for Node 12 (#497)ehmickybefore adoptiona09cbc0

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 84–86why, one step back
84 t.false(failed);
85});86

Fix error properties (#375)ehmickybefore adoptionc1b511b

line 87why, one step back
87test('failed is true on failure', async t => {

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

line 88why, one step back
88 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 back
89 t.true(failed);
90});91

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 94why, one step back
94

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 95why, one step back
95 subprocess.kill();

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 96why, one step back
96

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

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

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 103why, one step back
103

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 104why, one step back
104 process.kill(subprocess.pid, 'SIGINT');

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 105–106why, one step back
105
106 // `process.kill()` is emulated by Node.js on Windows

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

lines 107–109why, one step back
107 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 back
110});
111

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

lines 112–114why, one step back
112test('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 back
115});
116

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

lines 117–122why, one step back
117test('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 back
123});
124

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

lines 125–127why, one step back
125test('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 back
128});
129

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

lines 130–136why, one step back
130test('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 back
137 execaSync('wrong command');

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 138why, one step back
138 });

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 140–141why, one step back
140});
141

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

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

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 145why, one step back
145

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 146why, one step back
146 process.kill(subprocess.pid, 'SIGINT');

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 147why, one step back
147

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 148why, one step back
148 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 back
149 t.is(signal, 'SIGINT');
150 });151

Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f

line 152why, one step back
152 test('error.signalDescription is defined', async t => {

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

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

Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f

lines 154–160why, one step back
154
155 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 });160

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

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

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

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 163why, one step back
163

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 164why, one step back
164 process.kill(subprocess.pid, 'SIGTERM');

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 165why, one step back
165

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 166why, one step back
166 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 back
167 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 back
171 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 back
172 t.is(signal, 'SIGHUP');
173 });

Fix error properties (#375)ehmickybefore adoptionc1b511b

lines 174–175why, one step back
174
175 test('exitCode is undefined on signal termination', async t => {

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

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

Fix error properties (#375)ehmickybefore adoptionc1b511b

line 177why, one step back
177

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 178why, one step back
178 process.kill(subprocess.pid);

Fix error properties (#375)ehmickybefore adoptionc1b511b

line 179why, one step back
179

Rename internal variables (#379)ehmickybefore adoption1ac56ea

line 180why, one step back
180 const {exitCode} = await t.throwsAsync(subprocess);

Fix error properties (#375)ehmickybefore adoptionc1b511b

lines 181–182why, one step back
181 t.is(exitCode, undefined);
182 });

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

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

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 187–190why, one step back
187 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 back
191 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 back
192 t.is(signal, undefined);

Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f

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

Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f

line 197why, one step back
197 t.is(signalDescription, undefined);

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

lines 198–199why, one step back
198});
199

Fix error properties (#375)ehmickybefore adoptionc1b511b

line 200why, one step back
200test('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 back
201 const {code} = await execa('noop.js');

Fix error properties (#375)ehmickybefore adoptionc1b511b

lines 202–203why, one step back
202 t.is(code, undefined);
203});

Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d

line 204why, one step back
204

Fix error properties (#375)ehmickybefore adoptionc1b511b

line 205why, one step back
205test('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 back
206 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 back
207 t.is(code, 'ERR_INVALID_ARG_TYPE');

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

lines 208–218why, one step back
208});
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 back
219});