Skip to content
Myr

Handle stream errors even with `buffer: false` (#729)

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

authored by ehmicky · committed by GitHub · parent 1907e7c · Browse files · 2 files+41 added−6 removed
This commit

State

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

Diff stats

2 files+41 added−6 removed

  • tests:+18 added−5 removed
  • other:+23 added−1 removed

2 files+41 added−6 removed

modified:lib/stream.js+23 added-1 removed
modified:test/stream.js+18 added-5 removed
122 unmodified lines
123test('Can listen to `data` events on stderr when `buffer` set to `true`', testIterationBuffer, 2, true, true, false);124test('Can listen to `data` events on stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, true, false);125test('Can listen to `data` events on all when `buffer` set to `true`', testIterationBuffer, 1, true, true, true);126127const testNoBufferStreamError = async (t, index, all) => {128 const subprocess = execa('noop-fd.js', [`${index}`], {...fullStdio, buffer: false, all});129 const stream = all ? subprocess.all : subprocess.stdio[index];130 stream.destroy(new Error('test'));131 await t.throwsAsync(subprocess, {message: /test/});132};133134test('Listen to stdout errors even when `buffer` is `false`', testNoBufferStreamError, 1, false);135test('Listen to stderr errors even when `buffer` is `false`', testNoBufferStreamError, 2, false);136test('Listen to stdio[*] errors even when `buffer` is `false`', testNoBufferStreamError, 3, false);137test('Listen to all errors even when `buffer` is `false`', testNoBufferStreamError, 1, true);138139const maxBuffer = 10;140141const testMaxBufferSuccess = async (t, index, all) => {142 await t.notThrowsAsync(execa('max-buffer.js', [`${index}`, `${maxBuffer}`], {...fullStdio, maxBuffer, all}));
128 unmodified lines
271// This specific behavior does not happen on Windows.272// Also, on macOS, it randomly happens, which would make those tests randomly fail.273if (process.platform === 'linux') {274 const testBufferNotRead = async (t, index, all) => {263 const {timedOut} = await t.throwsAsync(execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all, timeout: 1e3}));275 const subprocess = execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all, timeout: 1e3});276 const {timedOut} = await t.throwsAsync(subprocess);277 t.true(timedOut);278 };279267 test.serial('Process buffers stdout, which prevents exit if not read and buffer is false', testBufferNotRead, 1, false);268 test.serial('Process buffers stderr, which prevents exit if not read and buffer is false', testBufferNotRead, 2, false);269 test.serial('Process buffers stdio[*], which prevents exit if not read and buffer is false', testBufferNotRead, 3, false);270 test.serial('Process buffers all, which prevents exit if not read and buffer is false', testBufferNotRead, 1, true);280 test('Process buffers stdout, which prevents exit if not read and buffer is false', testBufferNotRead, 1, false);281 test('Process buffers stderr, which prevents exit if not read and buffer is false', testBufferNotRead, 2, false);282 test('Process buffers stdio[*], which prevents exit if not read and buffer is false', testBufferNotRead, 3, false);283 test('Process buffers all, which prevents exit if not read and buffer is false', testBufferNotRead, 1, true);284285 const testBufferRead = async (t, index, all) => {286 const subprocess = execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all, timeout: 1e4});287 const stream = all ? subprocess.all : subprocess.stdio[index];
93 unmodified lines