Skip to content
Myr

Rename `index` to `fdNumber` (#862)

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

authored by ehmicky · committed by GitHub · parent 3bb0d61 · Browse files · 45 files+394 added−394 removed
This commit

State

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

Diff stats

45 files+394 added−394 removed

  • tests:+285 added−285 removed
  • other:+109 added−109 removed

45 files+394 added−394 removed

modified:lib/pipe/validate.js+22 added-22 removed
modified:lib/stdio/async.js+5 added-5 removed
47 unmodified lines
48 pipeStdioOption(spawned, nonGeneratorStream, inputStreamsGroups, controller);49 }50 }5152 for (const [index, inputStreams] of Object.entries(inputStreamsGroups)) {53 pipeStreams(inputStreams, spawned.stdio[index]);52 for (const [fdNumber, inputStreams] of Object.entries(inputStreamsGroups)) {53 pipeStreams(inputStreams, spawned.stdio[fdNumber]);54 }55};5657const pipeStdioOption = (spawned, {type, value, direction, index}, inputStreamsGroups, controller) => {57const pipeStdioOption = (spawned, {type, value, direction, fdNumber}, inputStreamsGroups, controller) => {58 if (type === 'native') {59 return;60 }6162 setStandardStreamMaxListeners(value, controller);6364 if (direction === 'output') {65 pipeStreams([spawned.stdio[index]], value);65 pipeStreams([spawned.stdio[fdNumber]], value);66 } else {67 inputStreamsGroups[index] = [...(inputStreamsGroups[index] ?? []), value];67 inputStreamsGroups[fdNumber] = [...(inputStreamsGroups[fdNumber] ?? []), value];68 }69};7071// Multiple processes might be piping from/to `process.std*` at the same time.
23 unmodified lines
modified:lib/stdio/direction.js+3 added-3 removed
4 unmodified lines
5 isWritableStream as isNodeWritableStream,6} from 'is-stream';7import {isWritableStream} from './type.js';89// For `stdio[index]` beyond stdin/stdout/stderr, we need to guess whether the value passed is intended for inputs or outputs.9// For `stdio[fdNumber]` beyond stdin/stdout/stderr, we need to guess whether the value passed is intended for inputs or outputs.10// This allows us to know whether to pipe _into_ or _from_ the stream.11// When `stdio[index]` is a single value, this guess is fairly straightforward.11// When `stdio[fdNumber]` is a single value, this guess is fairly straightforward.12// However, when it is an array instead, we also need to make sure the different values are not incompatible with each other.13export const addStreamDirection = stdioStreams => {14 const directions = stdioStreams.map(stdioStream => getStreamDirection(stdioStream));15
4 unmodified lines
20 const direction = directions.find(Boolean);21 return stdioStreams.map(stdioStream => addDirection(stdioStream, direction));22};2324const getStreamDirection = stdioStream => KNOWN_DIRECTIONS[stdioStream.index] ?? guessStreamDirection[stdioStream.type](stdioStream.value);24const getStreamDirection = stdioStream => KNOWN_DIRECTIONS[stdioStream.fdNumber] ?? guessStreamDirection[stdioStream.type](stdioStream.value);2526// `stdin`/`stdout`/`stderr` have a known direction27const KNOWN_DIRECTIONS = ['input', 'output', 'output'];28
52 unmodified lines
modified:lib/stdio/generator.js+5 added-5 removed
83 unmodified lines
84 return {value: duplexStream};85};8687// `childProcess.stdin|stdout|stderr|stdio` is directly mutated.88export const pipeGenerator = (spawned, {value, direction, index}) => {88export const pipeGenerator = (spawned, {value, direction, fdNumber}) => {89 if (direction === 'output') {90 pipeStreams([spawned.stdio[index]], value);90 pipeStreams([spawned.stdio[fdNumber]], value);91 } else {92 pipeStreams([value], spawned.stdio[index]);92 pipeStreams([value], spawned.stdio[fdNumber]);93 }9495 const streamProperty = PROCESS_STREAM_PROPERTIES[index];95 const streamProperty = PROCESS_STREAM_PROPERTIES[fdNumber];96 if (streamProperty !== undefined) {97 spawned[streamProperty] = value;98 }99100 spawned.stdio[index] = value;100 spawned.stdio[fdNumber] = value;101};102103const PROCESS_STREAM_PROPERTIES = ['stdin', 'stdout', 'stderr'];
modified:lib/stdio/handle.js+7 added-7 removed
9 unmodified lines
1011// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode12export const handleInput = (addProperties, options, isSync) => {13 const stdio = normalizeStdio(options);14 const [stdinStreams, ...otherStreamsGroups] = stdio.map((stdioOption, index) => getStdioStreams(stdioOption, index));14 const [stdinStreams, ...otherStreamsGroups] = stdio.map((stdioOption, fdNumber) => getStdioStreams(stdioOption, fdNumber));15 const stdioStreamsGroups = [[...stdinStreams, ...handleInputOptions(options)], ...otherStreamsGroups]16 .map(stdioStreams => validateStreams(stdioStreams))17 .map(stdioStreams => addStreamDirection(stdioStreams))18 .map(stdioStreams => handleStreamsLines(stdioStreams, options, isSync))
6 unmodified lines
2526// We make sure passing an array with a single item behaves the same as passing that item without an array.27// This is what users would expect.28// For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.29const getStdioStreams = (stdioOption, index) => {30 const optionName = getOptionName(index);29const getStdioStreams = (stdioOption, fdNumber) => {30 const optionName = getOptionName(fdNumber);31 const stdioOptions = Array.isArray(stdioOption) ? stdioOption : [stdioOption];32 const rawStdioStreams = stdioOptions.map(stdioOption => getStdioStream(stdioOption, optionName, index));32 const rawStdioStreams = stdioOptions.map(stdioOption => getStdioStream(stdioOption, optionName, fdNumber));33 const stdioStreams = filterDuplicates(rawStdioStreams);34 const isStdioArray = stdioStreams.length > 1;35 validateStdioArray(stdioStreams, isStdioArray, optionName);36 return stdioStreams.map(stdioStream => handleNativeStream(stdioStream, isStdioArray));37};3839const getOptionName = index => KNOWN_OPTION_NAMES[index] ?? `stdio[${index}]`;39const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;40const KNOWN_OPTION_NAMES = ['stdin', 'stdout', 'stderr'];4142const getStdioStream = (stdioOption, optionName, index) => {42const getStdioStream = (stdioOption, optionName, fdNumber) => {43 const type = getStdioOptionType(stdioOption, optionName);44 return {type, value: stdioOption, optionName, index};44 return {type, value: stdioOption, optionName, fdNumber};45};4647const filterDuplicates = stdioStreams => stdioStreams.filter((stdioStreamOne, indexOne) =>48 stdioStreams.every((stdioStreamTwo, indexTwo) =>
48 unmodified lines
modified:lib/stdio/input.js+2 added-2 removed
modified:lib/stdio/native.js+5 added-5 removed
4 unmodified lines
5// We then emulate the piping done by core Node.js.6// To do so, we transform the following values:7// - Node.js streams are marked as `type: nodeStream`8// - 'inherit' becomes `process.stdin|stdout|stderr`9// - any file descriptor integer becomes `process.stdio[index]`9// - any file descriptor integer becomes `process.stdio[fdNumber]`10// All of the above transformations tell Execa to perform manual piping.11export const handleNativeStream = (stdioStream, isStdioArray) => {12 const {type, value, index, optionName} = stdioStream;12 const {type, value, fdNumber, optionName} = stdioStream;1314 if (!isStdioArray || type !== 'native') {15 return stdioStream;16 }1718 if (value === 'inherit') {19 return {...stdioStream, type: 'nodeStream', value: getStandardStream(index, value, optionName)};19 return {...stdioStream, type: 'nodeStream', value: getStandardStream(fdNumber, value, optionName)};20 }2122 if (typeof value === 'number') {23 return {...stdioStream, type: 'nodeStream', value: getStandardStream(value, value, optionName)};
10 unmodified lines
34// - `fs.createReadStream()`/`fs.createWriteStream()` with the `fd` option do not work with character devices that use blocking reads/writes (such as interactive TTYs).35// - Using a TCP `Socket` would work but be rather complex to implement.36// Since this is an edge case, we simply throw an error message.37// See https://github.com/sindresorhus/execa/pull/643#discussion_r143590570738const getStandardStream = (index, value, optionName) => {39 const standardStream = STANDARD_STREAMS[index];38const getStandardStream = (fdNumber, value, optionName) => {39 const standardStream = STANDARD_STREAMS[fdNumber];4041 if (standardStream === undefined) {42 throw new TypeError(`The \`${optionName}: ${value}\` option is invalid: no such standard stream.`);43 }
3 unmodified lines
modified:lib/stdio/option.js+1 added-1 removed
24 unmodified lines
25 throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);26 }2728 const length = Math.max(stdio.length, STANDARD_STREAMS_ALIASES.length);29 return Array.from({length}, (value, index) => stdio[index]);29 return Array.from({length}, (value, fdNumber) => stdio[fdNumber]);30};3132const hasAlias = options => STANDARD_STREAMS_ALIASES.some(alias => options[alias] !== undefined);
modified:lib/stdio/sync.js+1 added-1 removed
52 unmodified lines
53 }5455 for (const stdioStreams of stdioStreamsGroups) {56 for (const stdioStream of stdioStreams) {57 pipeStdioOptionSync(result.output[stdioStream.index], stdioStream);57 pipeStdioOptionSync(result.output[stdioStream.fdNumber], stdioStream);58 }59 }60};61
9 unmodified lines
modified:lib/stream/all.js+1 added-1 removed
9 unmodified lines
10// Read the contents of `childProcess.all` and|or wait for its completion11export const waitForAllStream = ({spawned, encoding, buffer, maxBuffer, streamInfo}) => waitForChildStream({12 stream: getAllStream(spawned, encoding),13 spawned,14 index: 1,14 fdNumber: 1,15 encoding,16 buffer,17 maxBuffer: maxBuffer * 2,18 streamInfo,
18 unmodified lines
modified:lib/stream/child.js+5 added-5 removed
1import {setImmediate} from 'node:timers/promises';2import getStream, {getStreamAsArrayBuffer, getStreamAsArray, MaxBufferError} from 'get-stream';3import {waitForStream, handleStreamError, isInputFileDescriptor} from './wait.js';45export const waitForChildStream = async ({stream, spawned, index, encoding, buffer, maxBuffer, streamInfo}) => {5export const waitForChildStream = async ({stream, spawned, fdNumber, encoding, buffer, maxBuffer, streamInfo}) => {6 if (!stream) {7 return;8 }910 if (isInputFileDescriptor(index, streamInfo.stdioStreamsGroups)) {11 await waitForStream(stream, index, streamInfo);10 if (isInputFileDescriptor(fdNumber, streamInfo.stdioStreamsGroups)) {11 await waitForStream(stream, fdNumber, streamInfo);12 return;13 }1415 if (!buffer) {16 await Promise.all([17 waitForStream(stream, index, streamInfo),17 waitForStream(stream, fdNumber, streamInfo),18 resumeStream(stream),19 ]);20 return;21 }
4 unmodified lines
26 if (error instanceof MaxBufferError) {27 spawned.kill();28 }2930 handleStreamError(error, index, streamInfo);30 handleStreamError(error, fdNumber, streamInfo);31 return handleBufferedData(error, encoding);32 }33};34
36 unmodified lines
modified:lib/stream/resolve.js+5 added-5 removed
52 unmodified lines
53};5455// Read the contents of `childProcess.std*` and|or wait for its completion56const waitForChildStreams = ({spawned, encoding, buffer, maxBuffer, streamInfo}) =>57 spawned.stdio.map((stream, index) => waitForChildStream({stream, spawned, index, encoding, buffer, maxBuffer, streamInfo}));57 spawned.stdio.map((stream, fdNumber) => waitForChildStream({stream, spawned, fdNumber, encoding, buffer, maxBuffer, streamInfo}));5859// Transforms replace `childProcess.std*`, which means they are not exposed to users.60// However, we still want to wait for their completion.61const waitForOriginalStreams = (originalStreams, spawned, streamInfo) =>62 originalStreams.map((stream, index) => stream === spawned.stdio[index]62 originalStreams.map((stream, fdNumber) => stream === spawned.stdio[fdNumber]63 ? undefined64 : waitForStream(stream, index, streamInfo));64 : waitForStream(stream, fdNumber, streamInfo));6566// Some `stdin`/`stdout`/`stderr` options create a stream, e.g. when passing a file path.67// The `.pipe()` method automatically ends that stream when `childProcess` ends.68// This makes sure we wait for the completion of those streams, in order to catch any error.69const waitForCustomStreamsEnd = (stdioStreamsGroups, streamInfo) => stdioStreamsGroups.flatMap((stdioStreams, index) => stdioStreams69const waitForCustomStreamsEnd = (stdioStreamsGroups, streamInfo) => stdioStreamsGroups.flatMap((stdioStreams, fdNumber) => stdioStreams70 .filter(({value}) => isStream(value, {checkOpen: false}) && !isStandardStream(value))71 .map(({type, value}) => waitForStream(value, index, streamInfo, {71 .map(({type, value}) => waitForStream(value, fdNumber, streamInfo, {72 isSameDirection: type === 'generator',73 stopOnExit: type === 'native',74 })));75
9 unmodified lines
modified:lib/stream/wait.js+9 added-9 removed
1 unmodified line
23// Wraps `finished(stream)` to handle the following case:4// - When the child process exits, Node.js automatically calls `childProcess.stdin.destroy()`, which we need to ignore.5// - However, we still need to throw if `childProcess.stdin.destroy()` is called before child process exit.6export const waitForStream = async (stream, index, streamInfo, {isSameDirection, stopOnExit = false} = {}) => {6export const waitForStream = async (stream, fdNumber, streamInfo, {isSameDirection, stopOnExit = false} = {}) => {7 const {originalStreams: [originalStdin], exitPromise} = streamInfo;89 const abortController = new AbortController();10 try {
1 unmodified line
12 ...(stopOnExit || stream === originalStdin ? [exitPromise] : []),13 finished(stream, {cleanup: true, signal: abortController.signal}),14 ]);15 } catch (error) {16 handleStreamError(error, index, streamInfo, isSameDirection);16 handleStreamError(error, fdNumber, streamInfo, isSameDirection);17 } finally {18 abortController.abort();19 }20};
2 unmodified lines
23// When one stream errors, the error is propagated to the other streams on the same file descriptor.24// Those other streams might have a different direction due to the above.25// When this happens, the direction of both the initial stream and the others should then be taken into account.26// Therefore, we keep track of which file descriptor is currently propagating stream errors.27export const handleStreamError = (error, index, streamInfo, isSameDirection) => {28 if (!shouldIgnoreStreamError(error, index, streamInfo, isSameDirection)) {27export const handleStreamError = (error, fdNumber, streamInfo, isSameDirection) => {28 if (!shouldIgnoreStreamError(error, fdNumber, streamInfo, isSameDirection)) {29 throw error;30 }31};3233const shouldIgnoreStreamError = (error, index, {stdioStreamsGroups, propagating}, isSameDirection = true) => {34 if (propagating.has(index)) {33const shouldIgnoreStreamError = (error, fdNumber, {stdioStreamsGroups, propagating}, isSameDirection = true) => {34 if (propagating.has(fdNumber)) {35 return isStreamEpipe(error) || isStreamAbort(error);36 }3738 propagating.add(index);39 return isInputFileDescriptor(index, stdioStreamsGroups) === isSameDirection38 propagating.add(fdNumber);39 return isInputFileDescriptor(fdNumber, stdioStreamsGroups) === isSameDirection40 ? isStreamEpipe(error)41 : isStreamAbort(error);42};43
1 unmodified line
45// For example, `childProcess.stdin` is technically a Duplex, but can only be used as a writable.46// Therefore, we need to use the file descriptor's direction (`stdin` is input, `stdout` is output, etc.).47// However, while `childProcess.std*` and transforms follow that direction, any stream passed the `std*` option has the opposite direction.48// For example, `childProcess.stdin` is a writable, but the `stdin` option is a readable.49export const isInputFileDescriptor = (index, stdioStreamsGroups) => stdioStreamsGroups[index][0].direction === 'input';49export const isInputFileDescriptor = (fdNumber, stdioStreamsGroups) => stdioStreamsGroups[fdNumber][0].direction === 'input';5051// When `stream.destroy()` is called without an `error` argument, stream is aborted.52// This is the only way to abort a readable stream, which can be useful in some instances.53// Therefore, we ignore this error on readable streams.
8 unmodified lines
modified:test/fixtures/max-buffer.js+4 added-4 removed
1#!/usr/bin/env node2import process from 'node:process';3import {writeSync} from 'node:fs';45const index = Number(process.argv[2]);5const fdNumber = Number(process.argv[2]);6const bytes = '.'.repeat(Number(process.argv[3] || 1e7));7if (index === 1) {7if (fdNumber === 1) {8 process.stdout.write(bytes);9} else if (index === 2) {9} else if (fdNumber === 2) {10 process.stderr.write(bytes);11} else {12 writeSync(index, bytes);12 writeSync(fdNumber, bytes);13}
modified:test/fixtures/nested-stdio.js+6 added-6 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [stdioOption, index, file, ...args] = process.argv.slice(2);5const [stdioOption, fdNumber, file, ...args] = process.argv.slice(2);6let optionValue = JSON.parse(stdioOption);7optionValue = typeof optionValue === 'string' ? process[optionValue] : optionValue;8optionValue = Array.isArray(optionValue) && typeof optionValue[0] === 'string'9 ? [process[optionValue[0]], ...optionValue.slice(1)]10 : optionValue;11const stdio = ['ignore', 'inherit', 'inherit'];12stdio[index] = optionValue;13const childProcess = execa(file, [`${index}`, ...args], {stdio});12stdio[fdNumber] = optionValue;13const childProcess = execa(file, [`${fdNumber}`, ...args], {stdio});1415const shouldPipe = Array.isArray(optionValue) && optionValue.includes('pipe');16const hasPipe = childProcess.stdio[index] !== null;16const hasPipe = childProcess.stdio[fdNumber] !== null;1718if (shouldPipe && !hasPipe) {19 throw new Error(`childProcess.stdio[${index}] is null.`);19 throw new Error(`childProcess.stdio[${fdNumber}] is null.`);20}2122if (!shouldPipe && hasPipe) {23 throw new Error(`childProcess.stdio[${index}] should be null.`);23 throw new Error(`childProcess.stdio[${fdNumber}] should be null.`);24}2526await childProcess;
modified:test/fixtures/stdin-fd.js+3 added-3 removed
1#!/usr/bin/env node2import process from 'node:process';3import {readFileSync} from 'node:fs';45const fileDescriptorIndex = Number(process.argv[2]);6if (fileDescriptorIndex === 0) {5const fdNumber = Number(process.argv[2]);6if (fdNumber === 0) {7 process.stdin.pipe(process.stdout);8} else {9 process.stdout.write(readFileSync(fileDescriptorIndex));9 process.stdout.write(readFileSync(fdNumber));10}
modified:test/helpers/stdio.js+4 added-4 removed
1import process from 'node:process';23export const identity = value => value;45export const getStdio = (indexOrName, stdioOption, length = 3) => {6 if (typeof indexOrName === 'string') {7 return {[indexOrName]: stdioOption};5export const getStdio = (fdNumberOrName, stdioOption, length = 3) => {6 if (typeof fdNumberOrName === 'string') {7 return {[fdNumberOrName]: stdioOption};8 }910 const stdio = Array.from({length}).fill('pipe');11 stdio[indexOrName] = stdioOption;11 stdio[fdNumberOrName] = stdioOption;12 return {stdio};13};1415export const fullStdio = getStdio(3, 'pipe');
4 unmodified lines
modified:test/pipe/setup.js+2 added-2 removed
3 unmodified lines
4import {fullStdio} from '../helpers/stdio.js';56setFixtureDir();78const pipeToProcess = async (t, index, from, options) => {9 const {stdout} = await execa('noop-fd.js', [`${index}`, 'test'], options)8const pipeToProcess = async (t, fdNumber, from, options) => {9 const {stdout} = await execa('noop-fd.js', [`${fdNumber}`, 'test'], options)10 .pipe(execa('stdin.js'), {from});11 t.is(stdout, 'test');12};13
10 unmodified lines
modified:test/return/error.js+2 added-2 removed
70 unmodified lines
71test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true);72test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true);73test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true);7475const testPartialIgnoreMessage = async (t, index, stdioOption, output) => {76 const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(index, stdioOption, 4)));75const testPartialIgnoreMessage = async (t, fdNumber, stdioOption, output) => {76 const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));77 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));78};7980test('error.message does not contain stdout if not available', testPartialIgnoreMessage, 1, 'ignore', 'stderr');
106 unmodified lines
modified:test/return/output.js+10 added-10 removed
4 unmodified lines
5import {noopGenerator} from '../helpers/generator.js';67setFixtureDir();89const testOutput = async (t, index, execaMethod) => {10 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${index}`, 'foobar'], fullStdio);11 t.is(stdio[index], 'foobar');9const testOutput = async (t, fdNumber, execaMethod) => {10 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], fullStdio);11 t.is(stdio[fdNumber], 'foobar');1213 if (index === 1) {14 t.is(stdio[index], stdout);15 } else if (index === 2) {16 t.is(stdio[index], stderr);13 if (fdNumber === 1) {14 t.is(stdio[fdNumber], stdout);15 } else if (fdNumber === 2) {16 t.is(stdio[fdNumber], stderr);17 }18};1920test('can return stdout', testOutput, 1, execa);
90 unmodified lines
111112test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);113test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);114115const testStripFinalNewline = async (t, index, stripFinalNewline, execaMethod) => {116 const {stdio} = await execaMethod('noop-fd.js', [`${index}`, 'foobar\n'], {...fullStdio, stripFinalNewline});117 t.is(stdio[index], `foobar${stripFinalNewline === false ? '\n' : ''}`);115const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, execaMethod) => {116 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar\n'], {...fullStdio, stripFinalNewline});117 t.is(stdio[fdNumber], `foobar${stripFinalNewline === false ? '\n' : ''}`);118};119120test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);121test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);
21 unmodified lines
modified:test/stdio/async.js+2 added-2 removed
29 unmodified lines
30 if (isMultiple) {31 await onStdinRemoveListener();32 }3334 for (const [index, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {34 for (const [fdNumber, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {35 const defaultListeners = Object.fromEntries(Reflect.ownKeys(streamNewListeners).map(eventName => [eventName, []]));36 t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[index]});36 t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[fdNumber]});37 }38};3940test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);
45 unmodified lines
modified:test/stdio/direction.js+2 added-2 removed
36 unmodified lines
3738test('stdio[*] default direction is output', testAmbiguousDirection, execa);39test('stdio[*] default direction is output - sync', testAmbiguousDirection, execaSync);4041const testAmbiguousMultiple = async (t, index) => {41const testAmbiguousMultiple = async (t, fdNumber) => {42 const filePath = tempfile();43 await writeFile(filePath, 'foobar');44 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [{file: filePath}, ['foo', 'bar']]));44 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [{file: filePath}, ['foo', 'bar']]));45 t.is(stdout, 'foobarfoobar');46 await rm(filePath);47};48
2 unmodified lines
modified:test/stdio/encoding-end.js+8 added-8 removed
12 unmodified lines
13const pExec = promisify(exec);1415setFixtureDir();1617const checkEncoding = async (t, encoding, index, execaMethod) => {18 const {stdio} = await execaMethod('noop-fd.js', [`${index}`, STRING_TO_ENCODE], {...fullStdio, encoding});19 compareValues(t, stdio[index], encoding);17const checkEncoding = async (t, encoding, fdNumber, execaMethod) => {18 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});19 compareValues(t, stdio[fdNumber], encoding);2021 if (execaMethod !== execaSync) {22 const childProcess = execaMethod('noop-fd.js', [`${index}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});22 const childProcess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});23 const getStreamMethod = encoding === 'buffer' ? getStreamAsBuffer : getStream;24 const result = await getStreamMethod(childProcess.stdio[index]);24 const result = await getStreamMethod(childProcess.stdio[fdNumber]);25 compareValues(t, result, encoding);26 await childProcess;27 }2829 if (index === 3) {29 if (fdNumber === 3) {30 return;31 }3233 const {stdout, stderr} = await pExec(`node noop-fd.js ${index} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});34 compareValues(t, index === 1 ? stdout : stderr, encoding);33 const {stdout, stderr} = await pExec(`node noop-fd.js ${fdNumber} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});34 compareValues(t, fdNumber === 1 ? stdout : stderr, encoding);35};3637const compareValues = (t, value, encoding) => {38 if (encoding === 'buffer') {
158 unmodified lines
modified:test/stdio/encoding-start.js+3 added-3 removed
88 unmodified lines
89test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'String');90test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object');91test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object');9293const testFirstOutputGeneratorArgument = async (t, index) => {94 const {stdio} = await execa('noop-fd.js', [`${index}`], getStdio(index, getTypeofGenerator(true)));95 t.deepEqual(stdio[index], ['[object String]']);93const testFirstOutputGeneratorArgument = async (t, fdNumber) => {94 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));95 t.deepEqual(stdio[fdNumber], ['[object String]']);96};9798test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1);99test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2);
89 unmodified lines
modified:test/stdio/file-descriptor.js+5 added-5 removed
5 unmodified lines
6import {getStdio} from '../helpers/stdio.js';78setFixtureDir();910const testFileDescriptorOption = async (t, index, execaMethod) => {10const testFileDescriptorOption = async (t, fdNumber, execaMethod) => {11 const filePath = tempfile();12 const fileDescriptor = await open(filePath, 'w');13 await execaMethod('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, fileDescriptor));13 await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, fileDescriptor));14 t.is(await readFile(filePath, 'utf8'), 'foobar');15 await rm(filePath);16 await fileDescriptor.close();17};
4 unmodified lines
22test('pass `stdout` to a file descriptor - sync', testFileDescriptorOption, 1, execaSync);23test('pass `stderr` to a file descriptor - sync', testFileDescriptorOption, 2, execaSync);24test('pass `stdio[*]` to a file descriptor - sync', testFileDescriptorOption, 3, execaSync);2526const testStdinWrite = async (t, index) => {27 const subprocess = execa('stdin-fd.js', [`${index}`], getStdio(index, 'pipe'));28 subprocess.stdio[index].end('unicorns');26const testStdinWrite = async (t, fdNumber) => {27 const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, 'pipe'));28 subprocess.stdio[fdNumber].end('unicorns');29 const {stdout} = await subprocess;30 t.is(stdout, 'unicorns');31};32
2 unmodified lines
modified:test/stdio/file-path.js+20 added-20 removed
15 unmodified lines
1617const getAbsolutePath = file => ({file});18const getRelativePath = filePath => ({file: relative('.', filePath)});1920const getStdioFile = (index, file) => getStdio(index, index === 0 ? {file} : file);20const getStdioFile = (fdNumber, file) => getStdio(fdNumber, fdNumber === 0 ? {file} : file);2122const getStdioInput = (index, file) => {23 if (index === 'string') {22const getStdioInput = (fdNumberOrName, file) => {23 if (fdNumberOrName === 'string') {24 return {input: 'foobar'};25 }2627 if (index === 'binary') {27 if (fdNumberOrName === 'binary') {28 return {input: foobarUint8Array};29 }3031 return getStdioFile(index, file);31 return getStdioFile(fdNumberOrName, file);32};3334const testStdinFile = async (t, mapFilePath, index, execaMethod) => {34const testStdinFile = async (t, mapFilePath, fdNumber, execaMethod) => {35 const filePath = tempfile();36 await writeFile(filePath, 'foobar');37 const {stdout} = await execaMethod('stdin.js', getStdio(index, mapFilePath(filePath)));37 const {stdout} = await execaMethod('stdin.js', getStdio(fdNumber, mapFilePath(filePath)));38 t.is(stdout, 'foobar');39 await rm(filePath);40};41
9 unmodified lines
51test('stdin can be an absolute file path - sync', testStdinFile, getAbsolutePath, 0, execaSync);52test('inputFile can be a relative file path - sync', testStdinFile, identity, 'inputFile', execaSync);53test('stdin can be a relative file path - sync', testStdinFile, getRelativePath, 0, execaSync);5455const testOutputFile = async (t, mapFile, index, execaMethod) => {55const testOutputFile = async (t, mapFile, fdNumber, execaMethod) => {56 const filePath = tempfile();57 await execaMethod('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, mapFile(filePath)));57 await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, mapFile(filePath)));58 t.is(await readFile(filePath, 'utf8'), 'foobar');59 await rm(filePath);60};61
15 unmodified lines
77test('stdout can be a relative file path - sync', testOutputFile, getRelativePath, 1, execaSync);78test('stderr can be a relative file path - sync', testOutputFile, getRelativePath, 2, execaSync);79test('stdio[*] can be a relative file path - sync', testOutputFile, getRelativePath, 3, execaSync);8081const testStdioNonFileUrl = (t, index, execaMethod) => {81const testStdioNonFileUrl = (t, fdNumber, execaMethod) => {82 t.throws(() => {83 execaMethod('empty.js', getStdio(index, nonFileUrl));83 execaMethod('empty.js', getStdio(fdNumber, nonFileUrl));84 }, {message: /pathToFileURL/});85};8687test('inputFile cannot be a non-file URL', testStdioNonFileUrl, 'inputFile', execa);
15 unmodified lines
103104test('inputFile must be a file URL or string', testInvalidInputFile, execa);105test('inputFile must be a file URL or string - sync', testInvalidInputFile, execaSync);106107const testInputFileValidUrl = async (t, index, execaMethod) => {107const testInputFileValidUrl = async (t, fdNumber, execaMethod) => {108 const filePath = tempfile();109 await writeFile(filePath, 'foobar');110 const currentCwd = process.cwd();111 process.chdir(dirname(filePath));112113 try {114 const {stdout} = await execaMethod('stdin.js', getStdioFile(index, basename(filePath)));114 const {stdout} = await execaMethod('stdin.js', getStdioFile(fdNumber, basename(filePath)));115 t.is(stdout, 'foobar');116 } finally {117 process.chdir(currentCwd);118 await rm(filePath);
4 unmodified lines
123test.serial('stdin does not need to start with . when being a relative file path', testInputFileValidUrl, 0, execa);124test.serial('inputFile does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 'inputFile', execaSync);125test.serial('stdin does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 0, execaSync);126127const testFilePathObject = (t, index, execaMethod) => {127const testFilePathObject = (t, fdNumber, execaMethod) => {128 t.throws(() => {129 execaMethod('empty.js', getStdio(index, 'foobar'));129 execaMethod('empty.js', getStdio(fdNumber, 'foobar'));130 }, {message: /must be used/});131};132133test('stdin must be an object when it is a file path string', testFilePathObject, 0, execa);
4 unmodified lines
138test('stdout be an object when it is a file path string - sync', testFilePathObject, 1, execaSync);139test('stderr be an object when it is a file path string - sync', testFilePathObject, 2, execaSync);140test('stdio[*] must be an object when it is a file path string - sync', testFilePathObject, 3, execaSync);141142const testFileError = async (t, fixtureName, mapFile, index) => {142const testFileError = async (t, fixtureName, mapFile, fdNumber) => {143 await t.throwsAsync(144 execa(fixtureName, [`${index}`], getStdio(index, mapFile('./unknown/file'))),144 execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, mapFile('./unknown/file'))),145 {code: 'ENOENT'},146 );147};148
7 unmodified lines
156test.serial('stdout file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 1);157test.serial('stderr file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 2);158test.serial('stdio[*] file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 3);159160const testFileErrorSync = (t, mapFile, index) => {160const testFileErrorSync = (t, mapFile, fdNumber) => {161 t.throws(() => {162 execaSync('empty.js', getStdio(index, mapFile('./unknown/file')));162 execaSync('empty.js', getStdio(fdNumber, mapFile('./unknown/file')));163 }, {code: 'ENOENT'});164};165166test('inputFile file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 'inputFile');
9 unmodified lines
176177const testMultipleInputs = async (t, indices, execaMethod) => {178 const filePath = tempfile();179 await writeFile(filePath, 'foobar');180 const options = Object.assign({}, ...indices.map(index => getStdioInput(index, filePath)));180 const options = Object.assign({}, ...indices.map(fdNumber => getStdioInput(fdNumber, filePath)));181 const {stdout} = await execaMethod('stdin.js', options);182 t.is(stdout, 'foobar'.repeat(indices.length));183 await rm(filePath);184};
29 unmodified lines
modified:test/stdio/forward.js+2 added-2 removed
3 unmodified lines
4import {setFixtureDir} from '../helpers/fixtures-dir.js';56setFixtureDir();78const testOverlapped = async (t, index) => {9 const {stdout} = await execa('noop.js', ['foobar'], getStdio(index, ['overlapped', 'pipe']));8const testOverlapped = async (t, fdNumber) => {9 const {stdout} = await execa('noop.js', ['foobar'], getStdio(fdNumber, ['overlapped', 'pipe']));10 t.is(stdout, 'foobar');11};1213test('stdin can be ["overlapped", "pipe"]', testOverlapped, 0);
3 unmodified lines
modified:test/stdio/generator.js+8 added-8 removed
31 unmodified lines
32const getOutputObjectMode = objectMode => objectMode33 ? {generator: outputObjectGenerator, output: [foobarObject], getStreamMethod: getStreamAsArray}34 : {generator: uppercaseGenerator, output: foobarUppercase, getStreamMethod: getStream};3536const testGeneratorInput = async (t, index, objectMode) => {36const testGeneratorInput = async (t, fdNumber, objectMode) => {37 const {input, generator, output} = getInputObjectMode(objectMode);38 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [input, generator]));38 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, generator]));39 t.is(stdout, output);40};4142test('Can use generators with result.stdin', testGeneratorInput, 0, false);
30 unmodified lines
73test('Can use generators with childProcess.stdio[*] as input', testGeneratorStdioInputPipe, false);74test('Can use generators with childProcess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true);7576// eslint-disable-next-line max-params77const testGeneratorOutput = async (t, index, reject, useShortcutProperty, objectMode) => {77const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode) => {78 const {generator, output} = getOutputObjectMode(objectMode);79 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';80 const {stdout, stderr, stdio} = await execa(fixtureName, [`${index}`, foobarString], {...getStdio(index, generator), reject});81 const result = useShortcutProperty ? [stdout, stderr][index - 1] : stdio[index];80 const {stdout, stderr, stdio} = await execa(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generator), reject});81 const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];82 t.deepEqual(result, output);83};8485test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false);
16 unmodified lines
102test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true);103test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true);104test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true);105106const testGeneratorOutputPipe = async (t, index, useShortcutProperty, objectMode) => {106const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode) => {107 const {generator, output, getStreamMethod} = getOutputObjectMode(objectMode);108 const childProcess = execa('noop-fd.js', [`${index}`, foobarString], {...getStdio(index, generator), buffer: false});109 const stream = useShortcutProperty ? [childProcess.stdout, childProcess.stderr][index - 1] : childProcess.stdio[index];108 const childProcess = execa('noop-fd.js', [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generator), buffer: false});109 const stream = useShortcutProperty ? [childProcess.stdout, childProcess.stderr][fdNumber - 1] : childProcess.stdio[fdNumber];110 const [result] = await Promise.all([getStreamMethod(stream), childProcess]);111 t.deepEqual(result, output);112};113
174 unmodified lines
modified:test/stdio/handle.js+7 added-7 removed
3 unmodified lines
4import {setFixtureDir} from '../helpers/fixtures-dir.js';56setFixtureDir();78const testEmptyArray = (t, index, optionName, execaMethod) => {8const testEmptyArray = (t, fdNumber, optionName, execaMethod) => {9 t.throws(() => {10 execaMethod('empty.js', getStdio(index, []));10 execaMethod('empty.js', getStdio(fdNumber, []));11 }, {message: `The \`${optionName}\` option must not be an empty array.`});12};1314test('Cannot pass an empty array to stdin', testEmptyArray, 0, 'stdin', execa);
4 unmodified lines
19test('Cannot pass an empty array to stdout - sync', testEmptyArray, 1, 'stdout', execaSync);20test('Cannot pass an empty array to stderr - sync', testEmptyArray, 2, 'stderr', execaSync);21test('Cannot pass an empty array to stdio[*] - sync', testEmptyArray, 3, 'stdio[3]', execaSync);2223const testNoPipeOption = async (t, stdioOption, index) => {24 const childProcess = execa('empty.js', getStdio(index, stdioOption));25 t.is(childProcess.stdio[index], null);23const testNoPipeOption = async (t, stdioOption, fdNumber) => {24 const childProcess = execa('empty.js', getStdio(fdNumber, stdioOption));25 t.is(childProcess.stdio[fdNumber], null);26 await childProcess;27};2829test('stdin can be "ignore"', testNoPipeOption, 'ignore', 0);
32 unmodified lines
62test('stdio[*] can be ["inherit"]', testNoPipeOption, ['inherit'], 3);63test('stdio[*] can be 3', testNoPipeOption, 3, 3);64test('stdio[*] can be [3]', testNoPipeOption, [3], 3);6566const testInvalidArrayValue = (t, invalidStdio, index, execaMethod) => {66const testInvalidArrayValue = (t, invalidStdio, fdNumber, execaMethod) => {67 t.throws(() => {68 execaMethod('empty.js', getStdio(index, ['pipe', invalidStdio]));68 execaMethod('empty.js', getStdio(fdNumber, ['pipe', invalidStdio]));69 }, {message: /must not include/});70};7172test('Cannot pass "ignore" and another value to stdin', testInvalidArrayValue, 'ignore', 0, execa);
15 unmodified lines
modified:test/stdio/iterable.js+12 added-12 removed
27 unmodified lines
28};2930setFixtureDir();3132const testIterable = async (t, stdioOption, index) => {33 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, stdioOption));32const testIterable = async (t, stdioOption, fdNumber) => {33 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));34 t.is(stdout, 'foobar');35};3637test.serial('stdin option can be an array of strings', testIterable, [stringArray], 0);
14 unmodified lines
52const foobarAsyncObjectGenerator = function * () {53 yield foobarObject;54};5556const testObjectIterable = async (t, stdioOption, index) => {57 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stdioOption, serializeGenerator]));56const testObjectIterable = async (t, stdioOption, fdNumber) => {57 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stdioOption, serializeGenerator]));58 t.is(stdout, foobarObjectString);59};6061test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0);
2 unmodified lines
64test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3);65test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0);66test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3);6768const testIterableSync = (t, stdioOption, index) => {68const testIterableSync = (t, stdioOption, fdNumber) => {69 t.throws(() => {70 execaSync('empty.js', getStdio(index, stdioOption));70 execaSync('empty.js', getStdio(fdNumber, stdioOption));71 }, {message: /an iterable in sync mode/});72};7374test('stdin option cannot be an array of strings - sync', testIterableSync, [stringArray], 0);
7 unmodified lines
82const throwingGenerator = function * () {83 throw new Error('generator error');84};8586const testIterableError = async (t, index) => {87 const {originalMessage} = await t.throwsAsync(execa('stdin-fd.js', [`${index}`], getStdio(index, throwingGenerator())));86const testIterableError = async (t, fdNumber) => {87 const {originalMessage} = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator())));88 t.is(originalMessage, 'generator error');89};9091test('stdin option handles errors in iterables', testIterableError, 0);92test('stdio[*] option handles errors in iterables', testIterableError, 3);9394const testNoIterableOutput = (t, stdioOption, index, execaMethod) => {94const testNoIterableOutput = (t, stdioOption, fdNumber, execaMethod) => {95 t.throws(() => {96 execaMethod('empty.js', getStdio(index, stdioOption));96 execaMethod('empty.js', getStdio(fdNumber, stdioOption));97 }, {message: /cannot be an iterable/});98};99100test('stdout option cannot be an array of strings', testNoIterableOutput, [stringArray], 1, execa);
14 unmodified lines
115 t.true(stdout.startsWith('foo'));116 t.deepEqual(await iterable.next(), {value: undefined, done: true});117});118119const testMultipleIterable = async (t, index) => {120 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stringGenerator(), asyncGenerator()]));119const testMultipleIterable = async (t, fdNumber) => {120 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stringGenerator(), asyncGenerator()]));121 t.is(stdout, 'foobarfoobar');122};123124test('stdin option can be multiple iterables', testMultipleIterable, 0);
8 unmodified lines
modified:test/stdio/lines.js+7 added-7 removed
56 unmodified lines
57 ? textDecoder.decode(resultItem)58 : resultItem;5960// eslint-disable-next-line max-params61const testLines = async (t, index, input, expectedLines, isUint8Array, objectMode) => {61const testLines = async (t, fdNumber, input, expectedLines, isUint8Array, objectMode) => {62 const lines = [];63 const {stdio} = await execa('noop-fd.js', [`${index}`], {64 ...getStdio(index, [63 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], {64 ...getStdio(fdNumber, [65 {transform: inputGenerator.bind(undefined, stringsToUint8Arrays(input, isUint8Array)), objectMode},66 {transform: resultGenerator.bind(undefined, lines), objectMode},67 ]),68 encoding: isUint8Array ? 'buffer' : 'utf8',69 stripFinalNewline: false,70 });71 t.is(input.join(''), serializeResult(stdio[index], isUint8Array, objectMode));71 t.is(input.join(''), serializeResult(stdio[fdNumber], isUint8Array, objectMode));72 t.deepEqual(lines, stringsToUint8Arrays(expectedLines, isUint8Array));73};7475test('Split string stdout - n newlines, 1 chunk', testLines, 1, simpleChunk, simpleLines, false, false);
69 unmodified lines
145test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunk, simpleLines, true);146test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunk, simpleLines, true);147148// eslint-disable-next-line max-params149const testStreamLines = async (t, index, input, expectedLines, isUint8Array) => {150 const {stdio} = await execa('noop-fd.js', [`${index}`, input], {149const testStreamLines = async (t, fdNumber, input, expectedLines, isUint8Array) => {150 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`, input], {151 ...fullStdio,152 lines: true,153 encoding: isUint8Array ? 'buffer' : 'utf8',154 });155 t.deepEqual(stdio[index], stringsToUint8Arrays(expectedLines, isUint8Array));155 t.deepEqual(stdio[fdNumber], stringsToUint8Arrays(expectedLines, isUint8Array));156};157158test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleChunk[0], simpleLines, false);159test('"lines: true" splits lines, stdout, Uint8Array', testStreamLines, 1, simpleChunk[0], simpleLines, true);
70 unmodified lines
modified:test/stdio/native.js+8 added-8 removed
4 unmodified lines
5import {setFixtureDir} from '../helpers/fixtures-dir.js';67setFixtureDir();89const testRedirect = async (t, stdioOption, index, isInput) => {9const testRedirect = async (t, stdioOption, fdNumber, isInput) => {10 const {fixtureName, ...options} = isInput11 ? {fixtureName: 'stdin-fd.js', input: 'foobar'}12 : {fixtureName: 'noop-fd.js'};13 const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${index}`, fixtureName, 'foobar'], options);14 const resultIndex = isStderrDescriptor(stdioOption) ? 2 : 1;15 t.is(stdio[resultIndex], 'foobar');13 const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, fixtureName, 'foobar'], options);14 const resultFdNumber = isStderrDescriptor(stdioOption) ? 2 : 1;15 t.is(stdio[resultFdNumber], 'foobar');16};1718const isStderrDescriptor = stdioOption => stdioOption === 219 || stdioOption === 'stderr'
55 unmodified lines
7576test('stderr can be ["inherit", "pipe"]', testInheritStderr, ['inherit', 'pipe']);77test('stderr can be [2, "pipe"]', testInheritStderr, [2, 'pipe']);7879const testOverflowStream = async (t, index, stdioOption) => {80 const {stdout} = await execa('nested.js', [JSON.stringify(getStdio(index, stdioOption)), 'empty.js'], fullStdio);79const testOverflowStream = async (t, fdNumber, stdioOption) => {80 const {stdout} = await execa('nested.js', [JSON.stringify(getStdio(fdNumber, stdioOption)), 'empty.js'], fullStdio);81 t.is(stdout, '');82};8384if (platform === 'linux') {
9 unmodified lines
9495test('stdio[*] can use "inherit"', testOverflowStream, 3, 'inherit');96test('stdio[*] can use ["inherit"]', testOverflowStream, 3, ['inherit']);9798const testOverflowStreamArray = (t, index, stdioOption) => {98const testOverflowStreamArray = (t, fdNumber, stdioOption) => {99 t.throws(() => {100 execa('empty.js', getStdio(index, stdioOption));100 execa('empty.js', getStdio(fdNumber, stdioOption));101 }, {message: /no such standard stream/});102};103104test('stdin cannot use 4+ and another value', testOverflowStreamArray, 0, [4, 'pipe']);
4 unmodified lines
modified:test/stdio/node-stream.js+27 added-27 removed
13 unmodified lines
14import {noopReadable, noopWritable, noopDuplex, simpleReadable} from '../helpers/stream.js';1516setFixtureDir();1718const testNoFileStreamSync = async (t, index, stream) => {18const testNoFileStreamSync = async (t, fdNumber, stream) => {19 t.throws(() => {20 execaSync('empty.js', getStdio(index, stream));20 execaSync('empty.js', getStdio(fdNumber, stream));21 }, {code: 'ERR_INVALID_ARG_VALUE'});22};2324test('stdin cannot be a Node.js Readable without a file descriptor - sync', testNoFileStreamSync, 0, noopReadable());
16 unmodified lines
41 execaSync('empty.js', {input: simpleReadable()});42 }, {message: 'The `input` option cannot be a Node.js stream in sync mode.'});43});4445const testNoFileStream = async (t, index, stream) => {46 await t.throwsAsync(execa('empty.js', getStdio(index, stream)), {code: 'ERR_INVALID_ARG_VALUE'});45const testNoFileStream = async (t, fdNumber, stream) => {46 await t.throwsAsync(execa('empty.js', getStdio(fdNumber, stream)), {code: 'ERR_INVALID_ARG_VALUE'});47};4849test('stdin cannot be a Node.js Readable without a file descriptor', testNoFileStream, 0, noopReadable());50test('stdin cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 0, noopDuplex());
30 unmodified lines
8182 await rm(filePath);83};8485const testFileReadable = async (t, index, execaMethod) => {85const testFileReadable = async (t, fdNumber, execaMethod) => {86 const {stream, filePath} = await createFileReadStream();8788 const indexString = index === 'input' ? '0' : `${index}`;89 const {stdout} = await execaMethod('stdin-fd.js', [indexString], getStdio(index, stream));88 const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;89 const {stdout} = await execaMethod('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));90 t.is(stdout, 'foobar');9192 await rm(filePath);93};
3 unmodified lines
97test('stdio[*] can be a Node.js Readable with a file descriptor', testFileReadable, 3, execa);98test('stdin can be a Node.js Readable with a file descriptor - sync', testFileReadable, 0, execaSync);99test('stdio[*] can be a Node.js Readable with a file descriptor - sync', testFileReadable, 3, execaSync);100101const testFileReadableError = async (t, index) => {101const testFileReadableError = async (t, fdNumber) => {102 const {stream, filePath} = await createFileReadStream();103104 const indexString = index === 'input' ? '0' : `${index}`;105 const childProcess = execa('stdin-fd.js', [indexString], getStdio(index, stream));104 const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;105 const childProcess = execa('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));106107 await assertFileStreamError(t, childProcess, stream, filePath);108};109110test.serial('input handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 'input');111test.serial('stdin handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 0);112test.serial('stdio[*] handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 3);113114const testFileReadableOpen = async (t, index, useSingle, execaMethod) => {114const testFileReadableOpen = async (t, fdNumber, useSingle, execaMethod) => {115 const {stream, filePath} = await createFileReadStream();116 t.deepEqual(stream.eventNames(), []);117118 const stdioOption = useSingle ? stream : [stream, 'pipe'];119 await execaMethod('empty.js', getStdio(index, stdioOption));119 await execaMethod('empty.js', getStdio(fdNumber, stdioOption));120121 t.is(stream.readable, useSingle && index !== 'input');121 t.is(stream.readable, useSingle && fdNumber !== 'input');122 t.deepEqual(stream.eventNames(), []);123124 await rm(filePath);125};
4 unmodified lines
130test('stdio[*] leaves open a single Node.js Readable with a file descriptor', testFileReadableOpen, 3, true, execa);131test('stdin leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 0, true, execaSync);132test('stdio[*] leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 3, true, execaSync);133134const testFileWritable = async (t, index, execaMethod) => {134const testFileWritable = async (t, fdNumber, execaMethod) => {135 const {stream, filePath} = await createFileWriteStream();136137 await execaMethod('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, stream));137 await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, stream));138 t.is(await readFile(filePath, 'utf8'), 'foobar');139140 await rm(filePath);141};
4 unmodified lines
146test('stdout can be a Node.js Writable with a file descriptor - sync', testFileWritable, 1, execaSync);147test('stderr can be a Node.js Writable with a file descriptor - sync', testFileWritable, 2, execaSync);148test('stdio[*] can be a Node.js Writable with a file descriptor - sync', testFileWritable, 3, execaSync);149150const testFileWritableError = async (t, index) => {150const testFileWritableError = async (t, fdNumber) => {151 const {stream, filePath} = await createFileWriteStream();152153 const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStdio(index, stream));153 const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stream));154 childProcess.stdin.end(foobarString);155156 await assertFileStreamError(t, childProcess, stream, filePath);157};
1 unmodified line
159test.serial('stdout handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 1);160test.serial('stderr handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 2);161test.serial('stdio[*] handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 3);162163const testFileWritableOpen = async (t, index, useSingle, execaMethod) => {163const testFileWritableOpen = async (t, fdNumber, useSingle, execaMethod) => {164 const {stream, filePath} = await createFileWriteStream();165 t.deepEqual(stream.eventNames(), []);166167 const stdioOption = useSingle ? stream : [stream, 'pipe'];168 await execaMethod('empty.js', getStdio(index, stdioOption));168 await execaMethod('empty.js', getStdio(fdNumber, stdioOption));169170 t.is(stream.writable, useSingle);171 t.deepEqual(stream.eventNames(), []);172
9 unmodified lines
182test('stdout leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 1, true, execaSync);183test('stderr leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 2, true, execaSync);184test('stdio[*] leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 3, true, execaSync);185186const testLazyFileReadable = async (t, index) => {186const testLazyFileReadable = async (t, fdNumber) => {187 const filePath = tempfile();188 await writeFile(filePath, 'foobar');189 const stream = createReadStream(filePath);190191 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stream, 'pipe']));191 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe']));192 t.is(stdout, 'foobar');193194 await rm(filePath);195};196197test('stdin can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 0);198test('stdio[*] can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 3);199200const testLazyFileWritable = async (t, index) => {200const testLazyFileWritable = async (t, fdNumber) => {201 const filePath = tempfile();202 const stream = createWriteStream(filePath);203204 await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, [stream, 'pipe']));204 await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, [stream, 'pipe']));205 t.is(await readFile(filePath, 'utf8'), 'foobar');206207 await rm(filePath);208};
34 unmodified lines
243244test('Input streams are canceled on early process exit', testStreamEarlyExit, noopReadable(), 'stdin');245test('Output streams are canceled on early process exit', testStreamEarlyExit, noopWritable(), 'stdout');246247const testInputDuplexStream = async (t, index) => {247const testInputDuplexStream = async (t, fdNumber) => {248 const stream = new PassThrough();249 stream.end(foobarString);250 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stream, new Uint8Array()]));250 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));251 t.is(stdout, foobarString);252};253254test('Can pass Duplex streams to stdin', testInputDuplexStream, 0);255test('Can pass Duplex streams to input stdio[*]', testInputDuplexStream, 3);256257const testOutputDuplexStream = async (t, index) => {257const testOutputDuplexStream = async (t, fdNumber) => {258 const stream = new PassThrough();259 const [output] = await Promise.all([260 text(stream),261 execa('noop-fd.js', [`${index}`], getStdio(index, [stream, 'pipe'])),261 execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe'])),262 ]);263 t.is(output, foobarString);264};265
3 unmodified lines
modified:test/stdio/pipeline.js+10 added-10 removed
3 unmodified lines
4import {setFixtureDir} from '../helpers/fixtures-dir.js';56setFixtureDir();78const testDestroyStandard = async (t, index) => {9 const childProcess = execa('forever.js', {...getStdio(index, [STANDARD_STREAMS[index], 'pipe']), timeout: 1});8const testDestroyStandard = async (t, fdNumber) => {9 const childProcess = execa('forever.js', {...getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']), timeout: 1});10 await t.throwsAsync(childProcess, {message: /timed out/});11 t.false(STANDARD_STREAMS[index].destroyed);11 t.false(STANDARD_STREAMS[fdNumber].destroyed);12};1314test('Does not destroy process.stdin on child process errors', testDestroyStandard, 0);15test('Does not destroy process.stdout on child process errors', testDestroyStandard, 1);16test('Does not destroy process.stderr on child process errors', testDestroyStandard, 2);1718const testDestroyStandardSpawn = async (t, index) => {19 await t.throwsAsync(execa('forever.js', {...getStdio(index, [STANDARD_STREAMS[index], 'pipe']), uid: -1}));20 t.false(STANDARD_STREAMS[index].destroyed);18const testDestroyStandardSpawn = async (t, fdNumber) => {19 await t.throwsAsync(execa('forever.js', {...getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']), uid: -1}));20 t.false(STANDARD_STREAMS[fdNumber].destroyed);21};2223test('Does not destroy process.stdin on spawn process errors', testDestroyStandardSpawn, 0);24test('Does not destroy process.stdout on spawn process errors', testDestroyStandardSpawn, 1);25test('Does not destroy process.stderr on spawn process errors', testDestroyStandardSpawn, 2);2627const testDestroyStandardStream = async (t, index) => {28 const childProcess = execa('forever.js', getStdio(index, [STANDARD_STREAMS[index], 'pipe']));27const testDestroyStandardStream = async (t, fdNumber) => {28 const childProcess = execa('forever.js', getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']));29 const error = new Error('test');30 childProcess.stdio[index].destroy(error);30 childProcess.stdio[fdNumber].destroy(error);31 childProcess.kill();32 const thrownError = await t.throwsAsync(childProcess);33 t.is(thrownError, error);34 t.false(STANDARD_STREAMS[index].destroyed);34 t.false(STANDARD_STREAMS[fdNumber].destroyed);35};3637test('Does not destroy process.stdin on stream process errors', testDestroyStandardStream, 0);38test('Does not destroy process.stdout on stream process errors', testDestroyStandardStream, 1);
1 unmodified line
modified:test/stdio/type.js+6 added-6 removed
8 unmodified lines
9const uppercaseGenerator = function * (line) {10 yield line.toUpperCase();11};1213const testInvalidGenerator = (t, index, stdioOption) => {13const testInvalidGenerator = (t, fdNumber, stdioOption) => {14 t.throws(() => {15 execa('empty.js', getStdio(index, {...noopGenerator(), ...stdioOption}));15 execa('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));16 }, {message: /must be a generator/});17};1819test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true});
4 unmodified lines
24test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true});25test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true});26test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true});2728const testInvalidBinary = (t, index, optionName) => {28const testInvalidBinary = (t, fdNumber, optionName) => {29 t.throws(() => {30 execa('empty.js', getStdio(index, {transform: uppercaseGenerator, [optionName]: 'true'}));30 execa('empty.js', getStdio(fdNumber, {transform: uppercaseGenerator, [optionName]: 'true'}));31 }, {message: /a boolean/});32};3334test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary');
4 unmodified lines
39test('Cannot use invalid "objectMode" with stdout', testInvalidBinary, 1, 'objectMode');40test('Cannot use invalid "objectMode" with stderr', testInvalidBinary, 2, 'objectMode');41test('Cannot use invalid "objectMode" with stdio[*]', testInvalidBinary, 3, 'objectMode');4243const testSyncMethods = (t, index) => {43const testSyncMethods = (t, fdNumber) => {44 t.throws(() => {45 execaSync('empty.js', getStdio(index, uppercaseGenerator));45 execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator));46 }, {message: /cannot be a generator/});47};4849test('Cannot use generators with sync methods and stdin', testSyncMethods, 0);
3 unmodified lines
modified:test/stdio/typed-array.js+4 added-4 removed
4 unmodified lines
5import {foobarUint8Array} from '../helpers/input.js';67setFixtureDir();89const testUint8Array = async (t, index) => {10 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, foobarUint8Array));9const testUint8Array = async (t, fdNumber) => {10 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, foobarUint8Array));11 t.is(stdout, 'foobar');12};1314test('stdin option can be a Uint8Array', testUint8Array, 0);15test('stdio[*] option can be a Uint8Array', testUint8Array, 3);16test('stdin option can be a Uint8Array - sync', testUint8Array, 0);17test('stdio[*] option can be a Uint8Array - sync', testUint8Array, 3);1819const testNoUint8ArrayOutput = (t, index, execaMethod) => {19const testNoUint8ArrayOutput = (t, fdNumber, execaMethod) => {20 t.throws(() => {21 execaMethod('empty.js', getStdio(index, foobarUint8Array));21 execaMethod('empty.js', getStdio(fdNumber, foobarUint8Array));22 }, {message: /cannot be a Uint8Array/});23};2425test('stdout option cannot be a Uint8Array', testNoUint8ArrayOutput, 1, execa);
3 unmodified lines
modified:test/stdio/validate.js+2 added-2 removed
6 unmodified lines
78setFixtureDir();910// eslint-disable-next-line max-params11const testGeneratorReturn = async (t, index, generators, fixtureName, isNull) => {12 const childProcess = execa(fixtureName, [`${index}`], getStdio(index, generators));11const testGeneratorReturn = async (t, fdNumber, generators, fixtureName, isNull) => {12 const childProcess = execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generators));13 const message = isNull ? /not be called at all/ : /a string or an Uint8Array/;14 await t.throwsAsync(childProcess, {message});15};16
23 unmodified lines
modified:test/stdio/web-stream.js+12 added-12 removed
5 unmodified lines
6import {getStdio} from '../helpers/stdio.js';78setFixtureDir();910const testReadableStream = async (t, index) => {10const testReadableStream = async (t, fdNumber) => {11 const readableStream = Readable.toWeb(Readable.from('foobar'));12 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, readableStream));12 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream));13 t.is(stdout, 'foobar');14};1516test('stdin can be a ReadableStream', testReadableStream, 0);17test('stdio[*] can be a ReadableStream', testReadableStream, 3);1819const testWritableStream = async (t, index) => {19const testWritableStream = async (t, fdNumber) => {20 const result = [];21 const writableStream = new WritableStream({22 write(chunk) {23 result.push(chunk);24 },25 });26 await execa('noop-fd.js', [`${index}`, 'foobar'], getStdio(index, writableStream));26 await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, writableStream));27 t.is(result.join(''), 'foobar');28};2930test('stdout can be a WritableStream', testWritableStream, 1);31test('stderr can be a WritableStream', testWritableStream, 2);32test('stdio[*] can be a WritableStream', testWritableStream, 3);3334const testWebStreamSync = (t, StreamClass, index, optionName) => {34const testWebStreamSync = (t, StreamClass, fdNumber, optionName) => {35 t.throws(() => {36 execaSync('empty.js', getStdio(index, new StreamClass()));36 execaSync('empty.js', getStdio(fdNumber, new StreamClass()));37 }, {message: `The \`${optionName}\` option cannot be a web stream in sync mode.`});38};3940test('stdin cannot be a ReadableStream - sync', testWebStreamSync, ReadableStream, 0, 'stdin');
1 unmodified line
42test('stdout cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 1, 'stdout');43test('stderr cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 2, 'stderr');44test('stdio[*] cannot be a WritableStream - sync', testWebStreamSync, WritableStream, 3, 'stdio[3]');4546const testLongWritableStream = async (t, index) => {46const testLongWritableStream = async (t, fdNumber) => {47 let result = false;48 const writableStream = new WritableStream({49 async close() {50 await setImmediate();51 result = true;52 },53 });54 await execa('empty.js', getStdio(index, writableStream));54 await execa('empty.js', getStdio(fdNumber, writableStream));55 t.true(result);56};5758test('stdout waits for WritableStream completion', testLongWritableStream, 1);59test('stderr waits for WritableStream completion', testLongWritableStream, 2);60test('stdio[*] waits for WritableStream completion', testLongWritableStream, 3);6162const testWritableStreamError = async (t, index) => {62const testWritableStreamError = async (t, fdNumber) => {63 const error = new Error('foobar');64 const writableStream = new WritableStream({65 start(controller) {66 controller.error(error);67 },68 });69 const thrownError = await t.throwsAsync(execa('noop.js', getStdio(index, writableStream)));69 const thrownError = await t.throwsAsync(execa('noop.js', getStdio(fdNumber, writableStream)));70 t.is(thrownError, error);71};7273test('stdout option handles errors in WritableStream', testWritableStreamError, 1);74test('stderr option handles errors in WritableStream', testWritableStreamError, 2);75test('stdio[*] option handles errors in WritableStream', testWritableStreamError, 3);7677const testReadableStreamError = async (t, index) => {77const testReadableStreamError = async (t, fdNumber) => {78 const error = new Error('foobar');79 const readableStream = new ReadableStream({80 start(controller) {81 controller.error(error);82 },83 });84 const thrownError = await t.throwsAsync(execa('stdin-fd.js', [`${index}`], getStdio(index, readableStream)));84 const thrownError = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream)));85 t.is(thrownError, error);86};8788test('stdin option handles errors in ReadableStream', testReadableStreamError, 0);
10 unmodified lines
modified:test/stream/child.js+29 added-29 removed
8 unmodified lines
9setFixtureDir();1011const isWindows = platform === 'win32';1213const getStreamInputProcess = index => execa('stdin-fd.js', [`${index}`], index === 313const getStreamInputProcess = fdNumber => execa('stdin-fd.js', [`${fdNumber}`], fdNumber === 314 ? getStdio(3, [new Uint8Array(), infiniteGenerator])15 : {});16const getStreamOutputProcess = index => execa('noop-repeat.js', [`${index}`], index === 3 ? fullStdio : {});16const getStreamOutputProcess = fdNumber => execa('noop-repeat.js', [`${fdNumber}`], fdNumber === 3 ? fullStdio : {});1718const assertStreamInputError = (t, {exitCode, signal, isTerminated, failed}) => {19 t.is(exitCode, 0);20 t.is(signal, undefined);21 t.false(isTerminated);22 t.true(failed);23};2425const assertStreamOutputError = (t, index, {exitCode, signal, isTerminated, failed, stderr}) => {26 if (index !== 3) {25const assertStreamOutputError = (t, fdNumber, {exitCode, signal, isTerminated, failed, stderr}) => {26 if (fdNumber !== 3) {27 t.is(exitCode, 1);28 }2930 t.is(signal, undefined);31 t.false(isTerminated);32 t.true(failed);3334 if (index === 1 && !isWindows) {34 if (fdNumber === 1 && !isWindows) {35 t.true(stderr.includes('EPIPE'));36 }37};3839const testStreamInputAbort = async (t, index) => {40 const childProcess = getStreamInputProcess(index);41 childProcess.stdio[index].destroy();39const testStreamInputAbort = async (t, fdNumber) => {40 const childProcess = getStreamInputProcess(fdNumber);41 childProcess.stdio[fdNumber].destroy();42 const error = await t.throwsAsync(childProcess, prematureClose);43 assertStreamInputError(t, error);44};4546test('Aborting stdin should not make the process exit', testStreamInputAbort, 0);47test('Aborting input stdio[*] should not make the process exit', testStreamInputAbort, 3);4849const testStreamOutputAbort = async (t, index) => {50 const childProcess = getStreamOutputProcess(index);51 childProcess.stdio[index].destroy();49const testStreamOutputAbort = async (t, fdNumber) => {50 const childProcess = getStreamOutputProcess(fdNumber);51 childProcess.stdio[fdNumber].destroy();52 const error = await t.throwsAsync(childProcess);53 assertStreamOutputError(t, index, error);53 assertStreamOutputError(t, fdNumber, error);54};5556test('Aborting stdout should not make the process exit', testStreamOutputAbort, 1);57test('Aborting stderr should not make the process exit', testStreamOutputAbort, 2);58test('Aborting output stdio[*] should not make the process exit', testStreamOutputAbort, 3);5960const testStreamInputDestroy = async (t, index) => {61 const childProcess = getStreamInputProcess(index);60const testStreamInputDestroy = async (t, fdNumber) => {61 const childProcess = getStreamInputProcess(fdNumber);62 const error = new Error('test');63 childProcess.stdio[index].destroy(error);63 childProcess.stdio[fdNumber].destroy(error);64 t.is(await t.throwsAsync(childProcess), error);65 assertStreamInputError(t, error);66};6768test('Destroying stdin should not make the process exit', testStreamInputDestroy, 0);69test('Destroying input stdio[*] should not make the process exit', testStreamInputDestroy, 3);7071const testStreamOutputDestroy = async (t, index) => {72 const childProcess = getStreamOutputProcess(index);71const testStreamOutputDestroy = async (t, fdNumber) => {72 const childProcess = getStreamOutputProcess(fdNumber);73 const error = new Error('test');74 childProcess.stdio[index].destroy(error);74 childProcess.stdio[fdNumber].destroy(error);75 t.is(await t.throwsAsync(childProcess), error);76 assertStreamOutputError(t, index, error);76 assertStreamOutputError(t, fdNumber, error);77};7879test('Destroying stdout should not make the process exit', testStreamOutputDestroy, 1);80test('Destroying stderr should not make the process exit', testStreamOutputDestroy, 2);81test('Destroying output stdio[*] should not make the process exit', testStreamOutputDestroy, 3);8283const testStreamInputError = async (t, index) => {84 const childProcess = getStreamInputProcess(index);83const testStreamInputError = async (t, fdNumber) => {84 const childProcess = getStreamInputProcess(fdNumber);85 const error = new Error('test');86 const stream = childProcess.stdio[index];86 const stream = childProcess.stdio[fdNumber];87 stream.emit('error', error);88 stream.end();89 t.is(await t.throwsAsync(childProcess), error);90 assertStreamInputError(t, error);
1 unmodified line
9293test('Errors on stdin should not make the process exit', testStreamInputError, 0);94test('Errors on input stdio[*] should not make the process exit', testStreamInputError, 3);9596const testStreamOutputError = async (t, index) => {97 const childProcess = getStreamOutputProcess(index);96const testStreamOutputError = async (t, fdNumber) => {97 const childProcess = getStreamOutputProcess(fdNumber);98 const error = new Error('test');99 const stream = childProcess.stdio[index];99 const stream = childProcess.stdio[fdNumber];100 stream.emit('error', error);101 t.is(await t.throwsAsync(childProcess), error);102 assertStreamOutputError(t, index, error);102 assertStreamOutputError(t, fdNumber, error);103};104105test('Errors on stdout should not make the process exit', testStreamOutputError, 1);106test('Errors on stderr should not make the process exit', testStreamOutputError, 2);107test('Errors on output stdio[*] should not make the process exit', testStreamOutputError, 3);108109const testWaitOnStreamEnd = async (t, index) => {110 const childProcess = execa('stdin-fd.js', [`${index}`], fullStdio);109const testWaitOnStreamEnd = async (t, fdNumber) => {110 const childProcess = execa('stdin-fd.js', [`${fdNumber}`], fullStdio);111 await setTimeout(100);112 childProcess.stdio[index].end('foobar');112 childProcess.stdio[fdNumber].end('foobar');113 const {stdout} = await childProcess;114 t.is(stdout, 'foobar');115};116
2 unmodified lines
modified:test/stream/exit.js+18 added-18 removed
5 unmodified lines
6import {fullStdio, getStdio} from '../helpers/stdio.js';78setFixtureDir();910const testBufferIgnore = async (t, index, all) => {11 await t.notThrowsAsync(execa('max-buffer.js', [`${index}`], {...getStdio(index, 'ignore'), buffer: false, all}));10const testBufferIgnore = async (t, fdNumber, all) => {11 await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`], {...getStdio(fdNumber, 'ignore'), buffer: false, all}));12};1314test('Process buffers stdout, which does not prevent exit if ignored', testBufferIgnore, 1, false);15test('Process buffers stderr, which does not prevent exit if ignored', testBufferIgnore, 2, false);16test('Process buffers all, which does not prevent exit if ignored', testBufferIgnore, 1, true);1718const testBufferNotRead = async (t, index, all) => {19 const subprocess = execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all});18const testBufferNotRead = async (t, fdNumber, all) => {19 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});20 await t.notThrowsAsync(subprocess);21};2223test('Process buffers stdout, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, false);24test('Process buffers stderr, which does not prevent exit if not read and buffer is false', testBufferNotRead, 2, false);25test('Process buffers stdio[*], which does not prevent exit if not read and buffer is false', testBufferNotRead, 3, false);26test('Process buffers all, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, true);2728const testBufferRead = async (t, index, all) => {29 const subprocess = execa('max-buffer.js', [`${index}`], {...fullStdio, buffer: false, all});30 const stream = all ? subprocess.all : subprocess.stdio[index];28const testBufferRead = async (t, fdNumber, all) => {29 const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});30 const stream = all ? subprocess.all : subprocess.stdio[fdNumber];31 stream.resume();32 await t.notThrowsAsync(subprocess);33};34
1 unmodified line
36test('Process buffers stderr, which does not prevent exit if read and buffer is false', testBufferRead, 2, false);37test('Process buffers stdio[*], which does not prevent exit if read and buffer is false', testBufferRead, 3, false);38test('Process buffers all, which does not prevent exit if read and buffer is false', testBufferRead, 1, true);3940const testBufferExit = async (t, index, fixtureName, reject) => {41 const childProcess = execa(fixtureName, [`${index}`], {...fullStdio, reject});40const testBufferExit = async (t, fdNumber, fixtureName, reject) => {41 const childProcess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});42 await setTimeout(100);43 const {stdio} = await childProcess;44 t.is(stdio[index], 'foobar');44 t.is(stdio[fdNumber], 'foobar');45};4647test('Process buffers stdout before it is read', testBufferExit, 1, 'noop-delay.js', true);48test('Process buffers stderr before it is read', testBufferExit, 2, 'noop-delay.js', true);
4 unmodified lines
53test('Process buffers stdout right away, on failure', testBufferExit, 1, 'noop-fail.js', false);54test('Process buffers stderr right away, on failure', testBufferExit, 2, 'noop-fail.js', false);55test('Process buffers stdio[*] right away, on failure', testBufferExit, 3, 'noop-fail.js', false);5657const testBufferDirect = async (t, index) => {58 const childProcess = execa('noop-fd.js', [`${index}`], fullStdio);59 const data = await once(childProcess.stdio[index], 'data');57const testBufferDirect = async (t, fdNumber) => {58 const childProcess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);59 const data = await once(childProcess.stdio[fdNumber], 'data');60 t.is(data.toString().trim(), 'foobar');61 const result = await childProcess;62 t.is(result.stdio[index], 'foobar');62 t.is(result.stdio[fdNumber], 'foobar');63};6465test('Process buffers stdout right away, even if directly read', testBufferDirect, 1);66test('Process buffers stderr right away, even if directly read', testBufferDirect, 2);67test('Process buffers stdio[*] right away, even if directly read', testBufferDirect, 3);6869const testBufferDestroyOnEnd = async (t, index) => {70 const childProcess = execa('noop-fd.js', [`${index}`], fullStdio);69const testBufferDestroyOnEnd = async (t, fdNumber) => {70 const childProcess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);71 const result = await childProcess;72 t.is(result.stdio[index], 'foobar');73 t.true(childProcess.stdio[index].destroyed);72 t.is(result.stdio[fdNumber], 'foobar');73 t.true(childProcess.stdio[fdNumber].destroyed);74};7576test('childProcess.stdout must be read right away', testBufferDestroyOnEnd, 1);77test('childProcess.stderr must be read right away', testBufferDestroyOnEnd, 2);
1 unmodified line
modified:test/stream/max-buffer.js+22 added-22 removed
7 unmodified lines
8setFixtureDir();910const maxBuffer = 10;1112const testMaxBufferSuccess = async (t, index, all) => {13 await t.notThrowsAsync(execa('max-buffer.js', [`${index}`, `${maxBuffer}`], {...fullStdio, maxBuffer, all}));12const testMaxBufferSuccess = async (t, fdNumber, all) => {13 await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, maxBuffer, all}));14};1516test('maxBuffer does not affect stdout if too high', testMaxBufferSuccess, 1, false);17test('maxBuffer does not affect stderr if too high', testMaxBufferSuccess, 2, false);
8 unmodified lines
26 t.true(isTerminated);27 t.is(signal, 'SIGINT');28});2930const testMaxBufferLimit = async (t, index, all) => {30const testMaxBufferLimit = async (t, fdNumber, all) => {31 const length = all ? maxBuffer * 2 : maxBuffer;32 const result = await t.throwsAsync(33 execa('max-buffer.js', [`${index}`, `${length + 1}`], {...fullStdio, maxBuffer, all}),33 execa('max-buffer.js', [`${fdNumber}`, `${length + 1}`], {...fullStdio, maxBuffer, all}),34 {message: /maxBuffer exceeded/},35 );36 t.is(all ? result.all : result.stdio[index], '.'.repeat(length));36 t.is(all ? result.all : result.stdio[fdNumber], '.'.repeat(length));37};3839test('maxBuffer affects stdout', testMaxBufferLimit, 1, false);40test('maxBuffer affects stderr', testMaxBufferLimit, 2, false);41test('maxBuffer affects stdio[*]', testMaxBufferLimit, 3, false);42test('maxBuffer affects all', testMaxBufferLimit, 1, true);4344const testMaxBufferEncoding = async (t, index) => {44const testMaxBufferEncoding = async (t, fdNumber) => {45 const result = await t.throwsAsync(46 execa('max-buffer.js', [`${index}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'buffer'}),46 execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'buffer'}),47 );48 const stream = result.stdio[index];48 const stream = result.stdio[fdNumber];49 t.true(stream instanceof Uint8Array);50 t.is(Buffer.from(stream).toString(), '.'.repeat(maxBuffer));51};5253test('maxBuffer works with encoding buffer and stdout', testMaxBufferEncoding, 1);54test('maxBuffer works with encoding buffer and stderr', testMaxBufferEncoding, 2);55test('maxBuffer works with encoding buffer and stdio[*]', testMaxBufferEncoding, 3);5657const testMaxBufferHex = async (t, index) => {57const testMaxBufferHex = async (t, fdNumber) => {58 const halfMaxBuffer = maxBuffer / 2;59 const {stdio} = await t.throwsAsync(60 execa('max-buffer.js', [`${index}`, `${halfMaxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'hex'}),60 execa('max-buffer.js', [`${fdNumber}`, `${halfMaxBuffer + 1}`], {...fullStdio, maxBuffer, encoding: 'hex'}),61 );62 t.is(stdio[index], Buffer.from('.'.repeat(halfMaxBuffer)).toString('hex'));62 t.is(stdio[fdNumber], Buffer.from('.'.repeat(halfMaxBuffer)).toString('hex'));63};6465test('maxBuffer works with other encodings and stdout', testMaxBufferHex, 1);66test('maxBuffer works with other encodings and stderr', testMaxBufferHex, 2);67test('maxBuffer works with other encodings and stdio[*]', testMaxBufferHex, 3);6869const testNoMaxBuffer = async (t, index) => {70 const subprocess = execa('max-buffer.js', [`${index}`, `${maxBuffer}`], {...fullStdio, buffer: false});69const testNoMaxBuffer = async (t, fdNumber) => {70 const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, buffer: false});71 const [result, output] = await Promise.all([72 subprocess,73 getStream(subprocess.stdio[index]),73 getStream(subprocess.stdio[fdNumber]),74 ]);75 t.is(result.stdio[index], undefined);75 t.is(result.stdio[fdNumber], undefined);76 t.is(output, '.'.repeat(maxBuffer));77};7879test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1);80test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2);81test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3);8283const testNoMaxBufferOption = async (t, index) => {83const testNoMaxBufferOption = async (t, fdNumber) => {84 const length = maxBuffer + 1;85 const subprocess = execa('max-buffer.js', [`${index}`, `${length}`], {...fullStdio, maxBuffer, buffer: false});85 const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${length}`], {...fullStdio, maxBuffer, buffer: false});86 const [result, output] = await Promise.all([87 subprocess,88 getStream(subprocess.stdio[index]),88 getStream(subprocess.stdio[fdNumber]),89 ]);90 t.is(result.stdio[index], undefined);90 t.is(result.stdio[fdNumber], undefined);91 t.is(output, '.'.repeat(length));92};9394test('do not hit maxBuffer when `buffer` is `false` with stdout', testNoMaxBufferOption, 1);95test('do not hit maxBuffer when `buffer` is `false` with stderr', testNoMaxBufferOption, 2);96test('do not hit maxBuffer when `buffer` is `false` with stdio[*]', testNoMaxBufferOption, 3);9798const testMaxBufferAbort = async (t, index) => {99 const childProcess = execa('max-buffer.js', [`${index}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer});98const testMaxBufferAbort = async (t, fdNumber) => {99 const childProcess = execa('max-buffer.js', [`${fdNumber}`, `${maxBuffer + 1}`], {...fullStdio, maxBuffer});100 await Promise.all([101 t.throwsAsync(childProcess, {message: /maxBuffer exceeded/}),102 t.throwsAsync(getStream(childProcess.stdio[index]), {code: 'ABORT_ERR'}),102 t.throwsAsync(getStream(childProcess.stdio[fdNumber]), {code: 'ABORT_ERR'}),103 ]);104};105106test('abort stream when hitting maxBuffer with stdout', testMaxBufferAbort, 1);
2 unmodified lines
modified:test/stream/no-buffer.js+12 added-12 removed
6 unmodified lines
7import {foobarString} from '../helpers/input.js';89setFixtureDir();1011const testLateStream = async (t, index, all) => {12 const subprocess = execa('noop-fd-ipc.js', [`${index}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});11const testLateStream = async (t, fdNumber, all) => {12 const subprocess = execa('noop-fd-ipc.js', [`${fdNumber}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});13 await once(subprocess, 'message');14 const [output, allOutput] = await Promise.all([15 getStream(subprocess.stdio[index]),15 getStream(subprocess.stdio[fdNumber]),16 all ? getStream(subprocess.all) : undefined,17 subprocess,18 ]);19
14 unmodified lines
34 return output.toString();35};3637// eslint-disable-next-line max-params38const testIterationBuffer = async (t, index, buffer, useDataEvents, all) => {39 const subprocess = execa('noop-fd.js', [`${index}`, foobarString], {...fullStdio, buffer, all});38const testIterationBuffer = async (t, fdNumber, buffer, useDataEvents, all) => {39 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], {...fullStdio, buffer, all});40 const getOutput = useDataEvents ? getFirstDataEvent : getStream;41 const [result, output, allOutput] = await Promise.all([42 subprocess,43 getOutput(subprocess.stdio[index]),43 getOutput(subprocess.stdio[fdNumber]),44 all ? getOutput(subprocess.all) : undefined,45 ]);4647 const expectedProcessResult = buffer ? foobarString : undefined;48 const expectedOutput = !buffer || useDataEvents ? foobarString : '';4950 t.is(result.stdio[index], expectedProcessResult);50 t.is(result.stdio[fdNumber], expectedProcessResult);51 t.is(output, expectedOutput);5253 if (all) {54 t.is(result.all, expectedProcessResult);
17 unmodified lines
72test('Can listen to `data` events on stderr when `buffer` set to `true`', testIterationBuffer, 2, true, true, false);73test('Can listen to `data` events on stdio[*] when `buffer` set to `true`', testIterationBuffer, 3, true, true, false);74test('Can listen to `data` events on all when `buffer` set to `true`', testIterationBuffer, 1, true, true, true);7576const testNoBufferStreamError = async (t, index, all) => {77 const subprocess = execa('noop-fd.js', [`${index}`], {...fullStdio, buffer: false, all});78 const stream = all ? subprocess.all : subprocess.stdio[index];76const testNoBufferStreamError = async (t, fdNumber, all) => {77 const subprocess = execa('noop-fd.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});78 const stream = all ? subprocess.all : subprocess.stdio[fdNumber];79 const error = new Error('test');80 stream.destroy(error);81 t.is(await t.throwsAsync(subprocess), error);82};
11 unmodified lines
94 const {exitCode} = await t.throwsAsync(execa('fail.js', {buffer: false}));95 t.is(exitCode, 2);96});9798const testStreamEnd = async (t, index, buffer) => {98const testStreamEnd = async (t, fdNumber, buffer) => {99 const subprocess = execa('wrong command', {...fullStdio, buffer});100 await Promise.all([101 t.throwsAsync(subprocess, {message: /wrong command/}),102 once(subprocess.stdio[index], 'end'),102 once(subprocess.stdio[fdNumber], 'end'),103 ]);104};105106test('buffer: false > emits end event on stdout when promise is rejected', testStreamEnd, 1, false);
5 unmodified lines
modified:test/stream/resolve.js+3 added-3 removed
3 unmodified lines
4import {getStdio} from '../helpers/stdio.js';56setFixtureDir();78const testIgnore = async (t, index, execaMethod) => {9 const result = await execaMethod('noop.js', getStdio(index, 'ignore'));10 t.is(result.stdio[index], undefined);8const testIgnore = async (t, fdNumber, execaMethod) => {9 const result = await execaMethod('noop.js', getStdio(fdNumber, 'ignore'));10 t.is(result.stdio[fdNumber], undefined);11};1213test('stdout is undefined if ignored', testIgnore, 1, execa);14test('stderr is undefined if ignored', testIgnore, 2, execa);
35 unmodified lines
modified:test/stream/wait.js+25 added-25 removed
20 unmodified lines
21const destroyOptionStream = ({stream, error}) => {22 stream.destroy(error);23};2425const destroyChildStream = ({childProcess, index, error}) => {26 childProcess.stdio[index].destroy(error);25const destroyChildStream = ({childProcess, fdNumber, error}) => {26 childProcess.stdio[fdNumber].destroy(error);27};2829const getStreamStdio = (index, stream, useTransform) => getStdio(index, [stream, useTransform ? noopGenerator(false) : 'pipe']);29const getStreamStdio = (fdNumber, stream, useTransform) => getStdio(fdNumber, [stream, useTransform ? noopGenerator(false) : 'pipe']);3031// eslint-disable-next-line max-params32const testStreamAbortWait = async (t, streamMethod, stream, index, useTransform) => {33 const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));34 streamMethod({stream, childProcess, index});32const testStreamAbortWait = async (t, streamMethod, stream, fdNumber, useTransform) => {33 const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));34 streamMethod({stream, childProcess, fdNumber});35 childProcess.stdin.end();36 await setImmediate();37 stream.destroy();38
9 unmodified lines
48test('Keeps running when stdin option is used and childProcess.stdin Duplex ends, with a transform', testStreamAbortWait, noop, noopDuplex(), 0, true);49test('Keeps running when input stdio[*] option is used and input childProcess.stdio[*] ends, with a transform', testStreamAbortWait, noop, noopReadable(), 3, true);5051// eslint-disable-next-line max-params52const testStreamAbortSuccess = async (t, streamMethod, stream, index, useTransform) => {53 const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));54 streamMethod({stream, childProcess, index});52const testStreamAbortSuccess = async (t, streamMethod, stream, fdNumber, useTransform) => {53 const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));54 streamMethod({stream, childProcess, fdNumber});55 childProcess.stdin.end();5657 const {stdout} = await childProcess;58 t.is(stdout, '');
25 unmodified lines
84test('Passes when output childProcess.stdio[*] aborts with no more writes, with a transform', testStreamAbortSuccess, destroyChildStream, noopWritable(), 3, true);85test('Passes when output childProcess.stdio[*] Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroyChildStream, noopDuplex(), 3, true);8687// eslint-disable-next-line max-params88const testStreamAbortFail = async (t, streamMethod, stream, index, useTransform) => {89 const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));90 streamMethod({stream, childProcess, index});91 if (index !== 0) {88const testStreamAbortFail = async (t, streamMethod, stream, fdNumber, useTransform) => {89 const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));90 streamMethod({stream, childProcess, fdNumber});91 if (fdNumber !== 0) {92 childProcess.stdin.end();93 }9495 const error = await t.throwsAsync(childProcess);
20 unmodified lines
116test('Throws abort error when output stdio[*] option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 3, true);117test('Throws abort error when output stdio[*] Duplex option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 3, true);118119// eslint-disable-next-line max-params120const testStreamEpipeSuccess = async (t, streamMethod, stream, index, useTransform) => {121 const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));122 streamMethod({stream, childProcess, index});120const testStreamEpipeSuccess = async (t, streamMethod, stream, fdNumber, useTransform) => {121 const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));122 streamMethod({stream, childProcess, fdNumber});123 childProcess.stdin.end(foobarString);124125 const {stdio} = await childProcess;126 t.is(stdio[index], foobarString);126 t.is(stdio[fdNumber], foobarString);127 t.true(stream.destroyed);128};129130test('Passes when stdout option ends with more writes', testStreamEpipeSuccess, endOptionStream, noopWritable(), 1, false);
3 unmodified lines
134test('Passes when stderr option ends with more writes, with a transform', testStreamEpipeSuccess, endOptionStream, noopWritable(), 2, true);135test('Passes when output stdio[*] option ends with more writes, with a transform', testStreamEpipeSuccess, endOptionStream, noopWritable(), 3, true);136137// eslint-disable-next-line max-params138const testStreamEpipeFail = async (t, streamMethod, stream, index, useTransform) => {139 const childProcess = execa('noop-stdin-fd.js', [`${index}`], getStreamStdio(index, stream, useTransform));140 streamMethod({stream, childProcess, index});138const testStreamEpipeFail = async (t, streamMethod, stream, fdNumber, useTransform) => {139 const childProcess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));140 streamMethod({stream, childProcess, fdNumber});141 await setImmediate();142 childProcess.stdin.end(foobarString);143144 const {exitCode, stdio, stderr} = await t.throwsAsync(childProcess);145 t.is(exitCode, 1);146 t.is(stdio[index], '');146 t.is(stdio[fdNumber], '');147 t.true(stream.destroyed);148 if (index !== 2 && !isWindows) {148 if (fdNumber !== 2 && !isWindows) {149 t.true(stderr.includes('EPIPE'));150 }151};152
22 unmodified lines
175test('Throws EPIPE when output childProcess.stdio[*] aborts with more writes, with a transform', testStreamEpipeFail, destroyChildStream, noopWritable(), 3, true);176test('Throws EPIPE when output childProcess.stdio[*] Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyChildStream, noopDuplex(), 3, true);177178// eslint-disable-next-line max-params179const testStreamError = async (t, streamMethod, stream, index, useTransform) => {180 const childProcess = execa('empty.js', getStreamStdio(index, stream, useTransform));179const testStreamError = async (t, streamMethod, stream, fdNumber, useTransform) => {180 const childProcess = execa('empty.js', getStreamStdio(fdNumber, stream, useTransform));181 const error = new Error('test');182 streamMethod({stream, childProcess, index, error});182 streamMethod({stream, childProcess, fdNumber, error});183184 t.is(await t.throwsAsync(childProcess), error);185 const {exitCode, signal, isTerminated, failed} = error;186 t.is(exitCode, 0);
42 unmodified lines
modified:index.d.ts+38 added-38 removed
102 unmodified lines
103type BufferEncodingOption = 'buffer';104105// Whether `result.stdout|stderr|all` is an array of values due to `objectMode: true`106type IsObjectStream<107 StreamIndex extends string,107 FdNumber extends string,108 OptionsType extends CommonOptions = CommonOptions,109> = IsObjectModeStream<StreamIndex, IsObjectOutputOptions<StreamOption<StreamIndex, OptionsType>>, OptionsType>;109> = IsObjectModeStream<FdNumber, IsObjectOutputOptions<StreamOption<FdNumber, OptionsType>>, OptionsType>;110111type IsObjectModeStream<112 StreamIndex extends string,112 FdNumber extends string,113 IsObjectModeStreamOption extends boolean,114 OptionsType extends CommonOptions = CommonOptions,115> = IsObjectModeStreamOption extends true116 ? true117 : IsObjectOutputOptions<StdioProperty<StreamIndex, OptionsType>>;117 : IsObjectOutputOptions<StdioProperty<FdNumber, OptionsType>>;118119type IsObjectOutputOptions<OutputOptions extends StdioOption> = IsObjectOutputOption<OutputOptions extends StdioSingleOption[]120 ? OutputOptions[number]121 : OutputOptions
6 unmodified lines
128type BooleanObjectMode<ObjectModeOption extends StdioTransformFull['objectMode']> = ObjectModeOption extends true ? true : false;129130// Whether `result.stdout|stderr|all` is `undefined`, excluding the `buffer` option131type IgnoresStreamResult<132 StreamIndex extends string,132 FdNumber extends string,133 OptionsType extends CommonOptions = CommonOptions,134> = IgnoresStreamReturn<StreamIndex, IgnoresStdioResult<StreamOption<StreamIndex, OptionsType>>, OptionsType>;134> = IgnoresStreamReturn<FdNumber, IgnoresStdioResult<StreamOption<FdNumber, OptionsType>>, OptionsType>;135136type IgnoresStreamReturn<137 StreamIndex extends string,137 FdNumber extends string,138 IsIgnoredStreamOption extends boolean,139 OptionsType extends CommonOptions = CommonOptions,140> = IsIgnoredStreamOption extends true141 ? true142 : IgnoresStdioResult<StdioProperty<StreamIndex, OptionsType>>;142 : IgnoresStdioResult<StdioProperty<FdNumber, OptionsType>>;143144// Whether `result.stdio[*]` is `undefined`145type IgnoresStdioResult<StdioOptionType extends StdioOption> = StdioOptionType extends NoStreamStdioOption ? true : false;146147// Whether `result.stdout|stderr|all` is `undefined`148type IgnoresStreamOutput<149 StreamIndex extends string,149 FdNumber extends string,150 OptionsType extends CommonOptions = CommonOptions,151> = LacksBuffer<OptionsType['buffer']> extends true152 ? true153 : IsInputStdioIndex<StreamIndex, OptionsType> extends true153 : IsInputStdioDescriptor<FdNumber, OptionsType> extends true154 ? true155 : IgnoresStreamResult<StreamIndex, OptionsType>;155 : IgnoresStreamResult<FdNumber, OptionsType>;156157type LacksBuffer<BufferOption extends Options['buffer']> = BufferOption extends false ? true : false;158159// Whether `result.stdio[StreamIndex]` is an input stream160type IsInputStdioIndex<161 StreamIndex extends string,159// Whether `result.stdio[FdNumber]` is an input stream160type IsInputStdioDescriptor<161 FdNumber extends string,162 OptionsType extends CommonOptions = CommonOptions,163> = StreamIndex extends '0'163> = FdNumber extends '0'164 ? true165 : IsInputStdio<StdioProperty<StreamIndex, OptionsType>>;165 : IsInputStdio<StdioProperty<FdNumber, OptionsType>>;166167// Whether `result.stdio[3+]` is an input stream168type IsInputStdio<StdioOptionType extends StdioOption> = StdioOptionType extends StdinOption169 ? StdioOptionType extends StdoutStderrOption
2 unmodified lines
172 : false;173174// `options.stdin|stdout|stderr`175type StreamOption<176 StreamIndex extends string,176 FdNumber extends string,177 OptionsType extends CommonOptions = CommonOptions,178> = string extends StreamIndex ? StdioOption179 : StreamIndex extends '0' ? OptionsType['stdin']180 : StreamIndex extends '1' ? OptionsType['stdout']181 : StreamIndex extends '2' ? OptionsType['stderr']178> = string extends FdNumber ? StdioOption179 : FdNumber extends '0' ? OptionsType['stdin']180 : FdNumber extends '1' ? OptionsType['stdout']181 : FdNumber extends '2' ? OptionsType['stderr']182 : undefined;183184// `options.stdio[StreamIndex]`184// `options.stdio[FdNumber]`185type StdioProperty<186 StreamIndex extends string,186 FdNumber extends string,187 OptionsType extends CommonOptions = CommonOptions,188> = StdioOptionProperty<StreamIndex, StdioArrayOption<OptionsType>>;188> = StdioOptionProperty<FdNumber, StdioArrayOption<OptionsType>>;189190type StdioOptionProperty<191 StreamIndex extends string,191 FdNumber extends string,192 StdioOptionsType extends StdioOptions,193> = string extends StreamIndex193> = string extends FdNumber194 ? StdioOption | undefined195 : StdioOptionsType extends StdioOptionsArray196 ? StreamIndex extends keyof StdioOptionsType197 ? StdioOptionsType[StreamIndex]196 ? FdNumber extends keyof StdioOptionsType197 ? StdioOptionsType[FdNumber]198 : undefined199 : undefined;200201// Type of `result.stdout|stderr`202type StdioOutput<203 StreamIndex extends string,203 FdNumber extends string,204 OptionsType extends CommonOptions = CommonOptions,205> = StdioOutputResult<StreamIndex, IgnoresStreamOutput<StreamIndex, OptionsType>, OptionsType>;205> = StdioOutputResult<FdNumber, IgnoresStreamOutput<FdNumber, OptionsType>, OptionsType>;206207type StdioOutputResult<208 StreamIndex extends string,208 FdNumber extends string,209 StreamOutputIgnored extends boolean,210 OptionsType extends CommonOptions = CommonOptions,211> = StreamOutputIgnored extends true212 ? undefined213 : StreamEncoding<IsObjectStream<StreamIndex, OptionsType>, OptionsType['lines'], OptionsType['encoding']>;213 : StreamEncoding<IsObjectStream<FdNumber, OptionsType>, OptionsType['lines'], OptionsType['encoding']>;214215type StreamEncoding<216 IsObjectResult extends boolean,217 LinesOption extends CommonOptions['lines'],
27 unmodified lines
245type MapStdioOptions<246 StdioOptionsArrayType extends StdioOptionsArray,247 OptionsType extends CommonOptions = CommonOptions,248> = {249 [StreamIndex in keyof StdioOptionsArrayType]: StdioOutput<250 StreamIndex extends string ? StreamIndex : string,249 [FdNumber in keyof StdioOptionsArrayType]: StdioOutput<250 FdNumber extends string ? FdNumber : string,251 OptionsType252 >253};254
526 unmodified lines
781export type ExecaError<OptionsType extends Options = Options> = ExecaCommonReturnValue<false, OptionsType> & ExecaCommonError;782export type ExecaSyncError<OptionsType extends SyncOptions = SyncOptions> = ExecaCommonReturnValue<true, OptionsType> & ExecaCommonError;783784type StreamUnlessIgnored<785 StreamIndex extends string,785 FdNumber extends string,786 OptionsType extends Options = Options,787> = ChildProcessStream<StreamIndex, IgnoresStreamResult<StreamIndex, OptionsType>, OptionsType>;787> = ChildProcessStream<FdNumber, IgnoresStreamResult<FdNumber, OptionsType>, OptionsType>;788789type ChildProcessStream<790 StreamIndex extends string,790 FdNumber extends string,791 StreamResultIgnored extends boolean,792 OptionsType extends Options = Options,793> = StreamResultIgnored extends true794 ? null795 : InputOutputStream<IsInputStdioIndex<StreamIndex, OptionsType>>;795 : InputOutputStream<IsInputStdioDescriptor<FdNumber, OptionsType>>;796797type InputOutputStream<IsInput extends boolean> = IsInput extends true798 ? Writable799 : Readable;
582 unmodified lines