Skip to content
Myr

test.js

This file

Path

test.js

548 lines · 15.0 KiB · JavaScript

Last changed by

Add `buffer` option to be able to disable buffering (#133)Spencerbefore adoption50384aa

History of this file

Take it

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 1why, one step back
1import path from 'path';

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

line 2why, one step back
2import fs from 'fs';

add `input` optionJames Talmagebefore adoption605a674

line 3why, one step back
3import stream from 'stream';

add tests (#48)James Talmagebefore adoptionb15483a

line 4why, one step back
4import childProcess from 'child_process';

initSindre Sorhusbefore adoptionbc16d6b

line 5
5import test from 'ava';

make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220

line 6why, one step back
6import getStream from 'get-stream';

Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd

lines 7–8why, one step back
7import isRunning from 'is-running';
8import delay from 'delay';

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

line 9why, one step back
9import tempfile from 'tempfile';

Fix lintingSindre Sorhusbefore adoptionf4e2d56

line 10why, one step back
10import m from '.';

initSindre Sorhusbefore adoptionbc16d6b

line 11
11

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 12why, one step back
12process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;

Extend environment by default - fixes #87 (#88)Sam Verschuerenbefore adoptione370117

line 13why, one step back
13process.env.FOO = 'foo';

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 14why, one step back
14

initSindre Sorhusbefore adoptionbc16d6b

line 15
15test('execa()', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 16why, one step back
16 const {stdout} = await m('noop', ['foo']);

initSindre Sorhusbefore adoptionbc16d6b

lines 17–19
17 t.is(stdout, 'foo');
18});19

Turn off echo on Windows - fixes #116 (#118)Sam Verschuerenbefore adoptionff76235

lines 20–27why, one step back
20if (process.platform === 'win32') {
21 test('execa() - cmd file', async t => {22 const {stdout} = await m('hello.cmd');2324 t.is(stdout, 'Hello World');25 });26}27

initSindre Sorhusbefore adoptionbc16d6b

line 28
28test('buffer', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 29why, one step back
29 const {stdout} = await m('noop', ['foo'], {encoding: null});

initSindre Sorhusbefore adoptionbc16d6b

lines 30–33
30 t.true(Buffer.isBuffer(stdout));
31 t.is(stdout.toString(), 'foo');32});33

