Skip to content

Commit

Permalink
Merge 8db39f8 into cf32d16
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 16, 2019
2 parents cf32d16 + 8db39f8 commit 7dbd562
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
30 changes: 15 additions & 15 deletions test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ test('failed is true on failure', async t => {
});

test('error.killed is true if process was killed directly', async t => {
const cp = execa('noop');
const subprocess = execa('noop');

cp.kill();
subprocess.kill();

const {killed} = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});
const {killed} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});
t.true(killed);
});

test('error.killed is false if process was killed indirectly', async t => {
const cp = execa('noop');
const subprocess = execa('noop');

process.kill(cp.pid, 'SIGINT');
process.kill(subprocess.pid, 'SIGINT');

// `process.kill()` is emulated by Node.js on Windows
const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/;
const {killed} = await t.throwsAsync(cp, {message});
const {killed} = await t.throwsAsync(subprocess, {message});
t.false(killed);
});

Expand Down Expand Up @@ -125,20 +125,20 @@ if (process.platform === 'darwin') {

if (process.platform !== 'win32') {
test('error.signal is SIGINT', async t => {
const cp = execa('noop');
const subprocess = execa('noop');

process.kill(cp.pid, 'SIGINT');
process.kill(subprocess.pid, 'SIGINT');

const {signal} = await t.throwsAsync(cp, {message: /was killed with SIGINT/});
const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});
t.is(signal, 'SIGINT');
});

test('error.signal is SIGTERM', async t => {
const cp = execa('noop');
const subprocess = execa('noop');

process.kill(cp.pid, 'SIGTERM');
process.kill(subprocess.pid, 'SIGTERM');

const {signal} = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});
const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});
t.is(signal, 'SIGTERM');
});

Expand All @@ -148,11 +148,11 @@ if (process.platform !== 'win32') {
});

test('exitCode is undefined on signal termination', async t => {
const cp = execa('noop');
const subprocess = execa('noop');

process.kill(cp.pid);
process.kill(subprocess.pid);

const {exitCode} = await t.throwsAsync(cp);
const {exitCode} = await t.throwsAsync(subprocess);
t.is(exitCode, undefined);
});
}
Expand Down
12 changes: 6 additions & 6 deletions test/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ test('spawnAndKill cleanup detached SIGKILL', spawnAndKill, 'SIGKILL', true, tru
// See #128
test('removes exit handler on exit', async t => {
// FIXME: This relies on `signal-exit` internals
const ee = process.__signal_exit_emitter__;
const emitter = process.__signal_exit_emitter__;

const child = execa('noop');
const listener = ee.listeners('exit').pop();
const subprocess = execa('noop');
const listener = emitter.listeners('exit').pop();

await new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', resolve);
subprocess.on('error', reject);
subprocess.on('exit', resolve);
});

const included = ee.listeners('exit').includes(listener);
const included = emitter.listeners('exit').includes(listener);
t.false(included);
});

Expand Down
44 changes: 22 additions & 22 deletions test/stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs';
import stream from 'stream';
import Stream from 'stream';
import test from 'ava';
import getStream from 'get-stream';
import tempfile from 'tempfile';
Expand Down Expand Up @@ -61,17 +61,17 @@ test('input option can be a Buffer', async t => {
});

test('input can be a Stream', async t => {
const s = new stream.PassThrough();
s.write('howdy');
s.end();
const {stdout} = await execa('stdin', {input: s});
const stream = new Stream.PassThrough();
stream.write('howdy');
stream.end();
const {stdout} = await execa('stdin', {input: stream});
t.is(stdout, 'howdy');
});

test('you can write to child.stdin', async t => {
const child = execa('stdin');
child.stdin.end('unicorns');
t.is((await child).stdout, 'unicorns');
const subprocess = execa('stdin');
subprocess.stdin.end('unicorns');
t.is((await subprocess).stdout, 'unicorns');
});

