Do not prevent process normal exit (#809)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 8ff263c · Browse files · 11 files·+201 added−143 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+201 added−143 removed
- tests:+172 added−126 removed
- other:+29 added−17 removed
Provenance
- Commit
7ddf0a0- Tree
9be7fb9- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
8ff263c
11 files changed+201 added−143 removed
modified:lib/error.js+1 added-1 removed
104 unmodified linesExpand all10510610710810910911011111211340 unmodified lines104 unmodified linesExpand all error.escapedCommand = escapedCommand; error.cwd = cwd;
error.failed = true; error.timedOut = Boolean(timedOut); error.timedOut = timedOut; error.isCanceled = isCanceled; error.isTerminated = signal !== undefined; error.exitCode = exitCode; error.signal = signal;40 unmodified linesmodified:lib/kill.js+4 added-3 removed
61 unmodified lines62 63 const isProcessErrorExit = (exitCode, signal) => exitCode === undefined && signal === undefined;64 export const isFailedExit = (exitCode, signal) => exitCode !== 0 || signal !== null;65 66-const killAfterTimeout = async (timeout, context, {signal}) => {66+const killAfterTimeout = async (spawned, timeout, context, {signal}) => {67 await setTimeout(timeout, undefined, {signal});68 context.timedOut = true;69+ spawned.kill();70 const message = getErrorPrefix({timedOut: true, timeout});71 throw setDiscardedError(new Error(message));72 };73 74 // `timeout` option handling74-export const throwOnTimeout = (timeout, context, controller) => timeout === 0 || timeout === undefined75+export const throwOnTimeout = (spawned, timeout, context, controller) => timeout === 0 || timeout === undefined76 ? []76- : [killAfterTimeout(timeout, context, controller)];77+ : [killAfterTimeout(spawned, timeout, context, controller)];78 79 export const validateTimeout = ({timeout}) => {80 if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {81 throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);19 unmodified linesmodified:lib/stream.js+24 added-12 removed
1 import {once} from 'node:events';2 import {finished} from 'node:stream/promises';3 import {setImmediate} from 'node:timers/promises';4-import getStream, {getStreamAsArrayBuffer, getStreamAsArray} from 'get-stream';4+import getStream, {getStreamAsArrayBuffer, getStreamAsArray, MaxBufferError} from 'get-stream';5 import mergeStreams from '@sindresorhus/merge-streams';6 import {waitForSuccessfulExit, throwOnTimeout} from './kill.js';7 import {isStandardStream} from './stdio/utils.js';8 import {generatorToDuplexStream} from './stdio/generator.js';4 unmodified lines13 : undefined;14 15 // On failure, `result.stdout|stderr|all` should contain the currently buffered stream16 // They are automatically closed and flushed by Node.js when the child process exits17-// We guarantee this by calling `childProcess.kill()`17 // When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve18 const getBufferedData = async (streamPromise, encoding) => {19 try {20 return await streamPromise;6 unmodified lines27 28 // Read the contents of `childProcess.std*` and|or wait for its completion29 const waitForChildStreams = ({spawned, stdioStreamsGroups, encoding, buffer, maxBuffer, waitForStream}) => spawned.stdio.map((stream, index) => waitForChildStream({30 stream,31+ spawned,32 direction: stdioStreamsGroups[index][0].direction,33 encoding,34 buffer,35 maxBuffer,2 unmodified lines38 39 // Read the contents of `childProcess.all` and|or wait for its completion40 const waitForAllStream = ({spawned, encoding, buffer, maxBuffer, waitForStream}) => waitForChildStream({41 stream: getAllStream(spawned, encoding),42+ spawned,43 direction: 'output',44 encoding,45 buffer,46 maxBuffer: maxBuffer * 2,16 unmodified lines63 writableObjectMode: true,64 readableObjectMode: true,65 };66 66-const waitForChildStream = async ({stream, direction, encoding, buffer, maxBuffer, waitForStream}) => {67+const waitForChildStream = async ({stream, spawned, direction, encoding, buffer, maxBuffer, waitForStream}) => {68 if (!stream) {69 return;70 }71 9 unmodified lines81 ]);82 return;83 }84 84- if (stream.readableObjectMode) {85- return getStreamAsArray(stream, {maxBuffer});86- }85+ try {86+ return await getAnyStream(stream, encoding, maxBuffer);87+ } catch (error) {88+ if (error instanceof MaxBufferError) {89+ spawned.kill();90+ }91 88- const contents = encoding === 'buffer'89- ? await getStreamAsArrayBuffer(stream, {maxBuffer})90- : await getStream(stream, {maxBuffer});91- return applyEncoding(contents, encoding);92+ throw error;93+ }94 };95 96 // When using `buffer: false`, users need to read `childProcess.stdout|stderr|all` right away97 // See https://github.com/sindresorhus/execa/issues/730 and https://github.com/sindresorhus/execa/pull/729#discussion_r14654963103 unmodified lines101 stream.resume();102 }103 };104 105+const getAnyStream = async (stream, encoding, maxBuffer) => {106+ if (stream.readableObjectMode) {107+ return getStreamAsArray(stream, {maxBuffer});108+ }109+110+ const contents = encoding === 'buffer'111+ ? await getStreamAsArrayBuffer(stream, {maxBuffer})112+ : await getStream(stream, {maxBuffer});113+ return applyEncoding(contents, encoding);114+};115+116 const applyEncoding = (contents, encoding) => encoding === 'buffer' ? new Uint8Array(contents) : contents;117 118 // Transforms replace `childProcess.std*`, which means they are not exposed to users.119 // However, we still want to wait for their completion.80 unmodified lines200 ...originalPromises,201 ...customStreamsEndPromises,202 ]),203 throwOnProcessError(spawned, controller),191- ...throwOnTimeout(timeout, context, controller),204+ ...throwOnTimeout(spawned, timeout, context, controller),205 ]);206 } catch (error) {194- spawned.kill();207 return Promise.all([208 {error},209 exitPromise,210 Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise, encoding))),6 unmodified linesmodified:test/stdio/array.js+1 added
262 unmodified lines263 const testDestroyStandardStream = async (t, index) => {264 const childProcess = execa('forever.js', getStdio(index, [STANDARD_STREAMS[index], 'pipe']));265 const error = new Error('test');266 childProcess.stdio[index].destroy(error);267+ childProcess.kill();268 const thrownError = await t.throwsAsync(childProcess);269 t.is(thrownError, error);270 t.false(STANDARD_STREAMS[index].destroyed);271 };4 unmodified linesmodified:test/stdio/file-path.js+12 added-12 removed
137 unmodified lines138 test('stdout be an object when it is a file path string - sync', testFilePathObject, 1, execaSync);139 test('stderr be an object when it is a file path string - sync', testFilePathObject, 2, execaSync);140 test('stdio[*] must be an object when it is a file path string - sync', testFilePathObject, 3, execaSync);141 142-const testFileError = async (t, mapFile, index) => {142+const testFileError = async (t, fixtureName, mapFile, index) => {143 await t.throwsAsync(144- execa('forever.js', getStdio(index, mapFile('./unknown/file'))),144+ execa(fixtureName, [`${index}`], getStdio(index, mapFile('./unknown/file'))),145 {code: 'ENOENT'},146 );147 };148 149-test('inputFile file URL errors should be handled', testFileError, pathToFileURL, 'inputFile');150-test('stdin file URL errors should be handled', testFileError, pathToFileURL, 0);151-test('stdout file URL errors should be handled', testFileError, pathToFileURL, 1);152-test('stderr file URL errors should be handled', testFileError, pathToFileURL, 2);153-test('stdio[*] file URL errors should be handled', testFileError, pathToFileURL, 3);154-test('inputFile file path errors should be handled', testFileError, identity, 'inputFile');155-test('stdin file path errors should be handled', testFileError, getAbsolutePath, 0);156-test('stdout file path errors should be handled', testFileError, getAbsolutePath, 1);157-test('stderr file path errors should be handled', testFileError, getAbsolutePath, 2);158-test('stdio[*] file path errors should be handled', testFileError, getAbsolutePath, 3);149+test.serial('inputFile file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 'inputFile');150+test.serial('stdin file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 0);151+test.serial('stdout file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 1);152+test.serial('stderr file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 2);153+test.serial('stdio[*] file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 3);154+test.serial('inputFile file path errors should be handled', testFileError, 'stdin-fd.js', identity, 'inputFile');155+test.serial('stdin file path errors should be handled', testFileError, 'stdin-fd.js', getAbsolutePath, 0);156+test.serial('stdout file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 1);157+test.serial('stderr file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 2);158+test.serial('stdio[*] file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 3);159 160 const testFileErrorSync = (t, mapFile, index) => {161 t.throws(() => {162 execaSync('empty.js', getStdio(index, mapFile('./unknown/file')));51 unmodified linesmodified:test/stdio/generator.js+1 added
717 unmodified lines718 const testGeneratorDestroy = async (t, transform) => {719 const childProcess = execa('forever.js', {stdout: transform});720 const error = new Error('test');721 childProcess.stdout.destroy(error);722+ childProcess.kill();723 t.is(await t.throwsAsync(childProcess), error);724 };725 726 test('Generators are destroyed on process error, sync', testGeneratorDestroy, noopGenerator(false));5 unmodified linesmodified:test/stdio/iterable.js+8 added-8 removed
32 unmodified lines33 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, stdioOption));34 t.is(stdout, 'foobar');35 };36 37-test('stdin option can be an array of strings', testIterable, [stringArray], 0);38-test('stdio[*] option can be an array of strings', testIterable, [stringArray], 3);39-test('stdin option can be an array of Uint8Arrays', testIterable, [binaryArray], 0);40-test('stdio[*] option can be an array of Uint8Arrays', testIterable, [binaryArray], 3);41-test('stdin option can be an iterable of strings', testIterable, stringGenerator(), 0);42-test('stdio[*] option can be an iterable of strings', testIterable, stringGenerator(), 3);43-test('stdin option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 0);44-test('stdio[*] option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 3);37+test.serial('stdin option can be an array of strings', testIterable, [stringArray], 0);38+test.serial('stdio[*] option can be an array of strings', testIterable, [stringArray], 3);39+test.serial('stdin option can be an array of Uint8Arrays', testIterable, [binaryArray], 0);40+test.serial('stdio[*] option can be an array of Uint8Arrays', testIterable, [binaryArray], 3);41+test.serial('stdin option can be an iterable of strings', testIterable, stringGenerator(), 0);42+test.serial('stdio[*] option can be an iterable of strings', testIterable, stringGenerator(), 3);43+test.serial('stdin option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 0);44+test.serial('stdio[*] option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 3);45 test.serial('stdin option can be an async iterable', testIterable, asyncGenerator(), 0);46 test.serial('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3);47 48 const foobarObjectGenerator = function * () {84 unmodified linesmodified:test/stdio/node-stream.js+49 added-39 removed
179 unmodified lines180 test('Can pass Duplex streams to stdout', testOutputDuplexStream, 1);181 test('Can pass Duplex streams to stderr', testOutputDuplexStream, 2);182 test('Can pass Duplex streams to output stdio[*]', testOutputDuplexStream, 3);183 184+const assertStreamError = (t, {exitCode, signal, isTerminated, failed}) => {185+ t.is(exitCode, 0);186+ t.is(signal, undefined);187+ t.false(isTerminated);188+ t.true(failed);189+};190+191+const getStreamFixtureName = index => index === 0 ? 'stdin.js' : 'noop.js';192+193 test('Handles output streams ends', async t => {194 const stream = noopWritable();195+ const childProcess = execa('stdin.js', {stdout: [stream, 'pipe']});196 stream.end();187- await t.throwsAsync(188- execa('forever.js', {stdout: [stream, 'pipe']}),189- {code: 'ERR_STREAM_PREMATURE_CLOSE'},190- );197+ childProcess.stdin.end();198+ const error = await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});199+ assertStreamError(t, error);200 });201 193-const testStreamAbort = async (t, stream, streamName) => {202+const testStreamAbort = async (t, stream, index) => {203+ const childProcess = execa(getStreamFixtureName(index), getStdio(index, [stream, 'pipe']));204 stream.destroy();195- await t.throwsAsync(196- execa('forever.js', {[streamName]: [stream, 'pipe']}),197- {code: 'ERR_STREAM_PREMATURE_CLOSE'},198- );205+ const error = await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});206+ assertStreamError(t, error);207 };208 201-test('Handles input streams aborts', testStreamAbort, noopReadable(), 'stdin');202-test('Handles input Duplex streams aborts', testStreamAbort, noopDuplex(), 'stdin');203-test('Handles output streams aborts', testStreamAbort, noopWritable(), 'stdout');204-test('Handles output Duplex streams aborts', testStreamAbort, noopDuplex(), 'stdout');209+test('Handles input streams aborts', testStreamAbort, noopReadable(), 0);210+test('Handles input Duplex streams aborts', testStreamAbort, noopDuplex(), 0);211+test('Handles output streams aborts', testStreamAbort, noopWritable(), 1);212+test('Handles output Duplex streams aborts', testStreamAbort, noopDuplex(), 1);213 206-const testStreamError = async (t, stream, streamName) => {214+const testStreamError = async (t, stream, index) => {215+ const childProcess = execa(getStreamFixtureName(index), getStdio(index, [stream, 'pipe']));216 const error = new Error('test');217 stream.destroy(error);209- t.is(210- await t.throwsAsync(execa('forever.js', {[streamName]: [stream, 'pipe']})),211- error,212- );218+ t.is(await t.throwsAsync(childProcess), error);219+ assertStreamError(t, error);220 };221 215-test('Handles input streams errors', testStreamError, noopReadable(), 'stdin');216-test('Handles input Duplex streams errors', testStreamError, noopDuplex(), 'stdin');217-test('Handles output streams errors', testStreamError, noopWritable(), 'stdout');218-test('Handles output Duplex streams errors', testStreamError, noopDuplex(), 'stdout');222+test('Handles input streams errors', testStreamError, noopReadable(), 0);223+test('Handles input Duplex streams errors', testStreamError, noopDuplex(), 0);224+test('Handles output streams errors', testStreamError, noopWritable(), 1);225+test('Handles output Duplex streams errors', testStreamError, noopDuplex(), 1);226 227 const testChildStreamEnd = async (t, stream) => {221- const childProcess = execa('forever.js', {stdin: [stream, 'pipe']});228+ const childProcess = execa('stdin.js', {stdin: [stream, 'pipe']});229 childProcess.stdin.end();223- await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});230+ const error = await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});231+ assertStreamError(t, error);232 t.true(stream.destroyed);233 };234 235 test('Handles childProcess.stdin end', testChildStreamEnd, noopReadable());236 test('Handles childProcess.stdin Duplex end', testChildStreamEnd, noopDuplex());237 230-const testChildStreamAbort = async (t, stream, streamName) => {231- const childProcess = execa('forever.js', {[streamName]: [stream, 'pipe']});232- childProcess[streamName].destroy();233- await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});238+const testChildStreamAbort = async (t, stream, index) => {239+ const childProcess = execa(getStreamFixtureName(index), getStdio(index, [stream, 'pipe']));240+ childProcess.stdio[index].destroy();241+ const error = await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});242+ assertStreamError(t, error);243 t.true(stream.destroyed);244 };245 237-test('Handles childProcess.stdin aborts', testChildStreamAbort, noopReadable(), 'stdin');238-test('Handles childProcess.stdin Duplex aborts', testChildStreamAbort, noopDuplex(), 'stdin');239-test('Handles childProcess.stdout aborts', testChildStreamAbort, noopWritable(), 'stdout');240-test('Handles childProcess.stdout Duplex aborts', testChildStreamAbort, noopDuplex(), 'stdout');246+test('Handles childProcess.stdin aborts', testChildStreamAbort, noopReadable(), 0);247+test('Handles childProcess.stdin Duplex aborts', testChildStreamAbort, noopDuplex(), 0);248+test('Handles childProcess.stdout aborts', testChildStreamAbort, noopWritable(), 1);249+test('Handles childProcess.stdout Duplex aborts', testChildStreamAbort, noopDuplex(), 1);250 242-const testChildStreamError = async (t, stream, streamName) => {243- const childProcess = execa('forever.js', {[streamName]: [stream, 'pipe']});251+const testChildStreamError = async (t, stream, index) => {252+ const childProcess = execa(getStreamFixtureName(index), getStdio(index, [stream, 'pipe']));253 const error = new Error('test');245- childProcess[streamName].destroy(error);254+ childProcess.stdio[index].destroy(error);255 t.is(await t.throwsAsync(childProcess), error);256+ assertStreamError(t, error);257 t.true(stream.destroyed);258 };259 250-test('Handles childProcess.stdin errors', testChildStreamError, noopReadable(), 'stdin');251-test('Handles childProcess.stdin Duplex errors', testChildStreamError, noopDuplex(), 'stdin');252-test('Handles childProcess.stdout errors', testChildStreamError, noopWritable(), 'stdout');253-test('Handles childProcess.stdout Duplex errors', testChildStreamError, noopDuplex(), 'stdout');260+test('Handles childProcess.stdin errors', testChildStreamError, noopReadable(), 0);261+test('Handles childProcess.stdin Duplex errors', testChildStreamError, noopDuplex(), 0);262+test('Handles childProcess.stdout errors', testChildStreamError, noopWritable(), 1);263+test('Handles childProcess.stdout Duplex errors', testChildStreamError, noopDuplex(), 1);modified:test/kill.js+11 added-18 removed
117 unmodified lines118 t.true(isTerminated);119 t.is(signal, 'SIGKILL');120 });121 122- test('`forceKillAfterDelay` works with "error" events on childProcess', async t => {123- const subprocess = spawnNoKillableSimple();124- await once(subprocess, 'spawn');125- subprocess.emit('error', new Error('test'));126- const {isTerminated, signal} = await t.throwsAsync(subprocess);127- t.true(isTerminated);128- t.is(signal, 'SIGKILL');129- });130-131- test('`forceKillAfterDelay` works with "error" events on childProcess.stdout', async t => {132- const subprocess = spawnNoKillableSimple();133- await once(subprocess, 'spawn');134- subprocess.stdout.destroy(new Error('test'));135- const {isTerminated, signal} = await t.throwsAsync(subprocess);136- t.true(isTerminated);137- t.is(signal, 'SIGKILL');138- });139-122 test.serial('Can call `.kill()` with `forceKillAfterDelay` many times without triggering the maxListeners warning', async t => {123 let warning;124 const captureWarning = warningArgument => {125 warning = warningArgument;102 unmodified lines228 const {timedOut} = execaSync('noop.js');229 t.false(timedOut);230 });231 232+test('timedOut is true if the timeout happened after a different error occurred', async t => {233+ const childProcess = execa('forever.js', {timeout: 1e3});234+ const error = new Error('test');235+ childProcess.emit('error', error);236+ t.is(await t.throwsAsync(childProcess), error);237+ t.true(error.timedOut);238+});239+240 // When child process exits before parent process241 const spawnAndExit = async (t, cleanup, detached) => {242 await t.notThrowsAsync(execa('nested.js', [JSON.stringify({cleanup, detached}), 'noop.js']));243 };137 unmodified lines381 test('child process errors are handled before spawn', async t => {382 const subprocess = execa('forever.js');383 const error = new Error('test');384 subprocess.emit('error', error);385+ subprocess.kill();386 const thrownError = await t.throwsAsync(subprocess);387 t.is(thrownError, error);388 t.is(thrownError.exitCode, undefined);389 t.is(thrownError.signal, undefined);4 unmodified lines394 const subprocess = execa('forever.js');395 await once(subprocess, 'spawn');396 const error = new Error('test');397 subprocess.emit('error', error);398+ subprocess.kill();399 const thrownError = await t.throwsAsync(subprocess);400 t.is(thrownError, error);401 t.is(thrownError.exitCode, undefined);402 t.is(thrownError.signal, 'SIGTERM');19 unmodified lines422 const subprocess = execa('forever.js', {killSignal: 'SIGINT'});423 await once(subprocess, 'spawn');424 const error = new Error('test');425 subprocess.emit('error', error);426+ subprocess.kill();427 const thrownError = await t.throwsAsync(subprocess);428 t.is(thrownError, error);429 t.true(thrownError.isTerminated);430 t.is(thrownError.signal, 'SIGINT');1 unmodified linemodified:test/stream.js+90 added-49 removed
1 import {Buffer} from 'node:buffer';2 import {once} from 'node:events';3+import {platform} from 'node:process';4 import {getDefaultHighWaterMark} from 'node:stream';5 import {setTimeout} from 'node:timers/promises';6 import test from 'ava';7 import getStream from 'get-stream';92 unmodified lines100 t.is(allOutput, '');101 }102 };103 103-test.serial('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);104-test.serial('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);105-test.serial('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);106-test.serial('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);104+test('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);105+test('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);106+test('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);107+test('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);108 109 // eslint-disable-next-line max-params110 const testIterationBuffer = async (t, index, buffer, useDataEvents, all) => {111 const subprocess = execa('noop-fd.js', [`${index}`, foobarString], {...fullStdio, buffer, all});199 unmodified lines311 test('Process buffers stderr, which does not prevent exit if read and buffer is false', testBufferRead, 2, false);312 test('Process buffers stdio[*], which does not prevent exit if read and buffer is false', testBufferRead, 3, false);313 test('Process buffers all, which does not prevent exit if read and buffer is false', testBufferRead, 1, true);314 314-const getStreamDestroyOptions = (index, isInput) => {315+const getStreamInputProcess = index => execa('stdin-fd.js', [`${index}`], index === 3316+ ? getStdio(3, [new Uint8Array(), infiniteGenerator])317+ : {});318+const getStreamOutputProcess = index => execa('max-buffer.js', [`${index}`], index === 3 ? fullStdio : {});319+320+const assertStreamInputError = (t, {exitCode, signal, isTerminated, failed}) => {321+ t.is(exitCode, 0);322+ t.is(signal, undefined);323+ t.false(isTerminated);324+ t.true(failed);325+};326+327+const assertStreamOutputError = (t, index, {exitCode, signal, isTerminated, failed, stderr}) => {328 if (index !== 3) {316- return {};329+ t.is(exitCode, 1);330 }331 319- return getStdio(3, isInput ? [new Uint8Array(), infiniteGenerator] : 'pipe');332+ t.is(signal, undefined);333+ t.false(isTerminated);334+ t.true(failed);335+336+ if (index === 1 && platform !== 'win32') {337+ t.true(stderr.includes('EPIPE'));338+ }339 };340 322-const testStreamAbort = async (t, index, isInput) => {323- const childProcess = execa('forever.js', getStreamDestroyOptions(index, isInput));341+const testStreamInputAbort = async (t, index) => {342+ const childProcess = getStreamInputProcess(index);343 childProcess.stdio[index].destroy();325- await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});344+ const error = await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});345+ assertStreamInputError(t, error);346 };347 328-test('Aborting stdin should make the process exit', testStreamAbort, 0, true);329-test('Aborting stdout should make the process exit', testStreamAbort, 1, false);330-test('Aborting stderr should make the process exit', testStreamAbort, 2, false);331-test('Aborting output stdio[*] should make the process exit', testStreamAbort, 3, false);332-test('Aborting input stdio[*] should make the process exit', testStreamAbort, 3, true);348+test('Aborting stdin should not make the process exit', testStreamInputAbort, 0);349+test('Aborting input stdio[*] should not make the process exit', testStreamInputAbort, 3);350 334-const testStreamDestroy = async (t, index, isInput) => {335- const childProcess = execa('forever.js', getStreamDestroyOptions(index, isInput));351+const testStreamOutputAbort = async (t, index) => {352+ const childProcess = getStreamOutputProcess(index);353+ childProcess.stdio[index].destroy();354+ const error = await t.throwsAsync(childProcess);355+ assertStreamOutputError(t, index, error);356+};357+358+test('Aborting stdout should not make the process exit', testStreamOutputAbort, 1);359+test('Aborting stderr should not make the process exit', testStreamOutputAbort, 2);360+test('Aborting output stdio[*] should not make the process exit', testStreamOutputAbort, 3);361+362+const testStreamInputDestroy = async (t, index) => {363+ const childProcess = getStreamInputProcess(index);364 const error = new Error('test');365 childProcess.stdio[index].destroy(error);366 t.is(await t.throwsAsync(childProcess), error);367+ assertStreamInputError(t, error);368 };369 341-test('Destroying stdin should make the process exit', testStreamDestroy, 0, true);342-test('Destroying stdout should make the process exit', testStreamDestroy, 1, false);343-test('Destroying stderr should make the process exit', testStreamDestroy, 2, false);344-test('Destroying output stdio[*] should make the process exit', testStreamDestroy, 3, false);345-test('Destroying input stdio[*] should make the process exit', testStreamDestroy, 3, true);370+test('Destroying stdin should not make the process exit', testStreamInputDestroy, 0);371+test('Destroying input stdio[*] should not make the process exit', testStreamInputDestroy, 3);372 347-const testStreamError = async (t, index, isInput) => {348- const childProcess = execa('forever.js', getStreamDestroyOptions(index, isInput));373+const testStreamOutputDestroy = async (t, index) => {374+ const childProcess = getStreamOutputProcess(index);375 const error = new Error('test');350- childProcess.stdio[index].emit('error', error);376+ childProcess.stdio[index].destroy(error);377 t.is(await t.throwsAsync(childProcess), error);378+ assertStreamOutputError(t, index, error);379 };380 354-test('Errors on stdin should make the process exit', testStreamError, 0, true);355-test('Errors on stdout should make the process exit', testStreamError, 1, false);356-test('Errors on stderr should make the process exit', testStreamError, 2, false);357-test('Errors on output stdio[*] should make the process exit', testStreamError, 3, false);358-test('Errors on input stdio[*] should make the process exit', testStreamError, 3, true);381+test('Destroying stdout should not make the process exit', testStreamOutputDestroy, 1);382+test('Destroying stderr should not make the process exit', testStreamOutputDestroy, 2);383+test('Destroying output stdio[*] should not make the process exit', testStreamOutputDestroy, 3);384 360-test('Errors on streams use killSignal', async t => {361- const childProcess = execa('forever.js', {killSignal: 'SIGINT'});385+const testStreamInputError = async (t, index) => {386+ const childProcess = getStreamInputProcess(index);387 const error = new Error('test');363- childProcess.stdout.destroy(error);364- const thrownError = await t.throwsAsync(childProcess);365- t.is(thrownError, error);366- t.true(error.isTerminated);367- t.is(error.signal, 'SIGINT');368-});388+ const stream = childProcess.stdio[index];389+ stream.emit('error', error);390+ stream.end();391+ t.is(await t.throwsAsync(childProcess), error);392+ assertStreamInputError(t, error);393+};394 395+test('Errors on stdin should not make the process exit', testStreamInputError, 0);396+test('Errors on input stdio[*] should not make the process exit', testStreamInputError, 3);397+398+const testStreamOutputError = async (t, index) => {399+ const childProcess = getStreamOutputProcess(index);400+ const error = new Error('test');401+ const stream = childProcess.stdio[index];402+ stream.emit('error', error);403+ t.is(await t.throwsAsync(childProcess), error);404+ assertStreamOutputError(t, index, error);405+};406+407+test('Errors on stdout should not make the process exit', testStreamOutputError, 1);408+test('Errors on stderr should not make the process exit', testStreamOutputError, 2);409+test('Errors on output stdio[*] should not make the process exit', testStreamOutputError, 3);410+411 const testWaitOnStreamEnd = async (t, index) => {412 const childProcess = execa('stdin-fd.js', [`${index}`], fullStdio);413 await setTimeout(100);414 childProcess.stdio[index].end('foobar');415 const {stdout} = await childProcess;416 t.is(stdout, 'foobar');417 };418 378-test.serial('Process waits on stdin before exiting', testWaitOnStreamEnd, 0);379-test.serial('Process waits on stdio[*] before exiting', testWaitOnStreamEnd, 3);419+test('Process waits on stdin before exiting', testWaitOnStreamEnd, 0);420+test('Process waits on stdio[*] before exiting', testWaitOnStreamEnd, 3);421 422 const testBufferExit = async (t, index, fixtureName, reject) => {423 const childProcess = execa(fixtureName, [`${index}`], {...fullStdio, reject});424 await setTimeout(100);425 const {stdio} = await childProcess;426 t.is(stdio[index], 'foobar');427 };428 388-test.serial('Process buffers stdout before it is read', testBufferExit, 1, 'noop-delay.js', true);389-test.serial('Process buffers stderr before it is read', testBufferExit, 2, 'noop-delay.js', true);390-test.serial('Process buffers stdio[*] before it is read', testBufferExit, 3, 'noop-delay.js', true);391-test.serial('Process buffers stdout right away, on successfully exit', testBufferExit, 1, 'noop-fd.js', true);392-test.serial('Process buffers stderr right away, on successfully exit', testBufferExit, 2, 'noop-fd.js', true);393-test.serial('Process buffers stdio[*] right away, on successfully exit', testBufferExit, 3, 'noop-fd.js', true);394-test.serial('Process buffers stdout right away, on failure', testBufferExit, 1, 'noop-fail.js', false);395-test.serial('Process buffers stderr right away, on failure', testBufferExit, 2, 'noop-fail.js', false);396-test.serial('Process buffers stdio[*] right away, on failure', testBufferExit, 3, 'noop-fail.js', false);429+test('Process buffers stdout before it is read', testBufferExit, 1, 'noop-delay.js', true);430+test('Process buffers stderr before it is read', testBufferExit, 2, 'noop-delay.js', true);431+test('Process buffers stdio[*] before it is read', testBufferExit, 3, 'noop-delay.js', true);432+test('Process buffers stdout right away, on successfully exit', testBufferExit, 1, 'noop-fd.js', true);433+test('Process buffers stderr right away, on successfully exit', testBufferExit, 2, 'noop-fd.js', true);434+test('Process buffers stdio[*] right away, on successfully exit', testBufferExit, 3, 'noop-fd.js', true);435+test('Process buffers stdout right away, on failure', testBufferExit, 1, 'noop-fail.js', false);436+test('Process buffers stderr right away, on failure', testBufferExit, 2, 'noop-fail.js', false);437+test('Process buffers stdio[*] right away, on failure', testBufferExit, 3, 'noop-fail.js', false);438 439 const testBufferDirect = async (t, index) => {440 const childProcess = execa('noop-fd.js', [`${index}`], fullStdio);441 const data = await once(childProcess.stdio[index], 'data');29 unmodified linesmodified:package.json-1 removed
78 unmodified lines79 ]80 },81 "ava": {82 "workerThreads": false,83- "concurrency": 1,83 "timeout": "60s"84 },85 "xo": {86 "rules": {5 unmodified lines