Skip to content

Commit

Permalink
Make stdout|stderr properties undefined instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 14, 2019
1 parent f488c42 commit 7ca1e0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Expand Up @@ -110,8 +110,12 @@ function handleInput(spawned, input) {
}

function handleOutput(options, value) {
if (value && options.stripFinalNewline) {
value = stripFinalNewline(value);
if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
return;
}

if (options.stripFinalNewline) {
return stripFinalNewline(value);
}

return value;
Expand Down
14 changes: 14 additions & 0 deletions test.js
Expand Up @@ -51,6 +51,20 @@ test('stdout/stderr/all available on errors', async t => {
t.is(typeof error.all, 'string');
});

test('stdout/stderr/all are undefined if ignored', async t => {
const {stdout, stderr, all} = await execa('noop', {stdio: 'ignore'});
t.is(stdout, undefined);
t.is(stderr, undefined);
t.is(all, undefined);
});

test('stdout/stderr/all are undefined if ignored in sync mode', t => {
const {stdout, stderr, all} = execa.sync('noop', {stdio: 'ignore'});
t.is(stdout, undefined);
t.is(stderr, undefined);
t.is(all, undefined);
});

test('pass `stdout` to a file descriptor', async t => {
const file = tempfile('.txt');
await execa('fixtures/noop', ['foo bar'], {stdout: fs.openSync(file, 'w')});
Expand Down

0 comments on commit 7ca1e0b

Please sign in to comment.