test('input option can be a String - sync', t => {
Expand All @@ -95,7 +95,7 @@ test('opts.stdout:ignore - stdout will not collect data', async t => {
test('helpful error trying to provide an input stream in sync mode', t => {
t.throws(
() => {
execa.sync('stdin', {input: new stream.PassThrough()});
execa.sync('stdin', {input: new Stream.PassThrough()});
},
/The `input` option cannot be a stream in sync mode/
);
Expand Down Expand Up @@ -152,21 +152,21 @@ test('buffer: false > promise resolves when output is big but is not pipable', a
});

test('buffer: false > promise resolves when output is big and is read', async t => {
const cp = execa('max-buffer', {buffer: false});
cp.stdout.resume();
cp.stderr.resume();
await t.notThrowsAsync(cp);
const subprocess = execa('max-buffer', {buffer: false});
subprocess.stdout.resume();
subprocess.stderr.resume();
await t.notThrowsAsync(subprocess);
});

test('buffer: false > promise resolves when output is big and "all" is used and is read', async t => {
const cp = execa('max-buffer', {buffer: false, all: true});
cp.all.resume();
await t.notThrowsAsync(cp);
const subprocess = execa('max-buffer', {buffer: false, all: true});
subprocess.all.resume();
await t.notThrowsAsync(subprocess);
});

test('buffer: false > promise rejects when process returns non-zero', async t => {
const cp = execa('fail', {buffer: false});
const {exitCode} = await t.throwsAsync(cp);
const subprocess = execa('fail', {buffer: false});
const {exitCode} = await t.throwsAsync(subprocess);
t.is(exitCode, 2);
});

Expand All @@ -180,10 +180,10 @@ if (process.platform !== 'win32') {
});

test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => {
const cp = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});
cp.stdout.resume();
cp.stderr.resume();
const {timedOut} = await t.throwsAsync(cp);
const subprocess = execa('max-buffer', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});
subprocess.stdout.resume();
subprocess.stderr.resume();
const {timedOut} = await t.throwsAsync(subprocess);
t.true(timedOut);
});
}
36 changes: 18 additions & 18 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ test('execPath option', async t => {
});

test('stdin errors are handled', async t => {
const child = execa('noop');
child.stdin.emit('error', new Error('test'));
await t.throwsAsync(child, /test/);
const subprocess = execa('noop');
subprocess.stdin.emit('error', new Error('test'));
await t.throwsAsync(subprocess, /test/);
});

test('child process errors are handled', async t => {
const child = execa('noop');
child.emit('error', new Error('test'));
await t.throwsAsync(child, /test/);
const subprocess = execa('noop');
subprocess.emit('error', new Error('test'));
await t.throwsAsync(subprocess, /test/);
});

test('child process errors rejects promise right away', async t => {
const child = execa('noop');
child.emit('error', new Error('test'));
await t.throwsAsync(child, /test/);
const subprocess = execa('noop');
subprocess.emit('error', new Error('test'));
await t.throwsAsync(subprocess, /test/);
});

test('execa() returns a promise with pid', t => {
Expand All @@ -123,11 +123,11 @@ test('execa() returns a promise with pid', t => {
});

test('child_process.spawn() propagated errors have correct shape', t => {
const cp = execa('noop', {uid: -1});
const subprocess = execa('noop', {uid: -1});
t.notThrows(() => {
cp.catch(() => {});
cp.unref();
cp.on('error', () => {});
subprocess.catch(() => {});
subprocess.unref();
subprocess.on('error', () => {});
});
});

Expand All @@ -144,9 +144,9 @@ test('child_process.spawnSync() errors are propagated with a correct shape', t =
});

test('do not try to consume streams twice', async t => {
const cp = execa('noop', ['foo']);
t.is((await cp).stdout, 'foo');
t.is((await cp).stdout, 'foo');
const subprocess = execa('noop', ['foo']);
t.is((await subprocess).stdout, 'foo');
t.is((await subprocess).stdout, 'foo');
});

test('use relative path with \'..\' chars', async t => {
Expand All @@ -157,8 +157,8 @@ test('use relative path with \'..\' chars', async t => {

if (process.platform !== 'win32') {
test('execa() rejects if running non-executable', async t => {
const cp = execa('non-executable');
await t.throwsAsync(cp);
const subprocess = execa('non-executable');
await t.throwsAsync(subprocess);
});

test('execa() rejects with correct error and doesn\'t throw if running non-executable with input', async t => {
Expand Down

0 comments on commit 7dbd562

Please sign in to comment.