diff --git a/lib/stream.js b/lib/stream.js index 3dcc81d07d..32bdefe9bc 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -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; } diff --git a/test/stream.js b/test/stream.js index 32c3d0c678..aeceedb0d4 100644 --- a/test/stream.js +++ b/test/stream.js @@ -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'; @@ -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})); });