Skip to content
Myr

Require Node.js 8

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sindre Sorhus · committed by Sindre Sorhus · parent e897f44 · Browse files · 6 files+123 added−112 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+123 added−112 removed

  • tests:+2 added−2 removed
  • other:+121 added−110 removed

6 files+123 added−112 removed

modified:lib/errname.js+1 added-1 removed
modified:test/errname.js+2 added-2 removed
modified:.travis.yml-1 removed
modified:index.js+32 added-17 removed
18 unmodified lines
19 command = parsed.command;20 args = parsed.args;21 options = parsed.options;2223 options = Object.assign({23 options = {24 maxBuffer: TEN_MEGABYTES,25 buffer: true,26 stripFinalNewline: true,27 preferLocal: true,28 localDir: options.cwd || process.cwd(),29 encoding: 'utf8',30 reject: true,31 cleanup: true32 }, options, {31 cleanup: true,32 ...options,33 windowsHide: true34 });34 };3536 if (options.extendEnv !== false) {37 options.env = Object.assign({}, process.env, options.env);37 options.env = {38 ...process.env,39 ...options.env40 };41 }4243 if (options.preferLocal) {41 options.env = npmRunPath.env(Object.assign({}, options, {cwd: options.localDir}));44 options.env = npmRunPath.env({45 ...options,46 cwd: options.localDir47 });48 }4950 // TODO: Remove in the next major release51 if (options.stripEof === false) {
35 unmodified lines
87 return value;88}8990function handleShell(fn, command, options) {85 return fn(command, Object.assign({}, options, {shell: true}));91 return fn(command, {...options, shell: true});92}9394function getStream(process, stream, {encoding, buffer, maxBuffer}) {95 if (!process[stream]) {
166 unmodified lines
262 spawned.stderr.destroy();263 }264 }265266 // TODO: Use native "finally" syntax when targeting Node.js 10267 const handlePromise = () => pFinally(Promise.all([268 processDone,269 getStream(spawned, 'stdout', {encoding, buffer, maxBuffer}),270 getStream(spawned, 'stderr', {encoding, buffer, maxBuffer})264 ]).then(arr => {265 const result = arr[0];266 result.stdout = arr[1];267 result.stderr = arr[2];271 ]).then(results => { // eslint-disable-line promise/prefer-await-to-then272 const result = results[0];273 result.stdout = results[1];274 result.stderr = results[2];275276 if (result.error || result.code !== 0 || result.signal !== null) {277 const error = makeError(result, {278 joinedCommand,
28 unmodified lines
307 crossSpawn._enoent.hookChildProcess(spawned, parsed.parsed);308309 handleInput(spawned, parsed.options.input);310304 spawned.then = (onfulfilled, onrejected) => handlePromise().then(onfulfilled, onrejected);305 spawned.catch = onrejected => handlePromise().catch(onrejected);306 // eslint-disable-next-line no-use-extend-native/no-use-extend-native311 // eslint-disable-next-line promise/prefer-await-to-then312 spawned.then = (onFulfilled, onRejected) => handlePromise().then(onFulfilled, onRejected);313 spawned.catch = onRejected => handlePromise().catch(onRejected);314315 // TOOD: Remove the `if`-guard when targeting Node.js 10316 if (Promise.prototype.finally) {308 spawned.finally = onfinally => handlePromise().finally(onfinally);317 spawned.finally = onFinally => handlePromise().finally(onFinally);318 }319320 return spawned;321};322323// TODO: set `stderr: 'ignore'` when that option is implemented315module.exports.stdout = (...args) => module.exports(...args).then(x => x.stdout);324module.exports.stdout = async (...args) => {325 const {stdout} = await module.exports(...args);326 return stdout;327};328329// TODO: set `stdout: 'ignore'` when that option is implemented318module.exports.stderr = (...args) => module.exports(...args).then(x => x.stderr);330module.exports.stderr = async (...args) => {331 const {stderr} = await module.exports(...args);332 return stderr;333};334335module.exports.shell = (command, options) => handleShell(module.exports, command, options);336337module.exports.sync = (command, args, options) => {
35 unmodified lines
modified:package.json+7 added-7 removed
modified:test.js+81 added-84 removed
5 unmodified lines
6import getStream from 'get-stream';7import isRunning from 'is-running';8import delay from 'delay';9import tempfile from 'tempfile';10import m from '.';10import execa from '.';1112process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;13process.env.FOO = 'foo';1415const NO_NEWLINES_REGEXP = /^[^\n]*$/;16const STDERR_STDOUT_REGEXP = /stderr[^]*stdout/;17const TIMEOUT_REGEXP = /timed out after/;1819function getExitRegExp(exitMessage) {20 return new RegExp(`failed with exit code ${exitMessage}`);19const getExitRegExp = exitMessage => new RegExp(`failed with exit code ${exitMessage}`);21}2021test('execa()', async t => {24 const {stdout} = await m('noop', ['foo']);22 const {stdout} = await execa('noop', ['foo']);23 t.is(stdout, 'foo');24});2526if (process.platform === 'win32') {27 test('execa() - cmd file', async t => {30 const {stdout} = await m('hello.cmd');3128 const {stdout} = await execa('hello.cmd');29 t.is(stdout, 'Hello World');30 });31}3233test('buffer', async t => {37 const {stdout} = await m('noop', ['foo'], {encoding: null});34 const {stdout} = await execa('noop', ['foo'], {encoding: null});35 t.true(Buffer.isBuffer(stdout));36 t.is(stdout.toString(), 'foo');37});3839test('execa.stdout()', async t => {43 const stdout = await m.stdout('noop', ['foo']);40 const stdout = await execa.stdout('noop', ['foo']);41 t.is(stdout, 'foo');42});4344test('execa.stderr()', async t => {48 const stderr = await m.stderr('noop-err', ['foo']);45 const stderr = await execa.stderr('noop-err', ['foo']);46 t.is(stderr, 'foo');47});4849test('stdout/stderr available on errors', async t => {53 const err = await t.throwsAsync(m('exit', ['2']), {message: getExitRegExp('2')});50 const err = await t.throwsAsync(execa('exit', ['2']), {message: getExitRegExp('2')});51 t.is(typeof err.stdout, 'string');52 t.is(typeof err.stderr, 'string');53});5455test('include stdout and stderr in errors for improved debugging', async t => {59 await t.throwsAsync(m('fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});56 await t.throwsAsync(execa('fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});57});5859test('do not include in errors when `stdio` is set to `inherit`', async t => {63 await t.throwsAsync(m('fixtures/error-message.js', {stdio: 'inherit'}), {message: NO_NEWLINES_REGEXP});60 await t.throwsAsync(execa('fixtures/error-message.js', {stdio: 'inherit'}), {message: NO_NEWLINES_REGEXP});61});6263test('do not include `stderr` and `stdout` in errors when set to `inherit`', async t => {67 await t.throwsAsync(m('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}), {message: NO_NEWLINES_REGEXP});64 await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit', stderr: 'inherit'}), {message: NO_NEWLINES_REGEXP});65});6667test('do not include `stderr` and `stdout` in errors when `stdio` is set to `inherit`', async t => {71 await t.throwsAsync(m('fixtures/error-message.js', {stdio: [null, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});68 await t.throwsAsync(execa('fixtures/error-message.js', {stdio: [null, 'inherit', 'inherit']}), {message: NO_NEWLINES_REGEXP});69});7071test('do not include `stdout` in errors when set to `inherit`', async t => {75 const err = await t.throwsAsync(m('fixtures/error-message.js', {stdout: 'inherit'}), {message: /stderr/});72 const err = await t.throwsAsync(execa('fixtures/error-message.js', {stdout: 'inherit'}), {message: /stderr/});73 t.notRegex(err.message, /stdout/);74});7576test('do not include `stderr` in errors when set to `inherit`', async t => {80 const err = await t.throwsAsync(m('fixtures/error-message.js', {stderr: 'inherit'}), {message: /stdout/});77 const err = await t.throwsAsync(execa('fixtures/error-message.js', {stderr: 'inherit'}), {message: /stdout/});78 t.notRegex(err.message, /stderr/);79});8081test('pass `stdout` to a file descriptor', async t => {82 const file = tempfile('.txt');86 await m('fixtures/noop', ['foo bar'], {stdout: fs.openSync(file, 'w')});83 await execa('fixtures/noop', ['foo bar'], {stdout: fs.openSync(file, 'w')});84 t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');85});8687test('pass `stderr` to a file descriptor', async t => {88 const file = tempfile('.txt');92 await m('fixtures/noop-err', ['foo bar'], {stderr: fs.openSync(file, 'w')});89 await execa('fixtures/noop-err', ['foo bar'], {stderr: fs.openSync(file, 'w')});90 t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n');91});9293test('execa.shell()', async t => {97 const {stdout} = await m.shell('node fixtures/noop foo');94 const {stdout} = await execa.shell('node fixtures/noop foo');95 t.is(stdout, 'foo');96});9798test('execa.sync()', t => {102 const {stdout} = m.sync('noop', ['foo']);99 const {stdout} = execa.sync('noop', ['foo']);100 t.is(stdout, 'foo');101});102103test('execa.sync() throws error if written to stderr', t => {107 t.throws(() => m.sync('foo'), process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : /spawnSync foo ENOENT/);104 t.throws(() => execa.sync('foo'), process.platform === 'win32' ? /'foo' is not recognized as an internal or external command/ : /spawnSync foo ENOENT/);105});106107test('execa.sync() includes stdout and stderr in errors for improved debugging', t => {111 t.throws(() => m.sync('node', ['fixtures/error-message.js']), {message: STDERR_STDOUT_REGEXP, code: 1});108 t.throws(() => execa.sync('node', ['fixtures/error-message.js']), {message: STDERR_STDOUT_REGEXP, code: 1});109});110111test('skip throwing when using reject option in execa.sync()', t => {115 const err = m.sync('node', ['fixtures/error-message.js'], {reject: false});112 const err = execa.sync('node', ['fixtures/error-message.js'], {reject: false});113 t.is(typeof err.stdout, 'string');114 t.is(typeof err.stderr, 'string');115});116117test('execa.shellSync()', t => {121 const {stdout} = m.shellSync('node fixtures/noop foo');118 const {stdout} = execa.shellSync('node fixtures/noop foo');119 t.is(stdout, 'foo');120});121122test('execa.shellSync() includes stdout and stderr in errors for improved debugging', t => {126 t.throws(() => m.shellSync('node fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});123 t.throws(() => execa.shellSync('node fixtures/error-message.js'), {message: STDERR_STDOUT_REGEXP, code: 1});124});125126test('skip throwing when using reject option in execa.shellSync()', t => {130 const err = m.shellSync('node fixtures/error-message.js', {reject: false});127 const err = execa.shellSync('node fixtures/error-message.js', {reject: false});128 t.is(typeof err.stdout, 'string');129 t.is(typeof err.stderr, 'string');130});131132test('stripEof option (legacy)', async t => {136 const {stdout} = await m('noop', ['foo'], {stripEof: false});133 const {stdout} = await execa('noop', ['foo'], {stripEof: false});134 t.is(stdout, 'foo\n');135});136137test('stripFinalNewline option', async t => {141 const {stdout} = await m('noop', ['foo'], {stripFinalNewline: false});138 const {stdout} = await execa('noop', ['foo'], {stripFinalNewline: false});139 t.is(stdout, 'foo\n');140});141142test.serial('preferLocal option', async t => {146 t.true((await m('cat-names')).stdout.length > 2);143 t.true((await execa('cat-names')).stdout.length > 2);144145 if (process.platform === 'win32') {146 // TODO: figure out how to make the below not hang on Windows147 return;
1 unmodified line
149150 // Account for npm adding local binaries to the PATH151 const _path = process.env.PATH;152 process.env.PATH = '';156 await t.throwsAsync(m('cat-names', {preferLocal: false}), /spawn .* ENOENT/);153 await t.throwsAsync(execa('cat-names', {preferLocal: false}), /spawn .* ENOENT/);154 process.env.PATH = _path;155});156157test.serial('localDir option', async t => {158 const cwd = 'fixtures/local-dir';159 const bin = path.resolve(cwd, 'node_modules/.bin/self-path');160164 await m('npm', ['install', '--no-package-lock'], {cwd});161 await execa('npm', ['install', '--no-package-lock'], {cwd});162166 const {stdout} = await m(bin, {localDir: cwd});163 const {stdout} = await execa(bin, {localDir: cwd});164165 t.is(path.relative(cwd, stdout), path.normalize('node_modules/self-path'));166});167168test('input option can be a String', async t => {172 const {stdout} = await m('stdin', {input: 'foobar'});169 const {stdout} = await execa('stdin', {input: 'foobar'});170 t.is(stdout, 'foobar');171});172173test('input option can be a Buffer', async t => {177 const {stdout} = await m('stdin', {input: 'testing12'});174 const {stdout} = await execa('stdin', {input: 'testing12'});175 t.is(stdout, 'testing12');176});177178test('input can be a Stream', async t => {179 const s = new stream.PassThrough();180 s.write('howdy');181 s.end();185 const {stdout} = await m('stdin', {input: s});182 const {stdout} = await execa('stdin', {input: s});183 t.is(stdout, 'howdy');184});185186test('you can write to child.stdin', async t => {190 const child = m('stdin');187 const child = execa('stdin');188 child.stdin.end('unicorns');189 t.is((await child).stdout, 'unicorns');190});191192test('input option can be a String - sync', t => {196 const {stdout} = m.sync('stdin', {input: 'foobar'});193 const {stdout} = execa.sync('stdin', {input: 'foobar'});194 t.is(stdout, 'foobar');195});196197test('input option can be a Buffer - sync', t => {201 const {stdout} = m.sync('stdin', {input: Buffer.from('testing12', 'utf8')});198 const {stdout} = execa.sync('stdin', {input: Buffer.from('testing12', 'utf8')});199 t.is(stdout, 'testing12');200});201202test('opts.stdout:ignore - stdout will not collect data', async t => {206 const {stdout} = await m('stdin', {203 const {stdout} = await execa('stdin', {204 input: 'hello',205 stdio: [null, 'ignore', null]206 });207 t.is(stdout, null);208});209210test('helpful error trying to provide an input stream in sync mode', t => {211 t.throws(215 () => m.sync('stdin', {input: new stream.PassThrough()}),212 () => execa.sync('stdin', {input: new stream.PassThrough()}),213 /The `input` option cannot be a stream in sync mode/214 );215});216217test('execa() returns a promise with kill() and pid', t => {221 const promise = m('noop', ['foo']);218 const promise = execa('noop', ['foo']);219 t.is(typeof promise.kill, 'function');220 t.is(typeof promise.pid, 'number');221});222223test('maxBuffer affects stdout', async t => {227 await t.throwsAsync(m('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);228 await t.notThrowsAsync(m('max-buffer', ['stdout', '10'], {maxBuffer: 10}));224 await t.throwsAsync(execa('max-buffer', ['stdout', '11'], {maxBuffer: 10}), /stdout maxBuffer exceeded/);225 await t.notThrowsAsync(execa('max-buffer', ['stdout', '10'], {maxBuffer: 10}));226});227228test('maxBuffer affects stderr', async t => {232 await t.throwsAsync(m('max-buffer', ['stderr', '13'], {maxBuffer: 12}), /stderr maxBuffer exceeded/);233 await t.notThrowsAsync(m('max-buffer', ['stderr', '12'], {maxBuffer: 12}));229 await t.throwsAsync(execa('max-buffer', ['stderr', '13'], {maxBuffer: 12}), /stderr maxBuffer exceeded/);230 await t.notThrowsAsync(execa('max-buffer', ['stderr', '12'], {maxBuffer: 12}));231});232233test('do not buffer stdout when `buffer` set to `false`', async t => {237 const promise = m('max-buffer', ['stdout', '10'], {buffer: false});234 const promise = execa('max-buffer', ['stdout', '10'], {buffer: false});235 const [result, stdout] = await Promise.all([236 promise,237 getStream(promise.stdout)238 ]);
2 unmodified lines
241 t.is(stdout, '.........\n');242});243244test('do not buffer stderr when `buffer` set to `false`', async t => {248 const promise = m('max-buffer', ['stderr', '10'], {buffer: false});245 const promise = execa('max-buffer', ['stderr', '10'], {buffer: false});246 const [result, stderr] = await Promise.all([247 promise,248 getStream(promise.stderr)249 ]);
2 unmodified lines
252 t.is(stderr, '.........\n');253});254255test('skip throwing when using reject option', async t => {259 const error = await m('exit', ['2'], {reject: false});256 const error = await execa('exit', ['2'], {reject: false});257 t.is(typeof error.stdout, 'string');258 t.is(typeof error.stderr, 'string');259});260261test('allow unknown exit code', async t => {265 await t.throwsAsync(m('exit', ['255']), {message: /exit code 255 \(Unknown system error -255\)/});262 await t.throwsAsync(execa('exit', ['255']), {message: /exit code 255 \(Unknown system error -255\)/});263});264265test('execa() returns code and failed properties', async t => {269 const {code, failed} = await m('noop', ['foo']);270 const error = await t.throwsAsync(m('exit', ['2']), {code: 2, message: getExitRegExp('2')});266 const {code, failed} = await execa('noop', ['foo']);267 const error = await t.throwsAsync(execa('exit', ['2']), {code: 2, message: getExitRegExp('2')});268 t.is(code, 0);269 t.false(failed);270 t.true(error.failed);271});272273test('use relative path with \'..\' chars', async t => {274 const pathViaParentDir = path.join('..', path.basename(__dirname), 'fixtures', 'noop');278 const {stdout} = await m(pathViaParentDir, ['foo']);275 const {stdout} = await execa(pathViaParentDir, ['foo']);276 t.is(stdout, 'foo');277});278279if (process.platform !== 'win32') {280 test('execa() rejects if running non-executable', async t => {284 const cp = m('non-executable');281 const cp = execa('non-executable');282 await t.throwsAsync(cp);283 });284}285286test('error.killed is true if process was killed directly', async t => {290 const cp = m('forever');287 const cp = execa('forever');288289 setTimeout(() => {290 cp.kill();291 }, 100);
3 unmodified lines
295});296297// TODO: Should this really be the case, or should we improve on child_process?298test('error.killed is false if process was killed indirectly', async t => {302 const cp = m('forever');299 const cp = execa('forever');300301 setTimeout(() => {302 process.kill(cp.pid, 'SIGINT');303 }, 100);
19 unmodified lines
323}324325if (process.platform !== 'win32') {326 test('error.signal is SIGINT', async t => {330 const cp = m('forever');327 const cp = execa('forever');328329 setTimeout(() => {330 process.kill(cp.pid, 'SIGINT');331 }, 100);
2 unmodified lines
334 t.is(error.signal, 'SIGINT');335 });336337 test('error.signal is SIGTERM', async t => {341 const cp = m('forever');338 const cp = execa('forever');339340 setTimeout(() => {341 process.kill(cp.pid, 'SIGTERM');342 }, 100);
2 unmodified lines
345 t.is(error.signal, 'SIGTERM');346 });347348 test('custom error.signal', async t => {352 const error = await t.throwsAsync(m('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500, message: TIMEOUT_REGEXP}));349 const error = await t.throwsAsync(execa('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500, message: TIMEOUT_REGEXP}));350 t.is(error.signal, 'SIGHUP');351 });352}353354test('result.signal is null for successful execution', async t => {358 t.is((await m('noop')).signal, null);355 t.is((await execa('noop')).signal, null);356});357358test('result.signal is null if process failed, but was not killed', async t => {362 const error = await t.throwsAsync(m('exit', [2]), {message: getExitRegExp('2')});359 const error = await t.throwsAsync(execa('exit', [2]), {message: getExitRegExp('2')});360 t.is(error.signal, null);361});362363async function code(t, num) {367 await t.throwsAsync(m('exit', [`${num}`]), {code: num, message: getExitRegExp(num)});364 await t.throwsAsync(execa('exit', [`${num}`]), {code: num, message: getExitRegExp(num)});365}366367test('error.code is 2', code, 2);368test('error.code is 3', code, 3);369test('error.code is 4', code, 4);370371test('timeout will kill the process early', async t => {375 const error = await t.throwsAsync(m('delay', ['60000', '0'], {timeout: 1500, message: TIMEOUT_REGEXP}));372 const error = await t.throwsAsync(execa('delay', ['60000', '0'], {timeout: 1500, message: TIMEOUT_REGEXP}));373374 t.true(error.timedOut);375 t.not(error.code, 22);376});377378test('timeout will not kill the process early', async t => {382 const error = await t.throwsAsync(m('delay', ['3000', '22'], {timeout: 30000}), {code: 22, message: getExitRegExp('22')});379 const error = await t.throwsAsync(execa('delay', ['3000', '22'], {timeout: 30000}), {code: 22, message: getExitRegExp('22')});380 t.false(error.timedOut);381});382383test('timedOut will be false if no timeout was set and zero exit code', async t => {387 const result = await m('delay', ['1000', '0']);384 const result = await execa('delay', ['1000', '0']);385 t.false(result.timedOut);386});387388test('timedOut will be false if no timeout was set and non-zero exit code', async t => {392 const error = await t.throwsAsync(m('delay', ['1000', '3']), {message: getExitRegExp('3')});389 const error = await t.throwsAsync(execa('delay', ['1000', '3']), {message: getExitRegExp('3')});390 t.false(error.timedOut);391});392393async function errorMessage(t, expected, ...args) {397 await t.throwsAsync(m('exit', args), {message: expected});394 await t.throwsAsync(execa('exit', args), {message: expected});395}396397errorMessage.title = (message, expected) => `error.message matches: ${expected}`;398399test(errorMessage, /Command failed with exit code 2.*: exit 2 foo bar/, 2, 'foo', 'bar');400test(errorMessage, /Command failed with exit code 3.*: exit 3 baz quz/, 3, 'baz', 'quz');401402async function cmd(t, expected, ...args) {406 const error = await t.throwsAsync(m('fail', args));403 const error = await t.throwsAsync(execa('fail', args));404 t.is(error.cmd, `fail${expected}`);405409 const result = await m('noop', args);406 const result = await execa('noop', args);407 t.is(result.cmd, `noop${expected}`);408}409410cmd.title = (message, expected) => `cmd is: ${JSON.stringify(expected)}`;
3 unmodified lines
414test(cmd, '');415416async function spawnAndKill(t, signal, cleanup) {417 const name = cleanup ? 'sub-process' : 'sub-process-false';421 const cp = m(name);418 const cp = execa(name);419 let pid;420421 cp.stdout.setEncoding('utf8');422 cp.stdout.on('data', chunk => {
23 unmodified lines
446 test('cleanup false - SIGKILL', spawnAndKill, 'SIGKILL', false);447}448449test('execa.shell() supports the `shell` option', async t => {453 const {stdout} = await m.shell('node fixtures/noop foo', {450 const {stdout} = await execa.shell('node fixtures/noop foo', {451 shell: process.platform === 'win32' ? 'cmd.exe' : '/bin/bash'452 });453 t.is(stdout, 'foo');454});
2 unmodified lines
457 test('write to fast-exit process', async t => {458 // Try-catch here is necessary, because this test is not 100% accurate459 // Sometimes process can manage to accept input before exiting460 try {464 await m(`fast-exit-${process.platform}`, [], {input: 'data'});461 await execa(`fast-exit-${process.platform}`, [], {input: 'data'});462 t.pass();463 } catch (error) {464 t.is(error.code, 32);465 }466 });467}468469test('use environment variables by default', async t => {473 const result = await m.stdout('environment');470 const result = await execa.stdout('environment');471472 t.deepEqual(result.split('\n'), [473 'foo',474 'undefined'475 ]);476});477478test('extend environment variables by default', async t => {482 const result = await m.stdout('environment', [], {env: {BAR: 'bar'}});479 const result = await execa.stdout('environment', [], {env: {BAR: 'bar'}});480481 t.deepEqual(result.split('\n'), [482 'foo',483 'bar'484 ]);485});486487test('do not extend environment with `extendEnv: false`', async t => {491 const result = await m.stdout('environment', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});488 const result = await execa.stdout('environment', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});489490 t.deepEqual(result.split('\n'), [491 'undefined',492 'bar'
2 unmodified lines
495496test('use extend environment with `extendEnv: true` and `shell: true`', async t => {497 process.env.TEST = 'test';498 const command = process.platform === 'win32' ? 'echo %TEST%' : 'echo $TEST';502 const stdout = await m.stdout(command, {shell: true, env: {}, extendEnv: true});499 const stdout = await execa.stdout(command, {shell: true, env: {}, extendEnv: true});500 t.is(stdout, 'test');501 delete process.env.TEST;502});503504test('do not buffer when streaming', async t => {508 const result = await getStream(m('max-buffer', ['stdout', '21'], {maxBuffer: 10}).stdout);505 const result = await getStream(execa('max-buffer', ['stdout', '21'], {maxBuffer: 10}).stdout);506507 t.is(result, '....................\n');508});509510test('detach child process', async t => {511 const file = tempfile('.txt');512516 await m('detach', [file]);513 await execa('detach', [file]);514515 await delay(5000);516517 t.is(fs.readFileSync(file, 'utf8'), 'foo\n');
3 unmodified lines
521test('removes exit handler on exit', async t => {522 // FIXME: This relies on `signal-exit` internals523 const ee = process.__signal_exit_emitter__;524528 const child = m('noop');525 const child = execa('noop');526 const listener = ee.listeners('exit').pop();527528 await new Promise((resolve, reject) => {529 child.on('error', reject);
3 unmodified lines
533 const included = ee.listeners('exit').includes(listener);534 t.false(included);535});536540// eslint-disable-next-line no-use-extend-native/no-use-extend-native537// TOOD: Remove the `if`-guard when targeting Node.js 10538if (Promise.prototype.finally) {539 test('finally function is executed on success', async t => {540 let called = false;544 const {stdout} = await m('noop', ['foo']).finally(() => {541 const {stdout} = await execa('noop', ['foo']).finally(() => {542 called = true;543 });544 t.is(called, true);545 t.is(stdout, 'foo');546 });547548 test('finally function is executed on failure', async t => {549 let called = false;553 const err = await t.throwsAsync(m('exit', ['2']).finally(() => {550 const err = await t.throwsAsync(execa('exit', ['2']).finally(() => {551 called = true;552 }));553 t.is(called, true);554 t.is(typeof err.stdout, 'string');555 t.is(typeof err.stderr, 'string');556 });557558 test('throw in finally function bubbles up on success', async t => {562 const result = await t.throwsAsync(m('noop', ['foo']).finally(() => {559 const result = await t.throwsAsync(execa('noop', ['foo']).finally(() => {560 throw new Error('called');561 }));562 t.is(result.message, 'called');563 });564565 test('throw in finally bubbles up on error', async t => {569 const result = await t.throwsAsync(m('exit', ['2']).finally(() => {566 const result = await t.throwsAsync(execa('exit', ['2']).finally(() => {567 throw new Error('called');568 }));569 t.is(result.message, 'called');570 });
1 unmodified line