Skip to content
Myr

Add support for `std*: duplex` option (#937)

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

authored by ehmicky · committed by GitHub · parent 1c12be9 · Browse files · 22 files+789 added−221 removed
This commit

State

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

Diff stats

22 files+789 added−221 removed

  • tests:+548 added−186 removed
  • other:+241 added−35 removed

22 files+789 added−221 removed

modified:docs/transform.md+12 added
171 unmodified lines
172const {stdout} = await execa('./command.js', {stdout: {transform, final}});173console.log(stdout); // Ends with: 'Number of lines: 54'174```175176## Node.js Duplex/Transform streams177178A Node.js [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) or [`Transform`](https://nodejs.org/api/stream.html#class-streamtransform) stream can be used instead of a generator function. A `{transform}` plain object must be passed. The [`objectMode`](#object-mode) transform option can be used, but not the [`binary`](#encoding) nor [`preserveNewlines`](#newlines) options.179180```js181import {createGzip} from 'node:zlib';182import {execa} from 'execa';183184const {stdout} = await execa('./run.js', {stdout: {transform: createGzip()}});185console.log(stdout); // `stdout` is compressed with gzip186```187188## Combining189190The [`stdin`](../readme.md#stdin), [`stdout`](../readme.md#stdout-1), [`stderr`](../readme.md#stderr-1) and [`stdio`](../readme.md#stdio-1) options can accept an array of values. While this is not specific to transforms, this can be useful with them too. For example, the following transform impacts the value printed by `inherit`.191
22 unmodified lines
modified:lib/stdio/async.js+4 added-3 removed
modified:lib/stdio/direction.js+1 added
modified:lib/stdio/generator.js+40 added-9 removed
5 unmodified lines
6import {pipeStreams} from './pipeline.js';7import {isAsyncGenerator} from './type.js';8import {getValidateTransformReturn} from './validate.js';910export const getObjectMode = (stdioItems, direction, options) => {11 const transforms = getTransforms(stdioItems, direction, options);10export const getObjectMode = (stdioItems, optionName, direction, options) => {11 const transforms = getTransforms(stdioItems, optionName, direction, options);12 if (transforms.length === 0) {13 return false;14 }1516 const {value: {readableObjectMode, writableObjectMode}} = transforms.at(-1);17 return direction === 'input' ? writableObjectMode : readableObjectMode;18};1920export const normalizeTransforms = (stdioItems, direction, options) => [21 ...stdioItems.filter(({type}) => type !== 'generator'),22 ...getTransforms(stdioItems, direction, options),20export const normalizeTransforms = (stdioItems, optionName, direction, options) => [21 ...stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type)),22 ...getTransforms(stdioItems, optionName, direction, options),23];2425const getTransforms = (stdioItems, direction, {encoding}) => {26 const transforms = stdioItems.filter(({type}) => type === 'generator');25const getTransforms = (stdioItems, optionName, direction, {encoding}) => {26 const transforms = stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type));27 const newTransforms = Array.from({length: transforms.length});2829 for (const [index, stdioItem] of Object.entries(transforms)) {30 newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, direction, encoding});30 newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, optionName, direction, encoding});31 }3233 return sortTransforms(newTransforms, direction);34};3536export const TRANSFORM_TYPES = new Set(['generator', 'duplex']);3738const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => type === 'duplex'39 ? normalizeDuplex({stdioItem, optionName})40 : normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});4142const normalizeDuplex = ({43 stdioItem,44 stdioItem: {45 value: {46 transform,47 transform: {writableObjectMode, readableObjectMode},48 objectMode = readableObjectMode,49 },50 },51 optionName,52}) => {53 if (objectMode && !readableObjectMode) {54 throw new TypeError(`The \`${optionName}.objectMode\` option can only be \`true\` if \`new Duplex({objectMode: true})\` is used.`);55 }5657 if (!objectMode && readableObjectMode) {58 throw new TypeError(`The \`${optionName}.objectMode\` option cannot be \`false\` if \`new Duplex({objectMode: true})\` is used.`);59 }6061 return {62 ...stdioItem,63 value: {transform, writableObjectMode, readableObjectMode},64 };65};6636const normalizeTransform = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {67const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {68 const {69 transform,70 final,71 binary: binaryOption = false,
89 unmodified lines
modified:lib/stdio/handle.js+2 added-2 removed
95 unmodified lines
96};9798const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines}) => {99 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines});100 const normalizedStdioItems = normalizeTransforms(allStdioItems, direction, options);100 const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);101 return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));102};103104const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines}) => {105 if (!willPipeFileDescriptor(stdioItems)) {106 return stdioItems;107 }108109 const objectMode = getObjectMode(stdioItems, direction, options);109 const objectMode = getObjectMode(stdioItems, optionName, direction, options);110 return [111 ...stdioItems,112 ...handleStreamsEncoding({options, isSync, direction, optionName, objectMode}),113 ...handleStreamsVerbose({stdioItems, options, isSync, stdioState, verboseInfo, fdNumber, optionName}),
11 unmodified lines
modified:lib/stdio/sync.js+1 added
16 unmodified lines
17const addProperties = {18 generator: forbiddenIfSync,19 webStream: forbiddenIfSync,20 nodeStream: forbiddenIfSync,21 duplex: forbiddenIfSync,22 iterable: forbiddenIfSync,23 native() {},24};25
56 unmodified lines
modified:lib/stdio/type.js+26 added-3 removed
1import {isStream as isNodeStream} from 'is-stream';1import {isStream as isNodeStream, isDuplexStream} from 'is-stream';2import isPlainObj from 'is-plain-obj';3import {isUint8Array} from '../utils.js';45// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.
32 unmodified lines
3839 return 'native';40};4142const getTransformObjectType = (value, optionName) => isDuplexStream(value.transform, {checkOpen: false})43 ? getDuplexType(value, optionName)44 : getGeneratorObjectType(value, optionName);4546const getDuplexType = ({final, binary, objectMode}, optionName) => {47 checkUndefinedOption(final, `${optionName}.final`);48 checkUndefinedOption(binary, `${optionName}.binary`);49 checkBooleanOption(objectMode, `${optionName}.objectMode`);5051 return 'duplex';52};5354const checkUndefinedOption = (value, optionName) => {55 if (value !== undefined) {56 throw new TypeError(`The \`${optionName}\` option can only be defined when using a generator, not a Duplex stream.`);57 }58};5942const getTransformObjectType = ({transform, final, binary, objectMode}, optionName) => {60const getGeneratorObjectType = ({transform, final, binary, objectMode}, optionName) => {61 if (transform !== undefined && !isGenerator(transform)) {44 throw new TypeError(`The \`${optionName}.transform\` option must be a generator.`);62 throw new TypeError(`The \`${optionName}.transform\` option must be a generator or a Duplex stream.`);63 }6465 if (isDuplexStream(final, {checkOpen: false})) {66 throw new TypeError(`The \`${optionName}.final\` option must not be a Duplex stream.`);67 }6869 if (final !== undefined && !isGenerator(final)) {70 throw new TypeError(`The \`${optionName}.final\` option must be a generator.`);71 }72
42 unmodified lines
115 fileUrl: 'a file URL',116 filePath: 'a file path string',117 webStream: 'a web stream',118 nodeStream: 'a Node.js stream',119 duplex: 'a Duplex stream',120 native: 'any value',121 iterable: 'an iterable',122 string: 'a string',123 uint8Array: 'a Uint8Array',
1 unmodified line
modified:lib/stream/resolve.js+2 added-1 removed
2 unmodified lines
3import {waitForSuccessfulExit} from '../exit/code.js';4import {errorSignal} from '../exit/kill.js';5import {throwOnTimeout} from '../exit/timeout.js';6import {isStandardStream} from '../utils.js';7import {TRANSFORM_TYPES} from '../stdio/generator.js';8import {waitForAllStream} from './all.js';9import {waitForSubprocessStream, getBufferedData} from './subprocess.js';10import {waitForExit} from './exit.js';11import {waitForStream} from './wait.js';
57 unmodified lines
69// This makes sure we wait for the completion of those streams, in order to catch any error.70const waitForCustomStreamsEnd = (fileDescriptors, streamInfo) => fileDescriptors.flatMap(({stdioItems, fdNumber}) => stdioItems71 .filter(({value, stream = value}) => isNodeStream(stream, {checkOpen: false}) && !isStandardStream(stream))72 .map(({type, value, stream = value}) => waitForStream(stream, fdNumber, streamInfo, {72 isSameDirection: type === 'generator',73 isSameDirection: TRANSFORM_TYPES.has(type),74 stopOnExit: type === 'native',75 })));7677const throwOnSubprocessError = async (subprocess, {signal}) => {
8 unmodified lines
modified:lib/verbose/output.js+2 added-1 removed
1import {inspect} from 'node:util';2import {escapeLines} from '../arguments/escape.js';3import {BINARY_ENCODINGS} from '../arguments/encoding.js';4import {PIPED_STDIO_VALUES} from '../stdio/forward.js';5import {TRANSFORM_TYPES} from '../stdio/generator.js';6import {verboseLog} from './log.js';78export const handleStreamsVerbose = ({stdioItems, options, isSync, stdioState, verboseInfo, fdNumber, optionName}) => shouldLogOutput({stdioItems, options, isSync, verboseInfo, fdNumber})9 ? [{
12 unmodified lines
22 && !isSync23 && !BINARY_ENCODINGS.has(encoding)24 && fdUsesVerbose(fdNumber)25 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))25 || stdioItems.every(({type}) => type === 'generator'));26 || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));2728// Printing input streams would be confusing.29// Files and streams can produce big outputs, which we don't want to print.30// We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue.
30 unmodified lines
modified:test/fixtures/nested-inherit.js+4 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';3import {uppercaseGenerator} from '../helpers/generator.js';4import {generatorsMap} from '../helpers/map.js';56const type = process.argv[2];5await execa('noop-fd.js', ['1'], {stdout: ['inherit', uppercaseGenerator()]});7await execa('noop-fd.js', ['1'], {stdout: ['inherit', generatorsMap[type].uppercase()]});
modified:test/fixtures/nested-transform.js+4 added-3 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';4import {uppercaseGenerator} from '../helpers/generator.js';4import {generatorsMap} from '../helpers/map.js';56const [options, file, ...args] = process.argv.slice(2);7await execa(file, args, {stdout: uppercaseGenerator(), ...JSON.parse(options)});6const [optionsString, file, ...args] = process.argv.slice(2);7const {type, ...options} = JSON.parse(optionsString);8await execa(file, args, {stdout: generatorsMap[type].uppercase(), ...options});
added:test/helpers/duplex.js+59 added
1import {Transform} from 'node:stream';2import {setTimeout, scheduler} from 'node:timers/promises';3import {callbackify} from 'node:util';4import {foobarObject, foobarString} from './input.js';5import {casedSuffix, prefix, suffix} from './generator.js';67const getDuplex = (transform, encoding, outerObjectMode) => objectMode => ({8 transform: new Transform({9 transform: callbackify(async function (value) {10 return transform.call(this, value);11 }),12 objectMode,13 encoding,14 }),15 objectMode: outerObjectMode,16});1718export const addNoopDuplex = (duplex, addNoopTransform, objectMode) => addNoopTransform19 ? [duplex, noopDuplex(objectMode)]20 : [duplex];2122export const noopDuplex = getDuplex(value => value);2324export const serializeDuplex = getDuplex(object => JSON.stringify(object));2526export const getOutputDuplex = (input, outerObjectMode) => getDuplex(() => input, undefined, outerObjectMode);2728export const outputObjectDuplex = () => getOutputDuplex(foobarObject)(true);2930export const getOutputsDuplex = inputs => getDuplex(function () {31 for (const input of inputs) {32 this.push(input);33 }34});3536export const noYieldDuplex = getDuplex(() => {});3738export const multipleYieldDuplex = getDuplex(async function (line) {39 this.push(prefix);40 await scheduler.yield();41 this.push(line);42 await scheduler.yield();43 this.push(suffix);44});4546export const uppercaseEncodingDuplex = (encoding, outerObjectMode) => getDuplex(buffer => buffer.toString().toUpperCase(), encoding, outerObjectMode);4748export const uppercaseBufferDuplex = uppercaseEncodingDuplex();4950export const throwingDuplex = getDuplex(() => {51 throw new Error('Generator error');52});5354export const appendDuplex = getDuplex(string => `${string}${casedSuffix}`);5556export const timeoutDuplex = timeout => getDuplex(async () => {57 await setTimeout(timeout);58 return foobarString;59});
modified:test/helpers/input.js+1 added
13 unmodified lines
14export const foobarUtf16Uint8Array = bufferToUint8Array(foobarUtf16Buffer);15export const foobarDataView = new DataView(foobarArrayBuffer);16export const foobarHex = foobarBuffer.toString('hex');17export const foobarUppercase = foobarString.toUpperCase();18export const foobarUppercaseHex = Buffer.from(foobarUppercase).toString('hex');19export const foobarObject = {foo: 'bar'};20export const foobarObjectString = JSON.stringify(foobarObject);
added:test/helpers/map.js+62 added
1import {2 addNoopGenerator,3 noopGenerator,4 serializeGenerator,5 uppercaseBufferGenerator,6 uppercaseGenerator,7 getOutputGenerator,8 outputObjectGenerator,9 getOutputsGenerator,10 noYieldGenerator,11 multipleYieldGenerator,12 throwingGenerator,13 appendGenerator,14 timeoutGenerator,15} from './generator.js';16import {17 addNoopDuplex,18 noopDuplex,19 serializeDuplex,20 uppercaseBufferDuplex,21 getOutputDuplex,22 outputObjectDuplex,23 getOutputsDuplex,24 noYieldDuplex,25 multipleYieldDuplex,26 throwingDuplex,27 appendDuplex,28 timeoutDuplex,29} from './duplex.js';3031export const generatorsMap = {32 generator: {33 addNoop: addNoopGenerator,34 noop: noopGenerator,35 serialize: serializeGenerator,36 uppercaseBuffer: uppercaseBufferGenerator,37 uppercase: uppercaseGenerator,38 getOutput: getOutputGenerator,39 outputObject: outputObjectGenerator,40 getOutputs: getOutputsGenerator,41 noYield: noYieldGenerator,42 multipleYield: multipleYieldGenerator,43 throwing: throwingGenerator,44 append: appendGenerator,45 timeout: timeoutGenerator,46 },47 duplex: {48 addNoop: addNoopDuplex,49 noop: noopDuplex,50 serialize: serializeDuplex,51 uppercaseBuffer: uppercaseBufferDuplex,52 uppercase: uppercaseBufferDuplex,53 getOutput: getOutputDuplex,54 outputObject: outputObjectDuplex,55 getOutputs: getOutputsDuplex,56 noYield: noYieldDuplex,57 multipleYield: multipleYieldDuplex,58 throwing: throwingDuplex,59 append: appendDuplex,60 timeout: timeoutDuplex,61 },62};
added:test/stdio/duplex.js+57 added
1import {createHash} from 'node:crypto';2import {promisify} from 'node:util';3import {createGzip, gunzip} from 'node:zlib';4import test from 'ava';5import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {foobarString, foobarObject, foobarUppercase, foobarUppercaseHex} from '../helpers/input.js';8import {uppercaseEncodingDuplex, getOutputDuplex} from '../helpers/duplex.js';910setFixtureDir();1112test('Can use crypto.createHash()', async t => {13 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createHash('sha1')}, encoding: 'hex'});14 const expectedStdout = createHash('sha1').update(foobarString).digest('hex');15 t.is(stdout, expectedStdout);16});1718test('Can use zlib.createGzip()', async t => {19 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createGzip()}, encoding: 'buffer'});20 const decompressedStdout = await promisify(gunzip)(stdout);21 t.is(decompressedStdout.toString(), foobarString);22});2324test('Can use encoding "hex"', async t => {25 const {transform} = uppercaseEncodingDuplex('hex')();26 t.is(transform.readableEncoding, 'hex');27 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform}});28 t.is(stdout, foobarUppercaseHex);29});3031test('Cannot use objectMode: true with duplex.readableObjectMode: false', t => {32 t.throws(() => {33 execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, false)(true)});34 }, {message: /cannot be `false` if `new Duplex\({objectMode: true}\)`/});35});3637test('Cannot use objectMode: false with duplex.readableObjectMode: true', t => {38 t.throws(() => {39 execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, true)(false)});40 }, {message: /can only be `true` if `new Duplex\({objectMode: true}\)`/});41});4243const testObjectModeFalse = async (t, objectMode) => {44 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: uppercaseEncodingDuplex(undefined, objectMode)(false)});45 t.is(stdout, foobarUppercase);46};4748test('Can use objectMode: false with duplex.readableObjectMode: false', testObjectModeFalse, false);49test('Can use objectMode: undefined with duplex.readableObjectMode: false', testObjectModeFalse, undefined);5051const testObjectModeTrue = async (t, objectMode) => {52 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: getOutputDuplex(foobarObject, objectMode)(true)});53 t.deepEqual(stdout, [foobarObject]);54};5556test('Can use objectMode: true with duplex.readableObjectMode: true', testObjectModeTrue, true);57test('Can use objectMode: undefined with duplex.readableObjectMode: true', testObjectModeTrue, undefined);
modified:test/stdio/generator.js+242 added-130 removed
15 unmodified lines
16 foobarObject,17 foobarObjectString,18} from '../helpers/input.js';19import {20 addNoopGenerator,21 serializeGenerator,20 outputObjectGenerator,21 uppercaseGenerator,22 uppercaseBufferGenerator,23 appendGenerator,24 casedSuffix,25} from '../helpers/generator.js';26import {appendDuplex, uppercaseBufferDuplex} from '../helpers/duplex.js';27import {generatorsMap} from '../helpers/map.js';2829setFixtureDir();3031const textEncoder = new TextEncoder();3233const getInputObjectMode = (objectMode, addNoopTransform) => objectMode33const getInputObjectMode = (objectMode, addNoopTransform, type) => objectMode34 ? {35 input: [foobarObject],36 generators: addNoopGenerator(serializeGenerator(objectMode), addNoopTransform, objectMode),36 generators: generatorsMap[type].addNoop(generatorsMap[type].serialize(objectMode), addNoopTransform, objectMode),37 output: foobarObjectString,38 }39 : {40 input: foobarUint8Array,41 generators: addNoopGenerator(uppercaseGenerator(objectMode), addNoopTransform, objectMode),41 generators: generatorsMap[type].addNoop(generatorsMap[type].uppercase(objectMode), addNoopTransform, objectMode),42 output: foobarUppercase,43 };4445const getOutputObjectMode = (objectMode, addNoopTransform, binary) => objectMode45const getOutputObjectMode = (objectMode, addNoopTransform, type, binary) => objectMode46 ? {47 generators: addNoopGenerator(outputObjectGenerator(), addNoopTransform, objectMode, binary),47 generators: generatorsMap[type].addNoop(generatorsMap[type].outputObject(), addNoopTransform, objectMode, binary),48 output: [foobarObject],49 getStreamMethod: getStreamAsArray,50 }51 : {52 generators: addNoopGenerator(uppercaseBufferGenerator(objectMode, true), addNoopTransform, objectMode, binary),52 generators: generatorsMap[type].addNoop(generatorsMap[type].uppercaseBuffer(objectMode, true), addNoopTransform, objectMode, binary),53 output: foobarUppercase,54 getStreamMethod: getStream,55 };5657// eslint-disable-next-line max-params57const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform) => {58 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform);58const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform, type) => {59 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);60 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, ...generators]));61 t.is(stdout, output);62};6363test('Can use generators with result.stdin', testGeneratorInput, 0, false, false);64test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false);65test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false);66test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false);67test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true);68test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true);69test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true);70test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true);64test('Can use generators with result.stdin', testGeneratorInput, 0, false, false, 'generator');65test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'generator');66test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'generator');67test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'generator');68test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'generator');69test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'generator');70test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'generator');71test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'generator');72test('Can use duplexes with result.stdin', testGeneratorInput, 0, false, false, 'duplex');73test('Can use duplexes with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'duplex');74test('Can use duplexes with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'duplex');75test('Can use duplexes with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'duplex');76test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex');77test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex');78test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex');79test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex');8081// eslint-disable-next-line max-params73const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, input) => {74 const {generators, output} = getInputObjectMode(objectMode, addNoopTransform);82const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {83 const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);84 const subprocess = execa('stdin-fd.js', ['0'], getStdio(0, generators));85 const stream = useShortcutProperty ? subprocess.stdin : subprocess.stdio[0];86 stream.end(...input);87 const {stdout} = await subprocess;88 t.is(stdout, output);89};9082test('Can use generators with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, [foobarString, 'utf8']);83test('Can use generators with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, [foobarString, 'utf8']);84test('Can use generators with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, [foobarBuffer, 'buffer']);85test('Can use generators with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, [foobarBuffer, 'buffer']);86test('Can use generators with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, [foobarHex, 'hex']);87test('Can use generators with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, [foobarHex, 'hex']);88test('Can use generators with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, [foobarObject]);89test('Can use generators with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, [foobarObject]);90test('Can use generators with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, [foobarString, 'utf8']);91test('Can use generators with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, [foobarString, 'utf8']);92test('Can use generators with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, [foobarBuffer, 'buffer']);93test('Can use generators with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, [foobarBuffer, 'buffer']);94test('Can use generators with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, [foobarHex, 'hex']);95test('Can use generators with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, [foobarHex, 'hex']);96test('Can use generators with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, [foobarObject]);97test('Can use generators with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, [foobarObject]);91test('Can use generators with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'generator', [foobarString, 'utf8']);92test('Can use generators with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'generator', [foobarString, 'utf8']);93test('Can use generators with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'generator', [foobarBuffer, 'buffer']);94test('Can use generators with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'generator', [foobarBuffer, 'buffer']);95test('Can use generators with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'generator', [foobarHex, 'hex']);96test('Can use generators with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'generator', [foobarHex, 'hex']);97test('Can use generators with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'generator', [foobarObject]);98test('Can use generators with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'generator', [foobarObject]);99test('Can use generators with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarString, 'utf8']);100test('Can use generators with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarString, 'utf8']);101test('Can use generators with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarBuffer, 'buffer']);102test('Can use generators with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarBuffer, 'buffer']);103test('Can use generators with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarHex, 'hex']);104test('Can use generators with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarHex, 'hex']);105test('Can use generators with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'generator', [foobarObject]);106test('Can use generators with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'generator', [foobarObject]);107test('Can use duplexes with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'duplex', [foobarString, 'utf8']);108test('Can use duplexes with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'duplex', [foobarString, 'utf8']);109test('Can use duplexes with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarBuffer, 'buffer']);110test('Can use duplexes with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarBuffer, 'buffer']);111test('Can use duplexes with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarHex, 'hex']);112test('Can use duplexes with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarHex, 'hex']);113test('Can use duplexes with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'duplex', [foobarObject]);114test('Can use duplexes with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'duplex', [foobarObject]);115test('Can use duplexes with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarString, 'utf8']);116test('Can use duplexes with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarString, 'utf8']);117test('Can use duplexes with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarBuffer, 'buffer']);118test('Can use duplexes with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarBuffer, 'buffer']);119test('Can use duplexes with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarHex, 'hex']);120test('Can use duplexes with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarHex, 'hex']);121test('Can use duplexes with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'duplex', [foobarObject]);122test('Can use duplexes with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'duplex', [foobarObject]);12399const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform) => {100 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform);124const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform, type) => {125 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);126 const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, [[], ...generators]));127 subprocess.stdio[3].write(Array.isArray(input) ? input[0] : input);128 const {stdout} = await subprocess;129 t.is(stdout, output);130};131107test('Can use generators with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false);108test('Can use generators with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false);109test('Can use generators with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true);110test('Can use generators with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true);132test('Can use generators with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'generator');133test('Can use generators with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'generator');134test('Can use generators with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'generator');135test('Can use generators with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'generator');136test('Can use duplexes with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'duplex');137test('Can use duplexes with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'duplex');138test('Can use duplexes with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'duplex');139test('Can use duplexes with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'duplex');140141// eslint-disable-next-line max-params113const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform) => {114 const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform);142const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type) => {143 const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);144 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';145 const {stdout, stderr, stdio} = await execa(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generators), reject});146 const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];147 t.deepEqual(result, output);148};149121test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false);122test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false);123test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false);124test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false);125test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false);126test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false);127test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false);128test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false);129test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false);130test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false);131test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false);132test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false);133test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false);134test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false);135test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false);136test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false);137test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false);138test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false);139test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false);140test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false);141test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true);142test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true);143test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true);144test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true);145test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true);146test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true);147test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true);148test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true);149test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true);150test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true);151test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true);152test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true);153test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true);154test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true);155test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true);156test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true);157test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true);158test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true);159test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true);160test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true);150test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'generator');151test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'generator');152test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'generator');153test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'generator');154test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'generator');155test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'generator');156test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'generator');157test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'generator');158test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'generator');159test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'generator');160test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'generator');161test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'generator');162test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'generator');163test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'generator');164test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'generator');165test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'generator');166test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'generator');167test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'generator');168test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'generator');169test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'generator');170test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'generator');171test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'generator');172test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'generator');173test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'generator');174test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'generator');175test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'generator');176test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'generator');177test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'generator');178test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'generator');179test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'generator');180test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'generator');181test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'generator');182test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'generator');183test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'generator');184test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'generator');185test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'generator');186test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'generator');187test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'generator');188test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'generator');189test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'generator');190test('Can use duplexes with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'duplex');191test('Can use duplexes with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'duplex');192test('Can use duplexes with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'duplex');193test('Can use duplexes with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'duplex');194test('Can use duplexes with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'duplex');195test('Can use duplexes with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'duplex');196test('Can use duplexes with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'duplex');197test('Can use duplexes with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'duplex');198test('Can use duplexes with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'duplex');199test('Can use duplexes with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'duplex');200test('Can use duplexes with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'duplex');201test('Can use duplexes with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'duplex');202test('Can use duplexes with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'duplex');203test('Can use duplexes with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'duplex');204test('Can use duplexes with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'duplex');205test('Can use duplexes with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'duplex');206test('Can use duplexes with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'duplex');207test('Can use duplexes with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'duplex');208test('Can use duplexes with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'duplex');209test('Can use duplexes with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'duplex');210test('Can use duplexes with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'duplex');211test('Can use duplexes with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'duplex');212test('Can use duplexes with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'duplex');213test('Can use duplexes with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'duplex');214test('Can use duplexes with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'duplex');215test('Can use duplexes with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'duplex');216test('Can use duplexes with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'duplex');217test('Can use duplexes with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'duplex');218test('Can use duplexes with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'duplex');219test('Can use duplexes with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'duplex');220test('Can use duplexes with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'duplex');221test('Can use duplexes with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'duplex');222test('Can use duplexes with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'duplex');223test('Can use duplexes with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'duplex');224test('Can use duplexes with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'duplex');225test('Can use duplexes with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'duplex');226test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex');227test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex');228test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex');229test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex');230231// eslint-disable-next-line max-params163const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform) => {164 const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, true);232const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {233 const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);234 const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, generators));235 const stream = useShortcutProperty ? [subprocess.stdout, subprocess.stderr][fdNumber - 1] : subprocess.stdio[fdNumber];236 const [result] = await Promise.all([getStreamMethod(stream), subprocess]);237 t.deepEqual(result, output);238};239171test('Can use generators with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false);172test('Can use generators with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false);173test('Can use generators with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false);174test('Can use generators with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false);175test('Can use generators with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false);176test('Can use generators with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false);177test('Can use generators with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false);178test('Can use generators with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false);179test('Can use generators with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false);180test('Can use generators with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false);181test('Can use generators with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true);182test('Can use generators with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true);183test('Can use generators with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true);184test('Can use generators with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true);185test('Can use generators with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true);186test('Can use generators with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true);187test('Can use generators with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true);188test('Can use generators with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true);189test('Can use generators with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true);190test('Can use generators with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true);240test('Can use generators with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'generator');241test('Can use generators with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'generator');242test('Can use generators with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'generator');243test('Can use generators with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'generator');244test('Can use generators with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'generator');245test('Can use generators with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'generator');246test('Can use generators with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'generator');247test('Can use generators with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'generator');248test('Can use generators with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'generator');249test('Can use generators with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'generator');250test('Can use generators with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'generator');251test('Can use generators with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'generator');252test('Can use generators with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'generator');253test('Can use generators with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'generator');254test('Can use generators with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'generator');255test('Can use generators with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'generator');256test('Can use generators with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'generator');257test('Can use generators with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'generator');258test('Can use generators with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'generator');259test('Can use generators with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'generator');260test('Can use duplexes with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'duplex');261test('Can use duplexes with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'duplex');262test('Can use duplexes with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'duplex');263test('Can use duplexes with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'duplex');264test('Can use duplexes with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'duplex');265test('Can use duplexes with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'duplex');266test('Can use duplexes with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'duplex');267test('Can use duplexes with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'duplex');268test('Can use duplexes with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'duplex');269test('Can use duplexes with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'duplex');270test('Can use duplexes with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'duplex');271test('Can use duplexes with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'duplex');272test('Can use duplexes with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'duplex');273test('Can use duplexes with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'duplex');274test('Can use duplexes with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'duplex');275test('Can use duplexes with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'duplex');276test('Can use duplexes with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'duplex');277test('Can use duplexes with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'duplex');278test('Can use duplexes with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'duplex');279test('Can use duplexes with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'duplex');280281const getAllStdioOption = (stdioOption, encoding, objectMode) => {282 if (stdioOption) {283 return 'pipe';
86 unmodified lines
370test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false);371test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false);372test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false);373285test('Can use generators with input option', async t => {286 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: uppercaseGenerator(), input: foobarUint8Array});374const testInputOption = async (t, type) => {375 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});376 t.is(stdout, foobarUppercase);288});377};378379test('Can use generators with input option', testInputOption, 'generator');380test('Can use duplexes with input option', testInputOption, 'duplex');381382const testInputFile = async (t, getOptions, reversed) => {383 const filePath = tempfile();384 await writeFile(filePath, foobarString);385 const {stdin, ...options} = getOptions(filePath);
5 unmodified lines
391392test('Can use generators with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseGenerator()]}), false);393test('Can use generators with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseGenerator()]}), true);394test('Can use generators with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseGenerator()}), false);395test('Can use duplexes with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), false);396test('Can use duplexes with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), true);397test('Can use duplexes with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferDuplex()}), false);398304const testOutputFile = async (t, reversed) => {399const testOutputFile = async (t, reversed, type) => {400 const filePath = tempfile();306 const stdoutOption = [uppercaseBufferGenerator(false, true), {file: filePath}];401 const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];402 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;403 const {stdout} = await execa('noop-fd.js', ['1'], {stdout: reversedStdoutOption});404 t.is(stdout, foobarUppercase);405 t.is(await readFile(filePath, 'utf8'), foobarUppercase);406 await rm(filePath);407};408314test('Can use generators with a file as output', testOutputFile, false);315test('Can use generators with a file as output, reversed', testOutputFile, true);409test('Can use generators with a file as output', testOutputFile, false, 'generator');410test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator');411test('Can use duplexes with a file as output', testOutputFile, false, 'duplex');412test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex');413317test('Can use generators to a Writable stream', async t => {414const testWritableDestination = async (t, type) => {415 const passThrough = new PassThrough();416 const [{stdout}, streamOutput] = await Promise.all([320 execa('noop-fd.js', ['1', foobarString], {stdout: [uppercaseBufferGenerator(false, true), passThrough]}),417 execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].uppercaseBuffer(false, true), passThrough]}),418 getStream(passThrough),419 ]);420 t.is(stdout, foobarUppercase);421 t.is(streamOutput, foobarUppercase);325});422};423327test('Can use generators from a Readable stream', async t => {424test('Can use generators to a Writable stream', testWritableDestination, 'generator');425test('Can use duplexes to a Writable stream', testWritableDestination, 'duplex');426427const testReadableSource = async (t, type) => {428 const passThrough = new PassThrough();329 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, uppercaseGenerator()]});429 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});430 passThrough.end(foobarString);431 const {stdout} = await subprocess;432 t.is(stdout, foobarUppercase);333});433};434335test('Can use generators with "inherit"', async t => {336 const {stdout} = await execa('nested-inherit.js');435test('Can use generators from a Readable stream', testReadableSource, 'generator');436test('Can use duplexes from a Readable stream', testReadableSource, 'duplex');437438const testInherit = async (t, type) => {439 const {stdout} = await execa('nested-inherit.js', [type]);440 t.is(stdout, foobarUppercase);338});441};442443test('Can use generators with "inherit"', testInherit, 'generator');444test('Can use duplexes with "inherit"', testInherit, 'duplex');445340const testAppendInput = async (t, reversed) => {341 const stdin = [foobarUint8Array, uppercaseGenerator(), appendGenerator()];446const testAppendInput = async (t, reversed, type) => {447 const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];448 const reversedStdin = reversed ? stdin.reverse() : stdin;449 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: reversedStdin});450 const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;451 t.is(stdout, `${foobarUppercase}${reversedSuffix}`);452};453348test('Can use multiple generators as input', testAppendInput, false);349test('Can use multiple generators as input, reversed', testAppendInput, true);454test('Can use multiple generators as input', testAppendInput, false, 'generator');455test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator');456test('Can use multiple duplexes as input', testAppendInput, false, 'duplex');457test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex');458351const testAppendOutput = async (t, reversed) => {352 const stdoutOption = [uppercaseGenerator(), appendGenerator()];459const testAppendOutput = async (t, reversed, type) => {460 const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];461 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;462 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: reversedStdoutOption});463 const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;464 t.is(stdout, `${foobarUppercase}${reversedSuffix}`);465};466359test('Can use multiple generators as output', testAppendOutput, false);360test('Can use multiple generators as output, reversed', testAppendOutput, true);467test('Can use multiple generators as output', testAppendOutput, false, 'generator');468test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator');469test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex');470test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex');471472const testTwoGenerators = async (t, producesTwo, firstGenerator, secondGenerator = firstGenerator) => {473 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});474 const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;
1 unmodified line
476};477478test('Can use multiple identical generators', testTwoGenerators, true, appendGenerator().transform);479test('Can use multiple identical generators, options object', testTwoGenerators, true, appendGenerator());480test('Ignore duplicate identical duplexes', testTwoGenerators, false, appendDuplex());481test('Can use multiple generators with duplexes', testTwoGenerators, true, appendGenerator(false, false, true), appendDuplex());482483const testGeneratorSyntax = async (t, generator) => {484 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: generator});485 t.is(stdout, foobarUppercase);
4 unmodified lines
modified:test/stdio/transform.js+53 added-38 removed
7 unmodified lines
8import {9 noopGenerator,10 getOutputAsyncGenerator,11 getOutputGenerator,12 getOutputsGenerator,12 infiniteGenerator,13 outputObjectGenerator,15 noYieldGenerator,16 multipleYieldGenerator,14 convertTransformToFinal,15 prefix,16 suffix,20 throwingGenerator,17 GENERATOR_ERROR_REGEXP,22 timeoutGenerator,18} from '../helpers/generator.js';19import {generatorsMap} from '../helpers/map.js';20import {defaultHighWaterMark} from '../helpers/stream.js';21import {setFixtureDir} from '../helpers/fixtures-dir.js';2223setFixtureDir();
52 unmodified lines
76test('Synchronous yields are not buffered, line-wise passThrough', testHighWaterMark, true, false, false);77test('Synchronous yields are not buffered, binary passThrough', testHighWaterMark, true, true, false);78test('Synchronous yields are not buffered, objectMode as input but not output', testHighWaterMark, false, false, true);7980// eslint-disable-next-line max-params84const testNoYield = async (t, objectMode, final, output) => {85 const {stdout} = await execa('noop.js', {stdout: convertTransformToFinal(noYieldGenerator(objectMode), final)});81const testNoYield = async (t, type, objectMode, final, output) => {82 const {stdout} = await execa('noop.js', {stdout: convertTransformToFinal(generatorsMap[type].noYield(objectMode), final)});83 t.deepEqual(stdout, output);84};8589test('Generator can filter "transform" by not calling yield', testNoYield, false, false, '');90test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, true, false, []);91test('Generator can filter "final" by not calling yield', testNoYield, false, true, '');92test('Generator can filter "final" by not calling yield, objectMode', testNoYield, true, true, []);86test('Generator can filter "transform" by not calling yield', testNoYield, 'generator', false, false, '');87test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, 'generator', true, false, []);88test('Generator can filter "final" by not calling yield', testNoYield, 'generator', false, true, '');89test('Generator can filter "final" by not calling yield, objectMode', testNoYield, 'generator', true, true, []);90test('Duplex can filter by not calling push', testNoYield, 'duplex', false, false, '');91test('Duplex can filter by not calling push, objectMode', testNoYield, 'duplex', true, false, []);9294const testMultipleYields = async (t, final) => {95 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(multipleYieldGenerator(), final)});96 t.is(stdout, `${prefix}\n${foobarString}\n${suffix}`);93const testMultipleYields = async (t, type, final, binary) => {94 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});95 const newline = binary ? '' : '\n';96 t.is(stdout, `${prefix}${newline}${foobarString}${newline}${suffix}`);97};9899test('Generator can yield "transform" multiple times at different moments', testMultipleYields, false);100test('Generator can yield "final" multiple times at different moments', testMultipleYields, true);99test('Generator can yield "transform" multiple times at different moments', testMultipleYields, 'generator', false, false);100test('Generator can yield "final" multiple times at different moments', testMultipleYields, 'generator', true, false);101test('Duplex can push multiple times at different moments', testMultipleYields, 'duplex', false, true);102103const partsPerChunk = 4;104const chunksPerCall = 10;105const callCount = 5;
23 unmodified lines
129test('Generator "final" yields are sent right away', testManyYields, true);130131const maxBuffer = 10;132132test('Generators take "maxBuffer" into account', async t => {133const testMaxBuffer = async (t, type) => {134 const bigString = '.'.repeat(maxBuffer);135 const {stdout} = await execa('noop.js', {136 maxBuffer,136 stdout: getOutputGenerator(bigString)(false, true),137 stdout: generatorsMap[type].getOutput(bigString)(false, true),138 });139 t.is(stdout, bigString);140140 await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: getOutputGenerator(`${bigString}.`)(false)}));141});141 await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: generatorsMap[type].getOutput(`${bigString}.`)(false)}));142};143143test('Generators take "maxBuffer" into account, objectMode', async t => {144test('Generators take "maxBuffer" into account', testMaxBuffer, 'generator');145test('Duplexes take "maxBuffer" into account', testMaxBuffer, 'duplex');146147const testMaxBufferObject = async (t, type) => {148 const bigArray = Array.from({length: maxBuffer}).fill('.');149 const {stdout} = await execa('noop.js', {150 maxBuffer,147 stdout: getOutputsGenerator(bigArray)(true, true),151 stdout: generatorsMap[type].getOutputs(bigArray)(true, true),152 });153 t.is(stdout.length, maxBuffer);154151 await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: getOutputsGenerator([...bigArray, ''])(true)}));152});155 await t.throwsAsync(execa('noop.js', {maxBuffer, stdout: generatorsMap[type].getOutputs([...bigArray, ''])(true)}));156};157158test('Generators take "maxBuffer" into account, objectMode', testMaxBufferObject, 'generator');159test('Duplexes take "maxBuffer" into account, objectMode', testMaxBufferObject, 'duplex');160154const testAsyncGenerators = async (t, final) => {161const testAsyncGenerators = async (t, type, final) => {162 const {stdout} = await execa('noop.js', {156 stdout: convertTransformToFinal(timeoutGenerator(1e2)(), final),163 stdout: convertTransformToFinal(generatorsMap[type].timeout(1e2)(), final),164 });165 t.is(stdout, foobarString);166};167161test('Generators "transform" is awaited on success', testAsyncGenerators, false);162test('Generators "final" is awaited on success', testAsyncGenerators, true);168test('Generators "transform" is awaited on success', testAsyncGenerators, 'generator', false);169test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);170test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);171164const testThrowingGenerator = async (t, final) => {172const testThrowingGenerator = async (t, type, final) => {173 await t.throwsAsync(166 execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(throwingGenerator(), final)}),174 execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].throwing(), final)}),175 {message: GENERATOR_ERROR_REGEXP},176 );177};178171test('Generators "transform" errors make subprocess fail', testThrowingGenerator, false);172test('Generators "final" errors make subprocess fail', testThrowingGenerator, true);179test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false);180test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true);181test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false);182174test('Generators errors make subprocess fail even when other output generators do not throw', async t => {183const testSingleErrorOutput = async (t, type) => {184 await t.throwsAsync(176 execa('noop-fd.js', ['1', foobarString], {stdout: [noopGenerator(false), throwingGenerator(), noopGenerator(false)]}),185 execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]}),186 {message: GENERATOR_ERROR_REGEXP},187 );179});188};189181test('Generators errors make subprocess fail even when other input generators do not throw', async t => {182 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [noopGenerator(false), throwingGenerator(), noopGenerator(false)]});190test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator');191test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex');192193const testSingleErrorInput = async (t, type) => {194 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]});195 subprocess.stdin.write('foobar\n');196 await t.throwsAsync(subprocess, {message: GENERATOR_ERROR_REGEXP});185});197};198199test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator');200test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex');201202const testGeneratorCancel = async (t, error) => {203 const subprocess = execa('noop.js', {stdout: infiniteGenerator()});204 await once(subprocess.stdout, 'data');205 subprocess.stdout.destroy(error);
20 unmodified lines
modified:test/stdio/type.js+60 added-10 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {getStdio} from '../helpers/stdio.js';4import {noopGenerator, uppercaseGenerator} from '../helpers/generator.js';5import {uppercaseBufferDuplex} from '../helpers/duplex.js';6import {generatorsMap} from '../helpers/map.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';89setFixtureDir();10
11 unmodified lines
22test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true});23test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true});24test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true});2524const testInvalidBinary = (t, fdNumber, optionName) => {26const testInvalidBinary = (t, fdNumber, optionName, type) => {27 t.throws(() => {26 execa('empty.js', getStdio(fdNumber, {...uppercaseGenerator(), [optionName]: 'true'}));28 execa('empty.js', getStdio(fdNumber, {...generatorsMap[type].uppercase(), [optionName]: 'true'}));29 }, {message: /a boolean/});30};3130test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary');31test('Cannot use invalid "binary" with stdout', testInvalidBinary, 1, 'binary');32test('Cannot use invalid "binary" with stderr', testInvalidBinary, 2, 'binary');33test('Cannot use invalid "binary" with stdio[*]', testInvalidBinary, 3, 'binary');34test('Cannot use invalid "objectMode" with stdin', testInvalidBinary, 0, 'objectMode');35test('Cannot use invalid "objectMode" with stdout', testInvalidBinary, 1, 'objectMode');36test('Cannot use invalid "objectMode" with stderr', testInvalidBinary, 2, 'objectMode');37test('Cannot use invalid "objectMode" with stdio[*]', testInvalidBinary, 3, 'objectMode');32test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary', 'generator');33test('Cannot use invalid "binary" with stdout', testInvalidBinary, 1, 'binary', 'generator');34test('Cannot use invalid "binary" with stderr', testInvalidBinary, 2, 'binary', 'generator');35test('Cannot use invalid "binary" with stdio[*]', testInvalidBinary, 3, 'binary', 'generator');36test('Cannot use invalid "objectMode" with stdin, generators', testInvalidBinary, 0, 'objectMode', 'generator');37test('Cannot use invalid "objectMode" with stdout, generators', testInvalidBinary, 1, 'objectMode', 'generator');38test('Cannot use invalid "objectMode" with stderr, generators', testInvalidBinary, 2, 'objectMode', 'generator');39test('Cannot use invalid "objectMode" with stdio[*], generators', testInvalidBinary, 3, 'objectMode', 'generator');40test('Cannot use invalid "objectMode" with stdin, duplexes', testInvalidBinary, 0, 'objectMode', 'duplex');41test('Cannot use invalid "objectMode" with stdout, duplexes', testInvalidBinary, 1, 'objectMode', 'duplex');42test('Cannot use invalid "objectMode" with stderr, duplexes', testInvalidBinary, 2, 'objectMode', 'duplex');43test('Cannot use invalid "objectMode" with stdio[*], duplexes', testInvalidBinary, 3, 'objectMode', 'duplex');4445const testUndefinedOption = (t, fdNumber, optionName, optionValue) => {46 t.throws(() => {47 execa('empty.js', getStdio(fdNumber, {...uppercaseBufferDuplex(), [optionName]: optionValue}));48 }, {message: /can only be defined when using a generator/});49};5051test('Cannot use "binary" with duplexes and stdin', testUndefinedOption, 0, 'binary', true);52test('Cannot use "binary" with duplexes and stdout', testUndefinedOption, 1, 'binary', true);53test('Cannot use "binary" with duplexes and stderr', testUndefinedOption, 2, 'binary', true);54test('Cannot use "binary" with duplexes and stdio[*]', testUndefinedOption, 3, 'binary', true);55test('Cannot use "final" with duplexes and stdin', testUndefinedOption, 0, 'final', uppercaseBufferDuplex().transform);56test('Cannot use "final" with duplexes and stdout', testUndefinedOption, 1, 'final', uppercaseBufferDuplex().transform);57test('Cannot use "final" with duplexes and stderr', testUndefinedOption, 2, 'final', uppercaseBufferDuplex().transform);58test('Cannot use "final" with duplexes and stdio[*]', testUndefinedOption, 3, 'final', uppercaseBufferDuplex().transform);5960const testUndefinedFinal = (t, fdNumber, useTransform) => {61 t.throws(() => {62 execa('empty.js', getStdio(fdNumber, {63 transform: useTransform ? uppercaseGenerator().transform : undefined,64 final: uppercaseBufferDuplex().transform,65 }));66 }, {message: /must not be a Duplex/});67};6869test('Cannot use "final" with duplexes and stdin, without transform', testUndefinedFinal, 0, false);70test('Cannot use "final" with duplexes and stdout, without transform', testUndefinedFinal, 1, false);71test('Cannot use "final" with duplexes and stderr, without transform', testUndefinedFinal, 2, false);72test('Cannot use "final" with duplexes and stdio[*], without transform', testUndefinedFinal, 3, false);73test('Cannot use "final" with duplexes and stdin, with transform', testUndefinedFinal, 0, true);74test('Cannot use "final" with duplexes and stdout, with transform', testUndefinedFinal, 1, true);75test('Cannot use "final" with duplexes and stderr, with transform', testUndefinedFinal, 2, true);76test('Cannot use "final" with duplexes and stdio[*], with transform', testUndefinedFinal, 3, true);7778const testSyncMethodsGenerator = (t, fdNumber) => {79 t.throws(() => {80 execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator()));81 }, {message: /cannot be a generator/});
2 unmodified lines
84test('Cannot use generators with sync methods and stdin', testSyncMethodsGenerator, 0);85test('Cannot use generators with sync methods and stdout', testSyncMethodsGenerator, 1);86test('Cannot use generators with sync methods and stderr', testSyncMethodsGenerator, 2);87test('Cannot use generators with sync methods and stdio[*]', testSyncMethodsGenerator, 3);8889const testSyncMethodsDuplex = (t, fdNumber) => {90 t.throws(() => {91 execaSync('empty.js', getStdio(fdNumber, uppercaseBufferDuplex()));92 }, {message: /cannot be a Duplex stream/});93};9495test('Cannot use duplexes with sync methods and stdin', testSyncMethodsDuplex, 0);96test('Cannot use duplexes with sync methods and stdout', testSyncMethodsDuplex, 1);97test('Cannot use duplexes with sync methods and stderr', testSyncMethodsDuplex, 2);98test('Cannot use duplexes with sync methods and stdio[*]', testSyncMethodsDuplex, 3);
modified:test/verbose/output.js+6 added-3 removed
119 unmodified lines
120121test('Does not change stdout', testStdioSame, 1);122test('Does not change stderr', testStdioSame, 2);123124test('Prints stdout with only transforms', async t => {125 const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full'});124const testOnlyTransforms = async (t, type) => {125 const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type});126 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);127});127};128129test('Prints stdout with only transforms', testOnlyTransforms, 'generator');130test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex');131132test('Prints stdout with object transforms', async t => {133 const {stderr} = await nestedExeca('nested-object.js', 'noop.js', {verbose: 'full'});134 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);135});
107 unmodified lines
modified:index.d.ts+19 added-7 removed
30 unmodified lines
31 preserveNewlines?: boolean;32 objectMode?: boolean;33};3435type DuplexTransform = {36 transform: Duplex;37 objectMode?: boolean;38};3940type CommonStdioOption<IsSync extends boolean = boolean> =41 | BaseStdioOption42 | 'ipc'43 | number
1 unmodified line
45 | URL46 | {file: string}47 | IfAsync<IsSync,48 | GeneratorTransform44 | GeneratorTransformFull>;49 | GeneratorTransformFull50 | DuplexTransform>;5152type InputStdioOption<IsSync extends boolean = boolean> =53 | Uint8Array54 | Readable
72 unmodified lines
127>;128129type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull130 ? BooleanObjectMode<OutputOption['objectMode']>131 : OutputOption extends DuplexTransform132 ? DuplexObjectMode<OutputOption>125 : false;133 : false;134135type BooleanObjectMode<ObjectModeOption extends GeneratorTransformFull['objectMode']> = ObjectModeOption extends true ? true : false;136137type DuplexObjectMode<OutputOption extends DuplexTransform> = OutputOption['objectMode'] extends boolean138 ? OutputOption['objectMode']139 : OutputOption['transform']['readableObjectMode'];140141// Whether `result.stdout|stderr|all` is `undefined`, excluding the `buffer` option142type IgnoresStreamResult<143 FdNumber extends string,144 OptionsType extends CommonOptions = CommonOptions,
211 unmodified lines
356 - an `Uint8Array`.357358 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.359348 This can also be a generator function to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)360 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) to transform the input. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)361362 @default `inherit` with `$`, `pipe` otherwise363 */364 readonly stdin?: StdinOption<IsSync>;
11 unmodified lines
376 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).377378 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.379368 This can also be a generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)380 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)381382 @default 'pipe'383 */384 readonly stdout?: StdoutStderrOption<IsSync>;
11 unmodified lines
396 - a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).397398 This can be an [array of values](https://github.com/sindresorhus/execa#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.399388 This can also be a generator function to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)400 This can also be a generator function or a [`Duplex`](https://nodejs.org/api/stream.html#class-streamduplex) to transform the output. [Learn more.](https://github.com/sindresorhus/execa/tree/main/docs/transform.md)401402 @default 'pipe'403 */404 readonly stderr?: StdoutStderrOption<IsSync>;
940 unmodified lines
1345Same as `execa()` but synchronous.13461347Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.13481337Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1349Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.13501351@param file - The program/script to execute, as a string or file URL1352@param arguments - Arguments to pass to `file` on execution.1353@returns A `subprocessResult` object
105 unmodified lines
1459Same as `execaCommand()` but synchronous.14601461Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14621451Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1463Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14641465@param command - The program/script to execute and its arguments.1466@returns A `subprocessResult` object1467@throws A `subprocessResult` error
128 unmodified lines
modified:index.test-d.ts+124 added-1 removed
1// For some reason a default import of `process` causes2// `process.stdin`, `process.stderr`, and `process.stdout`3// to get treated as `any` by `@typescript-eslint/no-unsafe-assignment`.4import * as process from 'node:process';5import {Readable, Writable, type Duplex} from 'node:stream';5import {Readable, Writable, Duplex, Transform} from 'node:stream';6import {createWriteStream} from 'node:fs';7import {expectType, expectNotType, expectError, expectAssignable, expectNotAssignable} from 'tsd';8import {9 $,
11 unmodified lines
21 type ExecaSyncResult,22} from './index.js';2324const fileUrl = new URL('file:///test');25const duplexStream = new Duplex();26const duplex = {transform: duplexStream};27const duplexObject = {transform: duplexStream as Duplex & {readableObjectMode: true}};28const duplexNotObject = {transform: duplexStream as Duplex & {readableObjectMode: false}};29const duplexObjectProperty = {transform: duplexStream, objectMode: true as const};30const duplexNotObjectProperty = {transform: duplexStream, objectMode: false as const};31const duplexTransform = {transform: new Transform()};3233type AnySyncChunk = string | Uint8Array | undefined;34type AnyChunk = AnySyncChunk | string[] | unknown[];35expectType<Writable | null>({} as ExecaSubprocess['stdin']);
637 unmodified lines
673 const objectTransformLinesStdoutResult = await execa('unicorns', {lines: true, stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});674 expectType<unknown[]>(objectTransformLinesStdoutResult.stdout);675 expectType<[undefined, unknown[], string[]]>(objectTransformLinesStdoutResult.stdio);676677 const objectDuplexStdoutResult = await execa('unicorns', {stdout: duplexObject});678 expectType<unknown[]>(objectDuplexStdoutResult.stdout);679 expectType<[undefined, unknown[], string]>(objectDuplexStdoutResult.stdio);680681 const objectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: duplexObjectProperty});682 expectType<unknown[]>(objectDuplexPropertyStdoutResult.stdout);683 expectType<[undefined, unknown[], string]>(objectDuplexPropertyStdoutResult.stdio);684685 const objectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: true}});686 expectType<unknown[]>(objectTransformStdoutResult.stdout);687 expectType<[undefined, unknown[], string]>(objectTransformStdoutResult.stdio);688689 const objectDuplexStderrResult = await execa('unicorns', {stderr: duplexObject});690 expectType<unknown[]>(objectDuplexStderrResult.stderr);691 expectType<[undefined, string, unknown[]]>(objectDuplexStderrResult.stdio);692693 const objectDuplexPropertyStderrResult = await execa('unicorns', {stderr: duplexObjectProperty});694 expectType<unknown[]>(objectDuplexPropertyStderrResult.stderr);695 expectType<[undefined, string, unknown[]]>(objectDuplexPropertyStderrResult.stdio);696697 const objectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: true}});698 expectType<unknown[]>(objectTransformStderrResult.stderr);699 expectType<[undefined, string, unknown[]]>(objectTransformStderrResult.stdio);700701 const objectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexObject]});702 expectType<unknown[]>(objectDuplexStdioResult.stderr);703 expectType<[undefined, string, unknown[]]>(objectDuplexStdioResult.stdio);704705 const objectDuplexPropertyStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexObjectProperty]});706 expectType<unknown[]>(objectDuplexPropertyStdioResult.stderr);707 expectType<[undefined, string, unknown[]]>(objectDuplexPropertyStdioResult.stdio);708709 const objectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: true}]});710 expectType<unknown[]>(objectTransformStdioResult.stderr);711 expectType<[undefined, string, unknown[]]>(objectTransformStdioResult.stdio);712713 const singleObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject]});714 expectType<unknown[]>(singleObjectDuplexStdoutResult.stdout);715 expectType<[undefined, unknown[], string]>(singleObjectDuplexStdoutResult.stdio);716717 const singleObjectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: [duplexObjectProperty]});718 expectType<unknown[]>(singleObjectDuplexPropertyStdoutResult.stdout);719 expectType<[undefined, unknown[], string]>(singleObjectDuplexPropertyStdoutResult.stdio);720721 const singleObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}]});722 expectType<unknown[]>(singleObjectTransformStdoutResult.stdout);723 expectType<[undefined, unknown[], string]>(singleObjectTransformStdoutResult.stdio);724725 const manyObjectDuplexStdoutResult = await execa('unicorns', {stdout: [duplexObject, duplexObject]});726 expectType<unknown[]>(manyObjectDuplexStdoutResult.stdout);727 expectType<[undefined, unknown[], string]>(manyObjectDuplexStdoutResult.stdio);728729 const manyObjectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: [duplexObjectProperty, duplexObjectProperty]});730 expectType<unknown[]>(manyObjectDuplexPropertyStdoutResult.stdout);731 expectType<[undefined, unknown[], string]>(manyObjectDuplexPropertyStdoutResult.stdio);732733 const manyObjectTransformStdoutResult = await execa('unicorns', {stdout: [{transform: objectGenerator, final: objectFinal, objectMode: true}, {transform: objectGenerator, final: objectFinal, objectMode: true}]});734 expectType<unknown[]>(manyObjectTransformStdoutResult.stdout);735 expectType<[undefined, unknown[], string]>(manyObjectTransformStdoutResult.stdio);736737 const falseObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplexNotObject});738 expectType<string>(falseObjectDuplexStdoutResult.stdout);739 expectType<[undefined, string, string]>(falseObjectDuplexStdoutResult.stdio);740741 const falseObjectDuplexPropertyStdoutResult = await execa('unicorns', {stdout: duplexNotObjectProperty});742 expectType<string>(falseObjectDuplexPropertyStdoutResult.stdout);743 expectType<[undefined, string, string]>(falseObjectDuplexPropertyStdoutResult.stdio);744745 const falseObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal, objectMode: false}});746 expectType<string>(falseObjectTransformStdoutResult.stdout);747 expectType<[undefined, string, string]>(falseObjectTransformStdoutResult.stdio);748749 const falseObjectDuplexStderrResult = await execa('unicorns', {stderr: duplexNotObject});750 expectType<string>(falseObjectDuplexStderrResult.stderr);751 expectType<[undefined, string, string]>(falseObjectDuplexStderrResult.stdio);752753 const falseObjectDuplexPropertyStderrResult = await execa('unicorns', {stderr: duplexNotObjectProperty});754 expectType<string>(falseObjectDuplexPropertyStderrResult.stderr);755 expectType<[undefined, string, string]>(falseObjectDuplexPropertyStderrResult.stdio);756757 const falseObjectTransformStderrResult = await execa('unicorns', {stderr: {transform: objectGenerator, final: objectFinal, objectMode: false}});758 expectType<string>(falseObjectTransformStderrResult.stderr);759 expectType<[undefined, string, string]>(falseObjectTransformStderrResult.stdio);760761 const falseObjectDuplexStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexNotObject]});762 expectType<string>(falseObjectDuplexStdioResult.stderr);763 expectType<[undefined, string, string]>(falseObjectDuplexStdioResult.stdio);764765 const falseObjectDuplexPropertyStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', duplexNotObjectProperty]});766 expectType<string>(falseObjectDuplexPropertyStdioResult.stderr);767 expectType<[undefined, string, string]>(falseObjectDuplexPropertyStdioResult.stdio);768769 const falseObjectTransformStdioResult = await execa('unicorns', {stdio: ['pipe', 'pipe', {transform: objectGenerator, final: objectFinal, objectMode: false}]});770 expectType<string>(falseObjectTransformStdioResult.stderr);771 expectType<[undefined, string, string]>(falseObjectTransformStdioResult.stdio);772773 const undefinedObjectDuplexStdoutResult = await execa('unicorns', {stdout: duplex});774 expectType<string | unknown[]>(undefinedObjectDuplexStdoutResult.stdout);775 expectType<[undefined, string | unknown[], string]>(undefinedObjectDuplexStdoutResult.stdio);776777 const undefinedObjectTransformStdoutResult = await execa('unicorns', {stdout: {transform: objectGenerator, final: objectFinal}});778 expectType<string>(undefinedObjectTransformStdoutResult.stdout);779 expectType<[undefined, string, string]>(undefinedObjectTransformStdoutResult.stdio);780
479 unmodified lines
1260execa('unicorns', {stdin: [fileUrl]});1261execaSync('unicorns', {stdin: [fileUrl]});1262execa('unicorns', {stdin: {file: './test'}});1263execaSync('unicorns', {stdin: {file: './test'}});1264expectError(execa('unicorns', {stdin: {file: fileUrl}}));1265expectError(execaSync('unicorns', {stdin: {file: fileUrl}}));1266execa('unicorns', {stdin: [{file: './test'}]});1267execaSync('unicorns', {stdin: [{file: './test'}]});1268execa('unicorns', {stdin: 1});1269execaSync('unicorns', {stdin: 1});1270execa('unicorns', {stdin: [1]});1271execaSync('unicorns', {stdin: [1]});1272execa('unicorns', {stdin: duplex});1273expectError(execaSync('unicorns', {stdin: duplex}));1274execa('unicorns', {stdin: [duplex]});1275expectError(execaSync('unicorns', {stdin: [duplex]}));1276execa('unicorns', {stdin: duplexTransform});1277expectError(execaSync('unicorns', {stdin: duplexTransform}));1278execa('unicorns', {stdin: [duplexTransform]});1279expectError(execaSync('unicorns', {stdin: [duplexTransform]}));1280expectError(execa('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1281expectError(execaSync('unicorns', {stdin: {...duplex, objectMode: 'true'}}));1282execa('unicorns', {stdin: unknownGenerator});1283expectError(execaSync('unicorns', {stdin: unknownGenerator}));1284execa('unicorns', {stdin: [unknownGenerator]});1285expectError(execaSync('unicorns', {stdin: [unknownGenerator]}));
89 unmodified lines
1375execa('unicorns', {stdout: {file: './test'}});1376execaSync('unicorns', {stdout: {file: './test'}});1377execa('unicorns', {stdout: [{file: './test'}]});1378execaSync('unicorns', {stdout: [{file: './test'}]});1379expectError(execa('unicorns', {stdout: {file: fileUrl}}));1380expectError(execaSync('unicorns', {stdout: {file: fileUrl}}));1381execa('unicorns', {stdout: 1});1382execaSync('unicorns', {stdout: 1});1383execa('unicorns', {stdout: [1]});1384execaSync('unicorns', {stdout: [1]});1385execa('unicorns', {stdout: duplex});1386expectError(execaSync('unicorns', {stdout: duplex}));1387execa('unicorns', {stdout: [duplex]});1388expectError(execaSync('unicorns', {stdout: [duplex]}));1389execa('unicorns', {stdout: duplexTransform});1390expectError(execaSync('unicorns', {stdout: duplexTransform}));1391execa('unicorns', {stdout: [duplexTransform]});1392expectError(execaSync('unicorns', {stdout: [duplexTransform]}));1393expectError(execa('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1394expectError(execaSync('unicorns', {stdout: {...duplex, objectMode: 'true'}}));1395execa('unicorns', {stdout: unknownGenerator});1396expectError(execaSync('unicorns', {stdout: unknownGenerator}));1397execa('unicorns', {stdout: [unknownGenerator]});1398expectError(execaSync('unicorns', {stdout: [unknownGenerator]}));
89 unmodified lines
1488execa('unicorns', {stderr: {file: './test'}});1489execaSync('unicorns', {stderr: {file: './test'}});1490execa('unicorns', {stderr: [{file: './test'}]});1491execaSync('unicorns', {stderr: [{file: './test'}]});1492expectError(execa('unicorns', {stderr: {file: fileUrl}}));1493expectError(execaSync('unicorns', {stderr: {file: fileUrl}}));1494execa('unicorns', {stderr: 1});1495execaSync('unicorns', {stderr: 1});1496execa('unicorns', {stderr: [1]});1497execaSync('unicorns', {stderr: [1]});1498execa('unicorns', {stderr: duplex});1499expectError(execaSync('unicorns', {stderr: duplex}));1500execa('unicorns', {stderr: [duplex]});1501expectError(execaSync('unicorns', {stderr: [duplex]}));1502execa('unicorns', {stderr: duplexTransform});1503expectError(execaSync('unicorns', {stderr: duplexTransform}));1504execa('unicorns', {stderr: [duplexTransform]});1505expectError(execaSync('unicorns', {stderr: [duplexTransform]}));1506expectError(execa('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1507expectError(execaSync('unicorns', {stderr: {...duplex, objectMode: 'true'}}));1508execa('unicorns', {stderr: unknownGenerator});1509expectError(execaSync('unicorns', {stderr: unknownGenerator}));1510execa('unicorns', {stderr: [unknownGenerator]});1511expectError(execaSync('unicorns', {stderr: [unknownGenerator]}));
79 unmodified lines
1591expectError(execa('unicorns', {stdio: fileUrl}));1592expectError(execaSync('unicorns', {stdio: fileUrl}));1593expectError(execa('unicorns', {stdio: {file: './test'}}));1594expectError(execaSync('unicorns', {stdio: {file: './test'}}));1595expectError(execa('unicorns', {stdio: duplex}));1596expectError(execaSync('unicorns', {stdio: duplex}));1597expectError(execa('unicorns', {stdio: duplexTransform}));1598expectError(execaSync('unicorns', {stdio: duplexTransform}));1599expectError(execa('unicorns', {stdio: new Writable()}));1600expectError(execaSync('unicorns', {stdio: new Writable()}));1601expectError(execa('unicorns', {stdio: new Readable()}));1602expectError(execaSync('unicorns', {stdio: new Readable()}));
47 unmodified lines
1650 {transform: unknownGenerator, final: unknownFinal},1651 undefined,1652 fileUrl,1653 {file: './test'},1654 duplex,1655 duplexTransform,1656 new Writable(),1657 new Readable(),1658 new WritableStream(),1659 new ReadableStream(),
20 unmodified lines
1680 ],1681});1682expectError(execaSync('unicorns', {stdio: [unknownGenerator]}));1683expectError(execaSync('unicorns', {stdio: [{transform: unknownGenerator}]}));1684expectError(execaSync('unicorns', {stdio: [duplex]}));1685expectError(execaSync('unicorns', {stdio: [duplexTransform]}));1686expectError(execaSync('unicorns', {stdio: [new WritableStream()]}));1687expectError(execaSync('unicorns', {stdio: [new ReadableStream()]}));1688expectError(execaSync('unicorns', {stdio: [emptyStringGenerator()]}));1689expectError(execaSync('unicorns', {stdio: [asyncStringGenerator()]}));
15 unmodified lines
1705 [{transform: unknownGenerator, final: unknownFinal}],1706 [undefined],1707 [fileUrl],1708 [{file: './test'}],1709 [duplex],1710 [duplexTransform],1711 [new Writable()],1712 [new Readable()],1713 [new WritableStream()],1714 [new ReadableStream()],
24 unmodified lines
1739 ],1740});1741expectError(execaSync('unicorns', {stdio: [[unknownGenerator]]}));1742expectError(execaSync('unicorns', {stdio: [[{transform: unknownGenerator}]]}));1743expectError(execaSync('unicorns', {stdio: [[duplex]]}));1744expectError(execaSync('unicorns', {stdio: [[duplexTransform]]}));1745expectError(execaSync('unicorns', {stdio: [[new WritableStream()]]}));1746expectError(execaSync('unicorns', {stdio: [[new ReadableStream()]]}));1747expectError(execaSync('unicorns', {stdio: [[['foo', 'bar']]]}));1748expectError(execaSync('unicorns', {stdio: [[[new Uint8Array(), new Uint8Array()]]]}));
438 unmodified lines
modified:readme.md+8 added-8 removed
317 unmodified lines
318Same as [`execa()`](#execafile-arguments-options) but synchronous.319320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options), [`.iterable()`](#iterablereadableoptions), [`.readable()`](#readablereadableoptions), [`.writable()`](#writablewritableoptions), [`.duplex()`](#duplexduplexoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`forceKillAfterDelay`](#forcekillafterdelay), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a [transform](docs/transform.md) or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`forceKillAfterDelay`](#forcekillafterdelay), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, [`overlapped`](https://nodejs.org/api/child_process.html#optionsstdio), an iterable, a [transform](docs/transform.md), a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\
542 unmodified lines
869See also the [`input`](#input) and [`stdin`](#stdin) options.870871#### stdin872873Type: `string | number | stream.Readable | ReadableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\873Type: `string | number | stream.Readable | ReadableStream | URL | {file: string} | Uint8Array | Iterable<string | Uint8Array | unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}` (or a tuple of those types)\874Default: `inherit` with [`$`](#file-arguments-options), `pipe` otherwise875876[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard input. This can be:877- `'pipe'`: Sets [`subprocess.stdin`](https://nodejs.org/api/child_process.html#subprocessstdin) stream.
9 unmodified lines
887- an `Uint8Array`.888889This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.890891This can also be a generator function to transform the input. [Learn more.](docs/transform.md)891This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the input. [Learn more.](docs/transform.md)892893#### stdout894895Type: `string | number | stream.Writable | WritableStream | URL | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\895Type: `string | number | stream.Writable | WritableStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}` (or a tuple of those types)\896Default: `pipe`897898[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard output. This can be:899- `'pipe'`: Sets [`subprocessResult.stdout`](#stdout) (as a string or `Uint8Array`) and [`subprocess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout) (as a stream).
7 unmodified lines
907- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).908909This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.910911This can also be a generator function to transform the output. [Learn more.](docs/transform.md)911This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)912913#### stderr914915Type: `string | number | stream.Writable | WritableStream | URL | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>` (or a tuple of those types)\915Type: `string | number | stream.Writable | WritableStream | URL | {file: string} | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}` (or a tuple of those types)\916Default: `pipe`917918[How to setup](https://nodejs.org/api/child_process.html#child_process_options_stdio) the subprocess' standard error. This can be:919- `'pipe'`: Sets [`subprocessResult.stderr`](#stderr) (as a string or `Uint8Array`) and [`subprocess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr) (as a stream).
7 unmodified lines
927- a web [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream).928929This can be an [array of values](#redirect-stdinstdoutstderr-to-multiple-destinations) such as `['inherit', 'pipe']` or `[filePath, 'pipe']`.930931This can also be a generator function to transform the output. [Learn more.](docs/transform.md)931This can also be a generator function or a [`Duplex`](docs/transform.md#nodejs-duplextransform-streams) to transform the output. [Learn more.](docs/transform.md)932933#### stdio934935Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string> | AsyncIterable<Uint8Array> | AsyncIterable<unknown> | GeneratorFunction<string> | GeneratorFunction<Uint8Array> | GeneratorFunction<unknown>| AsyncGeneratorFunction<string> | AsyncGeneratorFunction<Uint8Array> | AsyncGeneratorFunction<unknown>>` (or a tuple of those types)\935Type: `string | Array<string | number | stream.Readable | stream.Writable | ReadableStream | WritableStream | URL | {file: string} | Uint8Array | Iterable<string> | Iterable<Uint8Array> | Iterable<unknown> | AsyncIterable<string | Uint8Array | unknown> | GeneratorFunction<string | Uint8Array | unknown> | AsyncGeneratorFunction<string | Uint8Array | unknown> | {transform: GeneratorFunction | AsyncGeneratorFunction | Duplex}>` (or a tuple of those types)\936Default: `pipe`937938Like the [`stdin`](#stdin), [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options but for all file descriptors at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.939
286 unmodified lines