add `execa.stdout()` shortcut (#14)Sindre Sorhusbefore adoption868f505

lines 34–43why, one step back
34test('execa.stdout()', async t => {
35 const stdout = await m.stdout('noop', ['foo']);36 t.is(stdout, 'foo');37});3839test('execa.stderr()', async t => {40 const stderr = await m.stderr('noop-err', ['foo']);41 t.is(stderr, 'foo');42});43

add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf

line 44why, one step back
44test('stdout/stderr available on errors', async t => {

meta tweaksSindre Sorhusbefore adoption858af26

lines 45–47why, one step back
45 const err = await t.throws(m('exit', ['2']));
46 t.is(typeof err.stdout, 'string');47 t.is(typeof err.stderr, 'string');

add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf

lines 48–49why, one step back
48});
49

add tests (#48)James Talmagebefore adoptionb15483a

line 50why, one step back
50test('include stdout and stderr in errors for improved debugging', async t => {

Use spawn instead of execFile (#27)James Talmagebefore adoption31a8d87

lines 51–52why, one step back
51 const err = await t.throws(m('fixtures/error-message.js'));
52 t.regex(err.message, /stdout/);

add tests (#48)James Talmagebefore adoptionb15483a

line 53why, one step back
53 t.regex(err.message, /stderr/);

Fix test for exit code 1 on windows (#78)Sam Verschuerenbefore adoption4231a10

line 54why, one step back
54 t.is(err.code, 1);

include stdout in errors for improved debuggingSindre Sorhusbefore adoptionaea8c9a

lines 55–56why, one step back
55});
56

Do not output stderr and stdout on stdio inherit - fixes #70 (#79)Sam Verschuerenbefore adoption2a12986

lines 57–58why, one step back
57test('do not include in errors when `stdio` is set to `inherit`', async t => {
58 const err = await t.throws(m('fixtures/error-message.js', {stdio: 'inherit'}));

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

lines 59–93why, one step back
59 t.notRegex(err.message, /\n/);
60});6162test('do not include `stderr` and `stdout` in errors when set to `inherit`', async t => {63 const err = await t.throws(m('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}));64 t.notRegex(err.message, /\n/);65});6667test('do not include `stderr` and `stdout` in errors when `stdio` is set to `inherit`', async t => {68 const err = await t.throws(m('fixtures/error-message.js', {stdio: [null, 'inherit', 'inherit']}));69 t.notRegex(err.message, /\n/);70});7172test('do not include `stdout` in errors when set to `inherit`', async t => {73 const err = await t.throws(m('fixtures/error-message.js', {stdout: 'inherit'}));74 t.notRegex(err.message, /stdout/);75 t.regex(err.message, /stderr/);76});7778test('do not include `stderr` in errors when set to `inherit`', async t => {79 const err = await t.throws(m('fixtures/error-message.js', {stderr: 'inherit'}));80 t.regex(err.message, /stdout/);81 t.notRegex(err.message, /stderr/);82});8384test('pass `stdout` to a file descriptor', async t => {85 const file = tempfile('.txt');86 await m('fixtures/noop', ['foo bar'], {stdout: fs.openSync(file, 'w')});87 t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');88});8990test('pass `stderr` to a file descriptor', async t => {91 const file = tempfile('.txt');92 await m('fixtures/noop-err', ['foo bar'], {stderr: fs.openSync(file, 'w')});93 t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');

Do not output stderr and stdout on stdio inherit - fixes #70 (#79)Sam Verschuerenbefore adoption2a12986

lines 94–95why, one step back
94});
95

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 96why, one step back
96test('execa.shell()', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 97why, one step back
97 const {stdout} = await m.shell('node fixtures/noop foo');

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

lines 98–100why, one step back
98 t.is(stdout, 'foo');
99});100

make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220

line 101why, one step back
101test('execa.spawn()', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

lines 102–103why, one step back
102 t.is(typeof m.spawn('noop').pid, 'number');
103 t.is((await getStream(m.spawn('noop', ['foo']).stdout)).trim(), 'foo');

expose `.spawn`Sindre Sorhusbefore adoptionb65479c

lines 104–105why, one step back
104});
105

add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c

line 106why, one step back
106test('execa.sync()', t => {

[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100

line 107why, one step back
107 const {stdout} = m.sync('noop', ['foo']);

add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c

lines 108–110why, one step back
108 t.is(stdout, 'foo');
109});110

Throw error in sync method - fixes #66 (#67)Sam Verschuerenbefore adoptionc8c9c7b

lines 111–114why, one step back
111test('execa.sync() throws error if written to stderr', t => {
112 t.throws(() => m.sync('foo'), process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : 'spawnSync foo ENOENT');113});114

Enhance error object in sync methods - fixes #98 (#107)Sam Verschuerenbefore adoptiond31cc91

lines 115–127why, one step back
115test('execa.sync() includes stdout and stderr in errors for improved debugging', t => {
116 const err = t.throws(() => m.sync('node', ['fixtures/error-message.js']));117 t.regex(err.message, /stdout/);118 t.regex(err.message, /stderr/);119 t.is(err.code, 1);120});121122test('skip throwing when using reject option in execa.sync()', t => {123 const err = m.sync('node', ['fixtures/error-message.js'], {reject: false});124 t.is(typeof err.stdout, 'string');125 t.is(typeof err.stderr, 'string');126});127

add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee

line 128why, one step back
128test('execa.shellSync()', t => {

[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100

line 129why, one step back
129 const {stdout} = m.shellSync('node fixtures/noop foo');

add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee

line 130why, one step back
130 t.is(stdout, 'foo');

Enhance error object in sync methods - fixes #98 (#107)Sam Verschuerenbefore adoptiond31cc91

lines 131–143why, one step back
131});
132133test('execa.shellSync() includes stdout and stderr in errors for improved debugging', t => {134 const err = t.throws(() => m.shellSync('node fixtures/error-message.js'));135 t.regex(err.message, /stdout/);136 t.regex(err.message, /stderr/);137 t.is(err.code, 1);138});139140test('skip throwing when using reject option in execa.shellSync()', t => {141 const err = m.shellSync('node fixtures/error-message.js', {reject: false});142 t.is(typeof err.stdout, 'string');143 t.is(typeof err.stderr, 'string');

add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee

lines 144–145why, one step back
144});
145

initSindre Sorhusbefore adoptionbc16d6b

line 146
146test('stripEof option', async t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 147why, one step back
147 const {stdout} = await m('noop', ['foo'], {stripEof: false});

initSindre Sorhusbefore adoptionbc16d6b

lines 148–150
148 t.is(stdout, 'foo\n');
149});150

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 151why, one step back
151test.serial('preferLocal option', async t => {

tweaksSindre Sorhusbefore adoptione3505a8

line 152why, one step back
152 t.true((await m('cat-names')).stdout.length > 2);

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 153why, one step back
153

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

lines 154–158why, one step back
154 if (process.platform === 'win32') {
155 // TODO: figure out how to make the below not hang on Windows156 return;157 }158

Fix linting (#77)Sam Verschuerenbefore adoption80a059d

line 159why, one step back
159 // Account for npm adding local binaries to the PATH

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

lines 160–161why, one step back
160 const _path = process.env.PATH;
161 process.env.PATH = '';

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 162why, one step back
162 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 163why, one step back
163 process.env.PATH = _path;

add `input` optionJames Talmagebefore adoption605a674

lines 164–165why, one step back
164});
165

Fix test flakiness on WindowsSindre Sorhusbefore adoptionf071546

line 166why, one step back
166test.serial('localDir option', async t => {

Add test for #73Sindre Sorhusbefore adoptionc7481f4

lines 167–173why, one step back
167 const cwd = 'fixtures/local-dir';
168 const bin = path.resolve(cwd, 'node_modules/.bin/self-path');169170 await m('npm', ['install', '--no-package-lock'], {cwd});171172 const {stdout} = await m(bin, {localDir: cwd});173

Meta tweaksSindre Sorhusbefore adoptionc0fc20c

line 174why, one step back
174 t.is(path.relative(cwd, stdout), path.normalize('node_modules/self-path'));

Add test for #73Sindre Sorhusbefore adoptionc7481f4

lines 175–176why, one step back
175});
176

add `input` optionJames Talmagebefore adoption605a674

line 177why, one step back
177test('input option can be a String', async t => {

fix option handling in #15Sindre Sorhusbefore adoption3d31e8d

line 178why, one step back
178 const {stdout} = await m('stdin', {input: 'foobar'});

add `input` optionJames Talmagebefore adoption605a674

lines 179–182why, one step back
179 t.is(stdout, 'foobar');
180});181182test('input option can be a Buffer', async t => {

fix option handling in #15Sindre Sorhusbefore adoption3d31e8d

line 183why, one step back
183 const {stdout} = await m('stdin', {input: 'testing12'});

add `input` optionJames Talmagebefore adoption605a674

lines 184–187why, one step back
184 t.is(stdout, 'testing12');
185});186187test('input can be a Stream', async t => {

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

line 188why, one step back
188 const s = new stream.PassThrough();

add `input` optionJames Talmagebefore adoption605a674

lines 189–190why, one step back
189 s.write('howdy');
190 s.end();

fix option handling in #15Sindre Sorhusbefore adoption3d31e8d

line 191why, one step back
191 const {stdout} = await m('stdin', {input: s});

add `input` optionJames Talmagebefore adoption605a674

lines 192–194why, one step back
192 t.is(stdout, 'howdy');
193});194

return the child process instead of a promise. (#18)James Talmagebefore adoption99f10ba

lines 195–200why, one step back
195test('you can write to child.stdin', async t => {
196 const child = m('stdin');197 child.stdin.end('unicorns');198 t.is((await child).stdout, 'unicorns');199});200

Fix linting (#77)Sam Verschuerenbefore adoption80a059d

line 201why, one step back
201test('input option can be a String - sync', t => {

[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100

line 202why, one step back
202 const {stdout} = m.sync('stdin', {input: 'foobar'});

add `input` optionJames Talmagebefore adoption605a674

lines 203–205why, one step back
203 t.is(stdout, 'foobar');
204});205

Fix linting (#77)Sam Verschuerenbefore adoption80a059d

lines 206–207why, one step back
206test('input option can be a Buffer - sync', t => {
207 const {stdout} = m.sync('stdin', {input: Buffer.from('testing12', 'utf8')});

add `input` optionJames Talmagebefore adoption605a674

line 208why, one step back
208 t.is(stdout, 'testing12');

Use spawn instead of execFile (#27)James Talmagebefore adoption31a8d87

lines 209–211why, one step back
209});
210211test('opts.stdout:ignore - stdout will not collect data', async t => {

fix XO lint issuesSindre Sorhusbefore adoption342096c

lines 212–215why, one step back
212 const {stdout} = await m('stdin', {
213 input: 'hello',214 stdio: [null, 'ignore', null]215 });

Use spawn instead of execFile (#27)James Talmagebefore adoption31a8d87

line 216why, one step back
216 t.is(stdout, null);

add `input` optionJames Talmagebefore adoption605a674

lines 217–220why, one step back
217});
218219test('helpful error trying to provide an input stream in sync mode', t => {220 t.throws(

fix option handling in #15Sindre Sorhusbefore adoption3d31e8d

line 221why, one step back
221 () => m.sync('stdin', {input: new stream.PassThrough()}),

add `input` optionJames Talmagebefore adoption605a674

lines 222–223why, one step back
222 /The `input` option cannot be a stream in sync mode/
223 );

Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484

lines 224–226why, one step back
224});
225226test('execa() returns a promise with kill() and pid', t => {

fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df

line 227why, one step back
227 const promise = m('noop', ['foo']);

Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484

lines 228–229why, one step back
228 t.is(typeof promise.kill, 'function');
229 t.is(typeof promise.pid, 'number');

initSindre Sorhusbefore adoptionbc16d6b

line 230
230});

add max-buffer support (#37)James Talmagebefore adoption6288806

line 231why, one step back
231

Fix tests (#89)Sam Verschuerenbefore adoption1861b5e

lines 232–234why, one step back
232test('maxBuffer affects stdout', async t => {
233 await t.throws(m('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);234 await t.notThrows(m('max-buffer', ['stdout', '10'], {maxBuffer: 10}));

add max-buffer support (#37)James Talmagebefore adoption6288806

lines 235–236why, one step back
235});
236

Fix tests (#89)Sam Verschuerenbefore adoption1861b5e

lines 237–239why, one step back
237test('maxBuffer affects stderr', async t => {
238 await t.throws(m('max-buffer', ['stderr', '13'], {maxBuffer: 12}), /stderr maxBuffer exceeded/);239 await t.notThrows(m('max-buffer', ['stderr', '12'], {maxBuffer: 12}));

add max-buffer support (#37)James Talmagebefore adoption6288806

line 240why, one step back
240});

Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76

line 241why, one step back
241

Add `buffer` option to be able to disable buffering (#133)Spencerbefore adoption50384aa

lines 242–263why, one step back
242test('do not buffer stdout when `buffer` set to `false`', async t => {
243 const promise = m('max-buffer', ['stdout', '10'], {buffer: false});244 const [result, stdout] = await Promise.all([245 promise,246 getStream(promise.stdout)247 ]);248249 t.is(result.stdout, undefined);250 t.is(stdout, '.........\n');251});252253test('do not buffer stderr when `buffer` set to `false`', async t => {254 const promise = m('max-buffer', ['stderr', '10'], {buffer: false});255 const [result, stderr] = await Promise.all([256 promise,257 getStream(promise.stderr)258 ]);259260 t.is(result.stderr, undefined);261 t.is(stderr, '.........\n');262});263

Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76

line 264why, one step back
264test('skip throwing when using reject option', async t => {

Fix tests (#89)Sam Verschuerenbefore adoption1861b5e

line 265why, one step back
265 const err = await m('exit', ['2'], {reject: false});

Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76

lines 266–277why, one step back
266 t.is(typeof err.stdout, 'string');
267 t.is(typeof err.stderr, 'string');268});269270test('execa() returns code and failed properties', async t => {271 const {code, failed} = await m('noop', ['foo']);272 const err = await t.throws(m('exit', ['2']));273 t.is(code, 0);274 t.false(failed);275 t.is(err.code, 2);276 t.true(err.failed);277});

Add test for `../` paths (#43)James Talmagebefore adoption56a20b1

lines 278–283why, one step back
278
279test(`use relative path with '..' chars`, async t => {280 const pathViaParentDir = path.join('..', path.basename(__dirname), 'fixtures', 'noop');281 const {stdout} = await m(pathViaParentDir, ['foo']);282 t.is(stdout, 'foo');283});

add tests (#48)James Talmagebefore adoptionb15483a

line 284why, one step back
284

add test case for throwing on non-executables (#49)Markus Wolfbefore adoptione10d263

line 285why, one step back
285if (process.platform !== 'win32') {

Fix tests (#89)Sam Verschuerenbefore adoption1861b5e

line 286why, one step back
286 test('execa() rejects if running non-executable', async t => {

ensure `execa` rejects and not throws when the core spawn throws and errorSindre Sorhusbefore adoption03964c1

line 287why, one step back
287 const cp = m('non-executable');

Fix tests (#89)Sam Verschuerenbefore adoption1861b5e

line 288why, one step back
288 await t.throws(cp);

add test case for throwing on non-executables (#49)Markus Wolfbefore adoptione10d263

lines 289–291why, one step back
289 });
290}291

add tests (#48)James Talmagebefore adoptionb15483a

lines 292–294why, one step back
292test('err.killed is true if process was killed directly', async t => {
293 const cp = m('forever');294

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

line 295why, one step back
295 setTimeout(() => {

add tests (#48)James Talmagebefore adoptionb15483a

lines 296–307why, one step back
296 cp.kill();
297 }, 100);298299 const err = await t.throws(cp);300301 t.true(err.killed);302});303304// TODO: Should this really be the case, or should we improve on child_process?305test('err.killed is false if process was killed indirectly', async t => {306 const cp = m('forever');307

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

line 308why, one step back
308 setTimeout(() => {

add tests (#48)James Talmagebefore adoptionb15483a

lines 309–324why, one step back
309 process.kill(cp.pid, 'SIGINT');
310 }, 100);311312 const err = await t.throws(cp);313314 t.false(err.killed);315});316317if (process.platform === 'darwin') {318 test.cb('sanity check: child_process.exec also has killed.false if killed indirectly', t => {319 const cp = childProcess.exec('forever', err => {320 t.truthy(err);321 t.false(err.killed);322 t.end();323 });324

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

line 325why, one step back
325 setTimeout(() => {

add tests (#48)James Talmagebefore adoptionb15483a

lines 326–334why, one step back
326 process.kill(cp.pid, 'SIGINT');
327 }, 100);328 });329}330331if (process.platform !== 'win32') {332 test('err.signal is SIGINT', async t => {333 const cp = m('forever');334

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

line 335why, one step back
335 setTimeout(() => {

add tests (#48)James Talmagebefore adoptionb15483a

lines 336–346why, one step back
336 process.kill(cp.pid, 'SIGINT');
337 }, 100);338339 const err = await t.throws(cp);340341 t.is(err.signal, 'SIGINT');342 });343344 test('err.signal is SIGTERM', async t => {345 const cp = m('forever');346

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

line 347why, one step back
347 setTimeout(() => {

add tests (#48)James Talmagebefore adoptionb15483a

lines 348–354why, one step back
348 process.kill(cp.pid, 'SIGTERM');
349 }, 100);350351 const err = await t.throws(cp);352353 t.is(err.signal, 'SIGTERM');354 });

Fix `killSignal` option (#93)Kevin Mårtenssonbefore adoption2cbcc5c

lines 355–360why, one step back
355
356 test('custom err.signal', async t => {357 const err = await t.throws(m('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500}));358359 t.is(err.signal, 'SIGHUP');360 });

add tests (#48)James Talmagebefore adoptionb15483a

lines 361–381why, one step back
361}
362363test('result.signal is null for successful execution', async t => {364 t.is((await m('noop')).signal, null);365});366367test('result.signal is null if process failed, but was not killed', async t => {368 const err = await t.throws(m('exit', [2]));369 t.is(err.signal, null);370});371372async function code(t, num) {373 const err = await t.throws(m('exit', [`${num}`]));374375 t.is(err.code, num);376}377378test('err.code is 2', code, 2);379test('err.code is 3', code, 3);380test('err.code is 4', code, 4);381

Reimplement missing features. Fixes #30 & #32 (#68)James Talmagebefore adoptione96350d

line 382why, one step back
382test('timeout will kill the process early', async t => {

Add `buffer` option to be able to disable buffering (#133)Spencerbefore adoption50384aa

line 383why, one step back
383 const err = await t.throws(m('delay', ['60000', '0'], {timeout: 1500}));

Reimplement missing features. Fixes #30 & #32 (#68)James Talmagebefore adoptione96350d

lines 384–389why, one step back
384
385 t.true(err.timedOut);386 t.not(err.code, 22);387});388389test('timeout will not kill the process early', async t => {

Fix test flakiness on WindowsSindre Sorhusbefore adoptionf071546

line 390why, one step back
390 const err = await t.throws(m('delay', ['3000', '22'], {timeout: 30000}));

Reimplement missing features. Fixes #30 & #32 (#68)James Talmagebefore adoptione96350d

lines 391–407why, one step back
391
392 t.false(err.timedOut);393 t.is(err.code, 22);394});395396test('timedOut will be false if no timeout was set and zero exit code', async t => {397 const result = await m('delay', ['1000', '0']);398399 t.false(result.timedOut);400});401402test('timedOut will be false if no timeout was set and non-zero exit code', async t => {403 const err = await t.throws(m('delay', ['1000', '3']));404405 t.false(err.timedOut);406});407

add tests (#48)James Talmagebefore adoptionb15483a

lines 408–433why, one step back
408async function errorMessage(t, expected, ...args) {
409 const err = await t.throws(m('exit', args));410411 t.regex(err.message, expected);412}413414errorMessage.title = (message, expected) => `err.message matches: ${expected}`;415416test(errorMessage, /Command failed: exit 2 foo bar/, 2, 'foo', 'bar');417test(errorMessage, /Command failed: exit 3 baz quz/, 3, 'baz', 'quz');418419async function cmd(t, expected, ...args) {420 const err = await t.throws(m('fail', args));421422 t.is(err.cmd, `fail${expected}`);423424 const result = await m('noop', args);425426 t.is(result.cmd, `noop${expected}`);427}428429cmd.title = (message, expected) => `cmd is: ${JSON.stringify(expected)}`;430431test(cmd, ' foo bar', 'foo', 'bar');432test(cmd, ' baz quz', 'baz', 'quz');433test(cmd, '');

Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd

lines 434–466why, one step back
434
435async function spawnAndKill(t, signal, cleanup) {436 const name = cleanup ? 'sub-process' : 'sub-process-false';437 const cp = m(name);438 let pid;439440 cp.stdout.setEncoding('utf8');441 cp.stdout.on('data', chunk => {442 pid = parseInt(chunk, 10);443 t.is(typeof pid, 'number');444445 setTimeout(() => {446 process.kill(cp.pid, signal);447 }, 100);448 });449450 await t.throws(cp);451452 // Give everybody some time to breath and kill things453 await delay(200);454455 t.false(isRunning(cp.pid));456 t.is(isRunning(pid), !cleanup);457}458459test('cleanup - SIGINT', spawnAndKill, 'SIGINT', true);460test('cleanup - SIGKILL', spawnAndKill, 'SIGTERM', true);461462if (process.platform !== 'win32') {463 // On Windows the subprocesses are actually always killed464 test('cleanup false - SIGINT', spawnAndKill, 'SIGTERM', false);465 test('cleanup false - SIGKILL', spawnAndKill, 'SIGKILL', false);466}

fix support for the `shell` option in `execa.shell()`Sindre Sorhusbefore adoptiona80487b

line 467why, one step back
467

Fix linting (#77)Sam Verschuerenbefore adoption80a059d

line 468why, one step back
468// See: https://github.com/sindresorhus/execa/issues/56

only set to failing test on WindowsSindre Sorhusbefore adoption7d88adc

lines 469–470why, one step back
469const onlyWinFailing = test[process.platform === 'win32' ? 'failing' : 'serial'];
470onlyWinFailing('execa.shell() supports the `shell` option', async t => {

fix support for the `shell` option in `execa.shell()`Sindre Sorhusbefore adoptiona80487b

lines 471–475why, one step back
471 const {stdout} = await m.shell('noop foo', {
472 shell: process.platform === 'win32' ? 'cmd.exe' : '/bin/bash'473 });474 t.is(stdout, 'foo');475});

Attach error listener to stdio stream (#74)Vsevolod Strukchinskybefore adoptiona71bef2

lines 476–478why, one step back
476
477if (process.platform !== 'win32') {478 test('write to fast-exit process', async t => {

Fix linting (#77)Sam Verschuerenbefore adoption80a059d

lines 479–480why, one step back
479 // Try-catch here is necessary, because this test is not 100% accurate
480 // Sometimes process can manage to accept input before exiting

Attach error listener to stdio stream (#74)Vsevolod Strukchinskybefore adoptiona71bef2

lines 481–482why, one step back
481 try {
482 await m(`fast-exit-${process.platform}`, [], {input: 'data'});

Fix tests (#89)Sam Verschuerenbefore adoption1861b5e

line 483why, one step back
483 t.pass();

Attach error listener to stdio stream (#74)Vsevolod Strukchinskybefore adoptiona71bef2

lines 484–488why, one step back
484 } catch (err) {
485 t.is(err.code, 'EPIPE');486 }487 });488}

Extend environment by default - fixes #87 (#88)Sam Verschuerenbefore adoptione370117

line 489why, one step back
489

Fix extending from process.env when no env option is provided - fixes #101 (#102)Sam Verschuerenbefore adoptionafa9700

lines 490–498why, one step back
490test('use environment variables by default', async t => {
491 const result = await m.stdout('environment');492493 t.deepEqual(result.split('\n'), [494 'foo',495 'undefined'496 ]);497});498

Extend environment by default - fixes #87 (#88)Sam Verschuerenbefore adoptione370117

lines 499–507why, one step back
499test('extend environment variables by default', async t => {
500 const result = await m.stdout('environment', [], {env: {BAR: 'bar'}});501502 t.deepEqual(result.split('\n'), [503 'foo',504 'bar'505 ]);506});507

Fix typo in test description (#137)Honza Javorekbefore adoption7e4d44c

line 508why, one step back
508test('do not extend environment with `extendEnv` option', async t => {

Extend environment by default - fixes #87 (#88)Sam Verschuerenbefore adoptione370117

lines 509–515why, one step back
509 const result = await m.stdout('environment', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});
510511 t.deepEqual(result.split('\n'), [512 'undefined',513 'bar'514 ]);515});

Do not buffer when streams are used - fixes #84 (#95)Sam Verschuerenbefore adoption5bab08b

lines 516–521why, one step back
516
517test('do not buffer when streaming', async t => {518 const result = await getStream(m('max-buffer', ['stdout', '21'], {maxBuffer: 10}).stdout);519520 t.is(result, '....................\n');521});

Detached child process should not kill child - fixes #115 (#117)Sam Verschuerenbefore adoption5f890ab

lines 522–527why, one step back
522
523test('detach child process', async t => {524 const file = tempfile('.txt');525526 await m('detach', [file]);527

Increase delay of detached child process (#120)Sam Verschuerenbefore adoption8fb8b6d

line 528why, one step back
528 await delay(5000);

Detached child process should not kill child - fixes #115 (#117)Sam Verschuerenbefore adoption5f890ab

lines 529–531why, one step back
529
530 t.is(fs.readFileSync(file, 'utf8'), 'foo\n');531});

Remove exit handler on exit (#129)Ryan Berdeenbefore adoption0defad4

lines 532–548why, one step back
532
533// See #128534test('removes exit handler on exit', async t => {535 // FIXME: This relies on `signal-exit` internals536 const ee = process.__signal_exit_emitter__;537538 const child = m('noop');539 const listener = ee.listeners('exit').pop();540541 await new Promise((resolve, reject) => {542 child.on('error', reject);543 child.on('exit', resolve);544 });545546 const included = ee.listeners('exit').indexOf(listener) !== -1;547 t.false(included);548});