Skip to content

Commit

Permalink
Emit end event on streams when process fails (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 11, 2023
1 parent 1f7677c commit 30c7a7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/stream.js
Expand Up @@ -36,7 +36,8 @@ export const makeAllStream = (spawned, {all}) => {

// On failure, `result.stdout|stderr|all` should contain the currently buffered stream
const getBufferedData = async (stream, streamPromise) => {
if (!stream) {
// When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve
if (!stream || streamPromise === undefined) {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions test/stream.js
Expand Up @@ -4,6 +4,7 @@ import fs from 'node:fs';
import Stream from 'node:stream';
import test from 'ava';
import getStream from 'get-stream';
import {pEvent} from 'p-event';
import tempfile from 'tempfile';
import {execa, execaSync} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';
Expand Down Expand Up @@ -173,6 +174,11 @@ test('buffer: false > promise rejects when process returns non-zero', async t =>
t.is(exitCode, 2);
});

test('buffer: false > emits end event when promise is rejected', async t => {
const subprocess = execa('wrong command', {buffer: false, reject: false});
await t.notThrowsAsync(Promise.all([subprocess, pEvent(subprocess.stdout, 'end')]));
});

test('can use all: true with stdout: ignore', async t => {
await t.notThrowsAsync(execa('max-buffer.js', {buffer: false, stdout: 'ignore', all: true}));
});
Expand Down

0 comments on commit 30c7a7a

Please sign in to comment.