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 fileTake it
fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 1why, one step back1import path from 'path';Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
line 2why, one step back2import fs from 'fs';add `input` optionJames Talmagebefore adoption605a674
line 3why, one step back3import stream from 'stream';add tests (#48)James Talmagebefore adoptionb15483a
line 4why, one step back4import childProcess from 'child_process';5import test from 'ava';make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220
line 6why, one step back6import getStream from 'get-stream';Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd
lines 7–8why, one step back7import isRunning from 'is-running';8import delay from 'delay';Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
line 9why, one step back9import tempfile from 'tempfile';Fix lintingSindre Sorhusbefore adoptionf4e2d56
line 10why, one step back10import m from '.';11fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 12why, one step back12process.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 back13process.env.FOO = 'foo';fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 14why, one step back1415test('execa()', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 16why, one step back16 const {stdout} = await m('noop', ['foo']);initSindre Sorhusbefore adoptionbc16d6b
lines 17–1917 t.is(stdout, 'foo');18});19Turn off echo on Windows - fixes #116 (#118)Sam Verschuerenbefore adoptionff76235
lines 20–27why, one step back20if (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}2728test('buffer', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 29why, one step back29 const {stdout} = await m('noop', ['foo'], {encoding: null});initSindre Sorhusbefore adoptionbc16d6b
lines 30–3330 t.true(Buffer.isBuffer(stdout));31 t.is(stdout.toString(), 'foo');32});33add `execa.stdout()` shortcut (#14)Sindre Sorhusbefore adoption868f505
lines 34–43why, one step back34test('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});43add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf
line 44why, one step back44test('stdout/stderr available on errors', async t => {meta tweaksSindre Sorhusbefore adoption858af26
lines 45–47why, one step back45 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 back48});49add tests (#48)James Talmagebefore adoptionb15483a
line 50why, one step back50test('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 back51 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 back53 t.regex(err.message, /stderr/);Fix test for exit code 1 on windows (#78)Sam Verschuerenbefore adoption4231a10
line 54why, one step back54 t.is(err.code, 1);include stdout in errors for improved debuggingSindre Sorhusbefore adoptionaea8c9a
lines 55–56why, one step back55});56Do not output stderr and stdout on stdio inherit - fixes #70 (#79)Sam Verschuerenbefore adoption2a12986
lines 57–58why, one step back57test('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 back59 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 back94});95Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 96why, one step back96test('execa.shell()', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 97why, one step back97 const {stdout} = await m.shell('node fixtures/noop foo');Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
lines 98–100why, one step back98 t.is(stdout, 'foo');99});100make `execa.spawn()` use the same argument normalization as `execa()`Sindre Sorhusbefore adoptiond6e3220
line 101why, one step back101test('execa.spawn()', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
lines 102–103why, one step back102 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 back104});105add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
line 106why, one step back106test('execa.sync()', t => {[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100
line 107why, one step back107 const {stdout} = m.sync('noop', ['foo']);add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
lines 108–110why, one step back108 t.is(stdout, 'foo');109});110Throw error in sync method - fixes #66 (#67)Sam Verschuerenbefore adoptionc8c9c7b
lines 111–114why, one step back111test('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});114Enhance error object in sync methods - fixes #98 (#107)Sam Verschuerenbefore adoptiond31cc91
lines 115–127why, one step back115test('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});127add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee
line 128why, one step back128test('execa.shellSync()', t => {[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100
line 129why, one step back129 const {stdout} = m.shellSync('node fixtures/noop foo');add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee
line 130why, one step back130 t.is(stdout, 'foo');Enhance error object in sync methods - fixes #98 (#107)Sam Verschuerenbefore adoptiond31cc91
lines 131–143why, one step back131});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 back144});145146test('stripEof option', async t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 147why, one step back147 const {stdout} = await m('noop', ['foo'], {stripEof: false});initSindre Sorhusbefore adoptionbc16d6b
lines 148–150148 t.is(stdout, 'foo\n');149});150Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 151why, one step back151test.serial('preferLocal option', async t => {tweaksSindre Sorhusbefore adoptione3505a8
line 152why, one step back152 t.true((await m('cat-names')).stdout.length > 2);Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 153why, one step back153fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
lines 154–158why, one step back154 if (process.platform === 'win32') {155 // TODO: figure out how to make the below not hang on Windows156 return;157 }158Fix linting (#77)Sam Verschuerenbefore adoption80a059d
line 159why, one step back159 // Account for npm adding local binaries to the PATHMerge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
lines 160–161why, one step back160 const _path = process.env.PATH;161 process.env.PATH = '';fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 162why, one step back162 await t.throws(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 163why, one step back163 process.env.PATH = _path;add `input` optionJames Talmagebefore adoption605a674
lines 164–165why, one step back164});165Fix test flakiness on WindowsSindre Sorhusbefore adoptionf071546
line 166why, one step back166test.serial('localDir option', async t => {Add test for #73Sindre Sorhusbefore adoptionc7481f4
lines 167–173why, one step back167 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});173Meta tweaksSindre Sorhusbefore adoptionc0fc20c
line 174why, one step back174 t.is(path.relative(cwd, stdout), path.normalize('node_modules/self-path'));Add test for #73Sindre Sorhusbefore adoptionc7481f4
lines 175–176why, one step back175});176add `input` optionJames Talmagebefore adoption605a674
line 177why, one step back177test('input option can be a String', async t => {fix option handling in #15Sindre Sorhusbefore adoption3d31e8d
line 178why, one step back178 const {stdout} = await m('stdin', {input: 'foobar'});add `input` optionJames Talmagebefore adoption605a674
lines 179–182why, one step back179 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 back183 const {stdout} = await m('stdin', {input: 'testing12'});add `input` optionJames Talmagebefore adoption605a674
lines 184–187why, one step back184 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 back188 const s = new stream.PassThrough();add `input` optionJames Talmagebefore adoption605a674
lines 189–190why, one step back189 s.write('howdy');190 s.end();fix option handling in #15Sindre Sorhusbefore adoption3d31e8d
line 191why, one step back191 const {stdout} = await m('stdin', {input: s});add `input` optionJames Talmagebefore adoption605a674
lines 192–194why, one step back192 t.is(stdout, 'howdy');193});194return the child process instead of a promise. (#18)James Talmagebefore adoption99f10ba
lines 195–200why, one step back195test('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});200Fix linting (#77)Sam Verschuerenbefore adoption80a059d
line 201why, one step back201test('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 back202 const {stdout} = m.sync('stdin', {input: 'foobar'});add `input` optionJames Talmagebefore adoption605a674
lines 203–205why, one step back203 t.is(stdout, 'foobar');204});205Fix linting (#77)Sam Verschuerenbefore adoption80a059d
lines 206–207why, one step back206test('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 back208 t.is(stdout, 'testing12');Use spawn instead of execFile (#27)James Talmagebefore adoption31a8d87
lines 209–211why, one step back209});210211test('opts.stdout:ignore - stdout will not collect data', async t => {fix XO lint issuesSindre Sorhusbefore adoption342096c
lines 212–215why, one step back212 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 back216 t.is(stdout, null);add `input` optionJames Talmagebefore adoption605a674
lines 217–220why, one step back217});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 back221 () => m.sync('stdin', {input: new stream.PassThrough()}),add `input` optionJames Talmagebefore adoption605a674
lines 222–223why, one step back222 /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 back224});225226test('execa() returns a promise with kill() and pid', t => {fix tests on Windows 💩Sindre Sorhusbefore adoption14f16df
line 227why, one step back227 const promise = m('noop', ['foo']);Attach pid and kill() to returned promise (#11)Luke Horvatbefore adoption9da5484
lines 228–229why, one step back228 t.is(typeof promise.kill, 'function');229 t.is(typeof promise.pid, 'number');230});add max-buffer support (#37)James Talmagebefore adoption6288806
line 231why, one step back231Fix tests (#89)Sam Verschuerenbefore adoption1861b5e
lines 232–234why, one step back232test('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 back235});236Fix tests (#89)Sam Verschuerenbefore adoption1861b5e
lines 237–239why, one step back237test('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 back240});Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76
line 241why, one step back241Add `buffer` option to be able to disable buffering (#133)Spencerbefore adoption50384aa
lines 242–263why, one step back242test('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});263Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76
line 264why, one step back264test('skip throwing when using reject option', async t => {Fix tests (#89)Sam Verschuerenbefore adoption1861b5e
line 265why, one step back265 const err = await m('exit', ['2'], {reject: false});Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76
lines 266–277why, one step back266 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 back278279test(`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 back284add test case for throwing on non-executables (#49)Markus Wolfbefore adoptione10d263
line 285why, one step back285if (process.platform !== 'win32') {Fix tests (#89)Sam Verschuerenbefore adoption1861b5e
line 286why, one step back286 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 back287 const cp = m('non-executable');Fix tests (#89)Sam Verschuerenbefore adoption1861b5e
line 288why, one step back288 await t.throws(cp);add test case for throwing on non-executables (#49)Markus Wolfbefore adoptione10d263
lines 289–291why, one step back289 });290}291add tests (#48)James Talmagebefore adoptionb15483a
lines 292–294why, one step back292test('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 back295 setTimeout(() => {add tests (#48)James Talmagebefore adoptionb15483a
lines 296–307why, one step back296 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 back308 setTimeout(() => {add tests (#48)James Talmagebefore adoptionb15483a
lines 309–324why, one step back309 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 back325 setTimeout(() => {add tests (#48)James Talmagebefore adoptionb15483a
lines 326–334why, one step back326 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 back335 setTimeout(() => {add tests (#48)James Talmagebefore adoptionb15483a
lines 336–346why, one step back336 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 back347 setTimeout(() => {add tests (#48)James Talmagebefore adoptionb15483a
lines 348–354why, one step back348 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 back355356 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 back361}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);381Reimplement missing features. Fixes #30 & #32 (#68)James Talmagebefore adoptione96350d
line 382why, one step back382test('timeout will kill the process early', async t => {Add `buffer` option to be able to disable buffering (#133)Spencerbefore adoption50384aa
line 383why, one step back383 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 back384385 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 back390 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 back391392 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});407add tests (#48)James Talmagebefore adoptionb15483a
lines 408–433why, one step back408async 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 back434435async 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 back467Fix linting (#77)Sam Verschuerenbefore adoption80a059d
line 468why, one step back468// See: https://github.com/sindresorhus/execa/issues/56only set to failing test on WindowsSindre Sorhusbefore adoption7d88adc
lines 469–470why, one step back469const 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 back471 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 back476477if (process.platform !== 'win32') {478 test('write to fast-exit process', async t => {Fix linting (#77)Sam Verschuerenbefore adoption80a059d
lines 479–480why, one step back479 // Try-catch here is necessary, because this test is not 100% accurate480 // Sometimes process can manage to accept input before exitingAttach error listener to stdio stream (#74)Vsevolod Strukchinskybefore adoptiona71bef2
lines 481–482why, one step back481 try {482 await m(`fast-exit-${process.platform}`, [], {input: 'data'});Fix tests (#89)Sam Verschuerenbefore adoption1861b5e
line 483why, one step back483 t.pass();Attach error listener to stdio stream (#74)Vsevolod Strukchinskybefore adoptiona71bef2
lines 484–488why, one step back484 } 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 back489Fix extending from process.env when no env option is provided - fixes #101 (#102)Sam Verschuerenbefore adoptionafa9700
lines 490–498why, one step back490test('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});498Extend environment by default - fixes #87 (#88)Sam Verschuerenbefore adoptione370117
lines 499–507why, one step back499test('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});507Fix typo in test description (#137)Honza Javorekbefore adoption7e4d44c
line 508why, one step back508test('do not extend environment with `extendEnv` option', async t => {Extend environment by default - fixes #87 (#88)Sam Verschuerenbefore adoptione370117
lines 509–515why, one step back509 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 back516517test('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 back522523test('detach child process', async t => {524 const file = tempfile('.txt');525526 await m('detach', [file]);527Increase delay of detached child process (#120)Sam Verschuerenbefore adoption8fb8b6d
line 528why, one step back528 await delay(5000);Detached child process should not kill child - fixes #115 (#117)Sam Verschuerenbefore adoption5f890ab
lines 529–531why, one step back529530 t.is(fs.readFileSync(file, 'utf8'), 'foo\n');531});Remove exit handler on exit (#129)Ryan Berdeenbefore adoption0defad4
lines 532–548why, one step back532533// 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});