Skip to content
Myr

Add support for transforms with `execaSync()` (#945)

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

authored by ehmicky · committed by GitHub · parent f744f7d · Browse files · 42 files+1615 added−898 removed
This commit

State

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

Diff stats

42 files+1615 added−898 removed

  • tests:+1160 added−613 removed
  • other:+455 added−285 removed

42 files+1615 added−898 removed

modified:lib/arguments/template.js+2 added-1 removed
modified:lib/exit/code.js+1 added-1 removed
modified:lib/return/error.js+1 added-1 removed
1import {signalsByName} from 'human-signals';2import stripFinalNewline from 'strip-final-newline';3import {isUint8Array, uint8ArrayToString} from '../utils.js';3import {isUint8Array, uint8ArrayToString} from '../stdio/uint-array.js';4import {fixCwdError} from '../arguments/cwd.js';5import {escapeLines} from '../arguments/escape.js';6import {getDurationMs} from './duration.js';7import {getFinalError, DiscardedError, isExecaError} from './cause.js';
189 unmodified lines
modified:lib/return/output.js-6 removed
modified:lib/stdio/async.js+1 added
15 unmodified lines
16};1718const addProperties = {19 generator: generatorToDuplexStream,20 asyncGenerator: generatorToDuplexStream,21 nodeStream: ({value}) => ({stream: value}),22 webTransform({value: {transform, writableObjectMode, readableObjectMode}}) {23 const objectMode = writableObjectMode || readableObjectMode;24 const stream = Duplex.fromWeb(transform, {objectMode});
91 unmodified lines
modified:lib/stdio/direction.js+1 added
29 unmodified lines
3031// `string` can only be added through the `input` option, i.e. does not need to be handled here32const guessStreamDirection = {33 generator: anyDirection,34 asyncGenerator: anyDirection,35 fileUrl: anyDirection,36 filePath: anyDirection,37 iterable: alwaysInput,38 asyncIterable: alwaysInput,
43 unmodified lines
modified:lib/stdio/encoding-final.js+3 added-4 removed
1import {StringDecoder} from 'node:string_decoder';23// Apply the `encoding` option using an implicit generator.4// This encodes the final output of `stdout`/`stderr`.5export const handleStreamsEncoding = ({options: {encoding}, isSync, direction, optionName, objectMode}) => {6 if (!shouldEncodeOutput({encoding, isSync, direction, objectMode})) {5export const handleStreamsEncoding = ({options: {encoding}, direction, optionName, objectMode}) => {6 if (!shouldEncodeOutput({encoding, direction, objectMode})) {7 return [];8 }910 const stringDecoder = new StringDecoder(encoding);
7 unmodified lines
18 optionName,19 }];20};2122const shouldEncodeOutput = ({encoding, isSync, direction, objectMode}) => direction === 'output'22const shouldEncodeOutput = ({encoding, direction, objectMode}) => direction === 'output'23 && encoding !== 'utf8'24 && encoding !== 'buffer'25 && !isSync25 && !objectMode;2627const encodingStringGenerator = function * (stringDecoder, chunk) {28 yield stringDecoder.write(chunk);
8 unmodified lines
modified:lib/stdio/encoding-transform.js+13 added-4 removed
1import {Buffer} from 'node:buffer';2import {isUint8Array} from './uint-array.js';34/*5When using generators, add an internal generator that converts chunks from `Buffer` to `string` or `Uint8Array`.6This allows generator functions to operate with those types instead.
11 unmodified lines
18 return;19 }2021 if (binary) {21 return {transform: encodingUint8ArrayGenerator};22 return {transform: encodingUint8ArrayGenerator.bind(undefined, new TextEncoder())};23 }2425 const textDecoder = new TextDecoder();26 return {
1 unmodified line
28 final: encodingStringFinal.bind(undefined, textDecoder),29 };30};3131const encodingUint8ArrayGenerator = function * (chunk) {32 yield Buffer.isBuffer(chunk) ? new Uint8Array(chunk) : chunk;32const encodingUint8ArrayGenerator = function * (textEncoder, chunk) {33 if (Buffer.isBuffer(chunk)) {34 yield new Uint8Array(chunk);35 } else if (typeof chunk === 'string') {36 yield textEncoder.encode(chunk);37 } else {38 yield chunk;39 }40};4142const encodingStringGenerator = function * (textDecoder, chunk) {36 yield Buffer.isBuffer(chunk) ? textDecoder.decode(chunk, {stream: true}) : chunk;43 yield Buffer.isBuffer(chunk) || isUint8Array(chunk)44 ? textDecoder.decode(chunk, {stream: true})45 : chunk;46};4748const encodingStringFinal = function * (textDecoder) {49 const lastChunk = textDecoder.decode();
4 unmodified lines
modified:lib/stdio/generator.js+29 added-8 removed
1import isPlainObj from 'is-plain-obj';2import {BINARY_ENCODINGS} from '../arguments/encoding.js';3import {generatorsToTransform} from './transform.js';3import {generatorsToTransform, runTransformSync} from './transform.js';4import {getEncodingTransformGenerator} from './encoding-transform.js';5import {getSplitLinesGenerator, getAppendNewlineGenerator} from './split.js';6import {pipeStreams} from './pipeline.js';7import {isAsyncGenerator} from './type.js';8import {getValidateTransformReturn} from './validate.js';8import {getValidateTransformInput, getValidateTransformReturn} from './validate.js';910export const getObjectMode = (stdioItems, optionName, direction, options) => {11 const transforms = getTransforms(stdioItems, optionName, direction, options);12 if (transforms.length === 0) {
19 unmodified lines
3233 return sortTransforms(newTransforms, direction);34};3536export const TRANSFORM_TYPES = new Set(['generator', 'duplex', 'webTransform']);36export const TRANSFORM_TYPES = new Set(['generator', 'asyncGenerator', 'duplex', 'webTransform']);3738const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => {39 if (type === 'duplex') {40 return normalizeDuplex({stdioItem, optionName});
98 unmodified lines
139140Chunks are currently processed serially. We could add a `concurrency` option to parallelize in the future.141*/142export const generatorToDuplexStream = ({143 value,144 value: {transform, final, writableObjectMode, readableObjectMode},145 forceEncoding,146 optionName,147}) => {148 const generators = addInternalGenerators({value, forceEncoding, optionName});149 const transformAsync = isAsyncGenerator(transform);150 const finalAsync = isAsyncGenerator(final);151 const stream = generatorsToTransform(generators, {transformAsync, finalAsync, writableObjectMode, readableObjectMode});152 return {stream};153};154155export const getGenerators = allStdioItems => allStdioItems.filter(({type}) => type === 'generator');156157export const runGeneratorsSync = (chunks, generators) => {158 for (const {value, optionName} of generators) {159 const generators = addInternalGenerators({value, forceEncoding: false, optionName});160 chunks = runTransformSync(generators, chunks);161 }162163 return chunks;164};165166const addInternalGenerators = ({167 value: {transform, final, binary, writableObjectMode, readableObjectMode, preserveNewlines},168 forceEncoding,169 optionName,170}) => {171 const state = {};148 const generators = [172 return [173 {transform: getValidateTransformInput(writableObjectMode, optionName)},174 getEncodingTransformGenerator(binary, writableObjectMode, forceEncoding),175 getSplitLinesGenerator({binary, preserveNewlines, writableObjectMode, state}),176 {transform, final},177 {transform: getValidateTransformReturn(readableObjectMode, optionName)},178 getAppendNewlineGenerator({binary, preserveNewlines, readableObjectMode, state}),179 ].filter(Boolean);155 const transformAsync = isAsyncGenerator(transform);156 const finalAsync = isAsyncGenerator(final);157 const stream = generatorsToTransform(generators, {transformAsync, finalAsync, writableObjectMode, readableObjectMode});158 return {stream};180};181182// `subprocess.stdin|stdout|stderr|stdio` is directly mutated.183export const pipeTransform = (subprocess, stream, direction, fdNumber) => {
15 unmodified lines
modified:lib/stdio/handle.js+25 added-15 removed
25 unmodified lines
26 const outputLines = [];27 const optionName = getOptionName(fdNumber);28 const stdioItems = initializeStdioItems({stdioOption, fdNumber, options, isSync, optionName});29 const direction = getStreamDirection(stdioItems, fdNumber, optionName);30 const objectMode = getObjectMode(stdioItems, optionName, direction, options);31 validateFileObjectMode(stdioItems, objectMode);30 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines});32 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});33 return {fdNumber, direction, outputLines, stdioItems: normalizedStdioItems};34};3536const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;
19 unmodified lines
56 optionName,57});5859const filterDuplicates = stdioItems => stdioItems.filter((stdioItemOne, indexOne) =>58 stdioItems.every((stdioItemTwo, indexTwo) =>59 stdioItemOne.value !== stdioItemTwo.value || indexOne >= indexTwo || stdioItemOne.type === 'generator'));60 stdioItems.every((stdioItemTwo, indexTwo) => stdioItemOne.value !== stdioItemTwo.value61 || indexOne >= indexTwo62 || stdioItemOne.type === 'generator'63 || stdioItemOne.type === 'asyncGenerator'));6465const validateStdioArray = (stdioItems, isStdioArray, optionName) => {66 if (stdioItems.length === 0) {67 throw new TypeError(`The \`${optionName}\` option must not be an empty array.`);
30 unmodified lines
98 throw new TypeError(`The \`${optionName}: { file: '...' }\` option must be used instead of \`${optionName}: '...'\`.`);99 }100};10198const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines}) => {99 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines});102const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode}) => {103 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});104 const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);105 return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));106};107104const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines}) => {105 if (!willPipeFileDescriptor(stdioItems)) {106 return stdioItems;107 }108109 const objectMode = getObjectMode(stdioItems, optionName, direction, options);110 return [108const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode}) => willPipeFileDescriptor(stdioItems)109 ? [110 ...stdioItems,112 ...handleStreamsEncoding({options, isSync, direction, optionName, objectMode}),111 ...handleStreamsEncoding({options, direction, optionName, objectMode}),112 ...handleStreamsVerbose({stdioItems, options, isSync, stdioState, verboseInfo, fdNumber, optionName}),113 ...handleStreamsLines({options, isSync, direction, optionName, objectMode, outputLines}),115 ];116};114 ]115 : stdioItems;116117// Some `stdio` values require Execa to create streams.118// For example, file paths create file read/write streams.119// Those transformations are specified in `addProperties`, which is both direction-specific and type-specific.120const addStreamProperties = (stdioItem, addProperties, direction) => ({121 ...stdioItem,122 ...addProperties[direction][stdioItem.type](stdioItem),123});124125const validateFileObjectMode = (stdioItems, objectMode) => {126 if (!objectMode) {127 return;128 }129130 const fileStdioItem = stdioItems.find(({type}) => type === 'fileUrl' || type === 'filePath');131 if (fileStdioItem !== undefined) {132 throw new TypeError(`The \`${fileStdioItem.optionName}\` option cannot use both files and transforms in objectMode.`);133 }134};
added:lib/stdio/input-sync.js+47 added
1import {joinToUint8Array, isUint8Array} from './uint-array.js';2import {TYPE_TO_MESSAGE} from './type.js';3import {getGenerators, runGeneratorsSync} from './generator.js';45// Apply `stdin`/`input`/`inputFile` options, before spawning, in sync mode, by converting it to the `input` option6export const addInputOptionsSync = (fileDescriptors, options) => {7 for (const fdNumber of getInputFdNumbers(fileDescriptors)) {8 addInputOptionSync(fileDescriptors, fdNumber, options);9 }10};1112const getInputFdNumbers = fileDescriptors => new Set(fileDescriptors13 .filter(({direction}) => direction === 'input')14 .map(({fdNumber}) => fdNumber));1516const addInputOptionSync = (fileDescriptors, fdNumber, options) => {17 const selectedStdioItems = fileDescriptors18 .filter(fileDescriptor => fileDescriptor.fdNumber === fdNumber)19 .flatMap(({stdioItems}) => stdioItems);20 const allStdioItems = selectedStdioItems.filter(({contents}) => contents !== undefined);21 if (allStdioItems.length === 0) {22 return;23 }2425 if (fdNumber !== 0) {26 const [{type, optionName}] = allStdioItems;27 throw new TypeError(`Only the \`stdin\` option, not \`${optionName}\`, can be ${TYPE_TO_MESSAGE[type]} with synchronous methods.`);28 }2930 const allContents = allStdioItems.map(({contents}) => contents);31 const transformedContents = allContents.map(contents => applySingleInputGeneratorsSync(contents, selectedStdioItems));32 options.input = joinToUint8Array(transformedContents);33};3435const applySingleInputGeneratorsSync = (contents, selectedStdioItems) => {36 const generators = getGenerators(selectedStdioItems).reverse();37 const newContents = runGeneratorsSync(contents, generators);38 validateSerializable(newContents);39 return joinToUint8Array(newContents);40};4142const validateSerializable = newContents => {43 const invalidItem = newContents.find(item => typeof item !== 'string' && !isUint8Array(item));44 if (invalidItem !== undefined) {45 throw new TypeError(`The \`stdin\` option is invalid: when passing objects as input, a transform must be used to serialize them to strings or Uint8Arrays: ${invalidItem}.`);46 }47};
modified:lib/stdio/input.js+1 added-1 removed
1import {isReadableStream} from 'is-stream';2import {isUint8Array} from '../utils.js';2import {isUint8Array} from './uint-array.js';3import {isUrl, isFilePathString} from './type.js';45// Append the `stdin` option with the `input` and `inputFile` options6export const handleInputOptions = ({input, inputFile}, fdNumber) => fdNumber === 0
44 unmodified lines
added:lib/stdio/output-sync.js+65 added
1import {writeFileSync} from 'node:fs';2import {joinToString, joinToUint8Array, bufferToUint8Array} from './uint-array.js';3import {getGenerators, runGeneratorsSync} from './generator.js';45// Apply `stdout`/`stderr` options, after spawning, in sync mode6export const transformOutputSync = (fileDescriptors, {output}, options) => {7 if (output === null) {8 return {output: Array.from({length: 3})};9 }1011 const state = {};12 const transformedOutput = output.map((result, fdNumber) =>13 transformOutputResultSync({result, fileDescriptors, fdNumber, options, state}));14 return {output: transformedOutput, ...state};15};1617const transformOutputResultSync = ({result, fileDescriptors, fdNumber, options, state}) => {18 if (result === null) {19 return result;20 }2122 const allStdioItems = fileDescriptors23 .filter(fileDescriptor => fileDescriptor.fdNumber === fdNumber && fileDescriptor.direction === 'output')24 .flatMap(({stdioItems}) => stdioItems);25 const uint8ArrayResult = bufferToUint8Array(result);26 const generators = getGenerators(allStdioItems);27 const chunks = runOutputGeneratorsSync([uint8ArrayResult], generators, state);28 const transformedResult = serializeChunks(chunks, generators, options);2930 try {31 if (state.error === undefined) {32 writeToFiles(transformedResult, allStdioItems);33 }3435 return transformedResult;36 } catch (error) {37 state.error = error;38 return transformedResult;39 }40};4142const runOutputGeneratorsSync = (chunks, generators, state) => {43 try {44 return runGeneratorsSync(chunks, generators);45 } catch (error) {46 state.error = error;47 return chunks;48 }49};5051const serializeChunks = (chunks, generators, {encoding}) => {52 if (generators.at(-1)?.value?.readableObjectMode) {53 return chunks;54 }5556 return encoding === 'buffer' ? joinToUint8Array(chunks) : joinToString(chunks, true);57};5859const writeToFiles = (transformedResult, allStdioItems) => {60 for (const {type, path} of allStdioItems) {61 if (type === 'fileUrl' || type === 'filePath') {62 writeFileSync(path, transformedResult);63 }64 }65};
modified:lib/stdio/sync.js+5 added-69 removed
1import {readFileSync, writeFileSync} from 'node:fs';1import {readFileSync} from 'node:fs';2import {isStream as isNodeStream} from 'is-stream';3import {bufferToUint8Array, uint8ArrayToString, isUint8Array} from '../utils.js';3import {bufferToUint8Array} from './uint-array.js';4import {handleInput} from './handle.js';5import {TYPE_TO_MESSAGE} from './type.js';67// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode7// Normalize `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode8export const handleInputSync = (options, verboseInfo) => {9 const {fileDescriptors} = handleInput(addPropertiesSync, options, verboseInfo, true);10 validateStdioArraysSync(fileDescriptors);11 addInputOptionsSync(fileDescriptors, options);11 return fileDescriptors;12};1314const forbiddenIfSync = ({type, optionName}) => {
12 unmodified lines
27 throw new TypeError(`The \`${optionName}\` option cannot be ${value} with synchronous methods.`);28};2930const addProperties = {32 generator: forbiddenIfSync,31 generator() {},32 asyncGenerator: forbiddenIfSync,33 webStream: forbiddenIfSync,34 nodeStream: forbiddenIfSync,35 webTransform: forbiddenIfSync,36 duplex: forbiddenIfSync,
62 unmodified lines
99 }100};101102const OPTION_NAMES = new Set(['input', 'inputFile']);103104const addInputOptionsSync = (fileDescriptors, options) => {105 for (const fdNumber of getInputFdNumbers(fileDescriptors)) {106 addInputOptionSync(fileDescriptors, fdNumber, options);107 }108};109110const getInputFdNumbers = fileDescriptors => new Set(fileDescriptors111 .filter(({direction}) => direction === 'input')112 .map(({fdNumber}) => fdNumber));113114const addInputOptionSync = (fileDescriptors, fdNumber, options) => {115 const allStdioItems = fileDescriptors116 .filter(fileDescriptor => fileDescriptor.fdNumber === fdNumber)117 .flatMap(({stdioItems}) => stdioItems)118 .filter(({contents}) => contents !== undefined);119 if (allStdioItems.length === 0) {120 return;121 }122123 if (fdNumber !== 0) {124 const [{type, optionName}] = allStdioItems;125 throw new TypeError(`Only the \`stdin\` option, not \`${optionName}\`, can be ${TYPE_TO_MESSAGE[type]} with synchronous methods.`);126 }127128 const allContents = allStdioItems.map(({contents}) => contents);129 options.input = serializeAllContents(allContents.flat());130};131132const serializeAllContents = allContents => {133 const invalidContents = allContents.find(contents => typeof contents !== 'string' && !isUint8Array(contents));134 if (invalidContents !== undefined) {135 throw new TypeError(`The \`stdin\` option is invalid: only strings or Uint8Arrays can be yielded from iterables when using the synchronous methods: ${invalidContents}.`);136 }137138 return allContents.length === 1139 ? allContents[0]140 : allContents.map(contents => serializeContents(contents)).join('');141};142143const serializeContents = contents => typeof contents === 'string' ? contents : uint8ArrayToString(contents);144145// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in sync mode146export const pipeOutputSync = (fileDescriptors, {output}) => {147 if (output === null) {148 return;149 }150151 for (const {stdioItems, fdNumber, direction} of fileDescriptors) {152 for (const {type, path} of stdioItems) {153 pipeStdioItemSync(output[fdNumber], type, path, direction);154 }155 }156};157158const pipeStdioItemSync = (result, type, path, direction) => {159 if (result === null || direction === 'input') {160 return;161 }162163 if (type === 'fileUrl' || type === 'filePath') {164 writeFileSync(path, result);165 }166};
modified:lib/stdio/transform.js+6 added
96 unmodified lines
97 done(error);98 }99};100101// Run synchronous generators with `execaSync()`102export const runTransformSync = (generators, chunks) => [103 ...chunks.flatMap(chunk => [...transformChunkSync(chunk, generators, 0)]),104 ...finalChunksSync(generators),105];106107const transformChunkSync = function * (chunk, generators, index) {108 if (index === generators.length) {109 yield chunk;110 return;
27 unmodified lines
modified:lib/stdio/type.js+8 added-3 removed
1import {isStream as isNodeStream, isDuplexStream} from 'is-stream';2import isPlainObj from 'is-plain-obj';3import {isUint8Array} from '../utils.js';3import {isUint8Array} from './uint-array.js';45// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.6export const getStdioItemType = (value, optionName) => {7 if (isGenerator(value)) {7 if (isAsyncGenerator(value)) {8 return 'asyncGenerator';9 }1011 if (isSyncGenerator(value)) {12 return 'generator';13 }1415 if (isUrl(value)) {
88 unmodified lines
104105 checkBooleanOption(binary, `${optionName}.binary`);106 checkBooleanOption(objectMode, `${optionName}.objectMode`);107104 return 'generator';108 return isAsyncGenerator(transform) || isAsyncGenerator(final) ? 'asyncGenerator' : 'generator';109};110111const checkBooleanOption = (value, optionName) => {112 if (value !== undefined && typeof value !== 'boolean') {
31 unmodified lines
144145// Convert types to human-friendly strings for error messages146export const TYPE_TO_MESSAGE = {147 generator: 'a generator',148 asyncGenerator: 'an async generator',149 fileUrl: 'a file URL',150 filePath: 'a file path string',151 webStream: 'a web stream',152 nodeStream: 'a Node.js stream',
8 unmodified lines
added:lib/stdio/uint-array.js+59 added
1import {Buffer} from 'node:buffer';23export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);45export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);67const textEncoder = new TextEncoder();8const stringToUint8Array = string => textEncoder.encode(string);910const textDecoder = new TextDecoder();11export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);1213export const joinToString = (uint8ArraysOrStrings, areRelated) => {14 if (uint8ArraysOrStrings.length === 1 && typeof uint8ArraysOrStrings[0] === 'string') {15 return uint8ArraysOrStrings[0];16 }1718 const strings = uint8ArraysToStrings(uint8ArraysOrStrings, areRelated);19 return strings.join('');20};2122const uint8ArraysToStrings = (uint8ArraysOrStrings, areRelated) => {23 const decoder = new TextDecoder();24 const strings = uint8ArraysOrStrings.map(uint8ArrayOrString => isUint8Array(uint8ArrayOrString)25 ? decoder.decode(uint8ArrayOrString, {stream: areRelated})26 : uint8ArrayOrString);27 const finalString = decoder.decode();28 return finalString === '' ? strings : [...strings, finalString];29};3031export const joinToUint8Array = uint8ArraysOrStrings => {32 if (uint8ArraysOrStrings.length === 1 && isUint8Array(uint8ArraysOrStrings[0])) {33 return uint8ArraysOrStrings[0];34 }3536 const uint8Arrays = stringsToUint8Arrays(uint8ArraysOrStrings);37 const result = new Uint8Array(getJoinLength(uint8Arrays));3839 let index = 0;40 for (const uint8Array of uint8Arrays) {41 result.set(uint8Array, index);42 index += uint8Array.length;43 }4445 return result;46};4748const stringsToUint8Arrays = uint8ArraysOrStrings => uint8ArraysOrStrings.map(uint8ArrayOrString => typeof uint8ArrayOrString === 'string'49 ? stringToUint8Array(uint8ArrayOrString)50 : uint8ArrayOrString);5152const getJoinLength = uint8Arrays => {53 let joinLength = 0;54 for (const uint8Array of uint8Arrays) {55 joinLength += uint8Array.length;56 }5758 return joinLength;59};
modified:lib/stdio/validate.js+13 added-1 removed
1import {Buffer} from 'node:buffer';2import {isUint8Array} from '../utils.js';2import {isUint8Array} from './uint-array.js';34export const getValidateTransformInput = (writableObjectMode, optionName) => writableObjectMode5 ? undefined6 : validateStringTransformInput.bind(undefined, optionName);78const validateStringTransformInput = function * (optionName, chunk) {9 if (typeof chunk !== 'string' && !isUint8Array(chunk) && !Buffer.isBuffer(chunk)) {10 throw new TypeError(`The \`${optionName}\` option's transform must use "objectMode: true" to receive as input: ${typeof chunk}.`);11 }1213 yield chunk;14};1516export const getValidateTransformReturn = (readableObjectMode, optionName) => readableObjectMode17 ? validateObjectTransformReturn.bind(undefined, optionName)18 : validateStringTransformReturn.bind(undefined, optionName);19
23 unmodified lines
modified:lib/sync.js+20 added-10 removed
1import {spawnSync} from 'node:child_process';2import {handleCommand, handleOptions} from './arguments/options.js';3import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';4import {handleOutput, handleResult} from './return/output.js';5import {handleInputSync, pipeOutputSync} from './stdio/sync.js';5import {handleInputSync} from './stdio/sync.js';6import {addInputOptionsSync} from './stdio/input-sync.js';7import {transformOutputSync} from './stdio/output-sync.js';8import {logEarlyResult} from './verbose/complete.js';9import {getSyncExitResult} from './exit/code.js';1011export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {
37 unmodified lines
49 throw new TypeError(`The "${value}" option cannot be used with synchronous methods.`);50};5152const spawnSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {51 let syncResult;52 try {53 syncResult = spawnSync(file, args, options);54 } catch (error) {55 return makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: true});53 const syncResult = runSubprocessSync({file, args, options, command, escapedCommand, fileDescriptors, startTime});54 if (syncResult.failed) {55 return syncResult;56 }5758 const {error, exitCode, signal} = getSyncExitResult(syncResult);59 pipeOutputSync(fileDescriptors, syncResult);6061 const output = syncResult.output || Array.from({length: 3});58 const {resultError, exitCode, signal} = getSyncExitResult(syncResult);59 const {output, error = resultError} = transformOutputSync(fileDescriptors, syncResult, options);60 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));61 return getSyncResult({error, exitCode, signal, stdio, options, command, escapedCommand, startTime});62};6364const runSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {65 try {66 addInputOptionsSync(fileDescriptors, options);67 const normalizedOptions = normalizeSpawnSyncOptions(options);68 return spawnSync(file, args, normalizedOptions);69 } catch (error) {70 return makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: true});71 }72};7374const normalizeSpawnSyncOptions = ({encoding, ...options}) => ({...options, encoding: 'buffer'});7576const getSyncResult = ({error, exitCode, signal, stdio, options, command, escapedCommand, startTime}) => error === undefined77 ? makeSuccessResult({command, escapedCommand, stdio, options, startTime})78 : makeError({79 error,
11 unmodified lines
modified:lib/utils.js-8 removed
1import {Buffer} from 'node:buffer';1import {ChildProcess} from 'node:child_process';2import {addAbortListener} from 'node:events';3import process from 'node:process';46export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);78export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);910const textDecoder = new TextDecoder();11export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);125export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);6export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];7export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];8
13 unmodified lines
modified:test/convert/loop.js+7 added-7 removed
131 unmodified lines
132 await subprocess;133};134135test('.iterable() uses Uint8Arrays with "binary: true"', testObjectMode, simpleChunksUint8Array, 'iterable', null, false, false, true);136test('.iterable() uses strings with "binary: true" and .setEncoding("utf8")', testObjectMode, simpleChunks, 'iterable', 'utf8', false, false, true);137test('.iterable() uses strings with "binary: true" and "encoding: buffer"', testObjectMode, simpleChunks, 'iterable', 'utf8', false, false, true, {encoding: 'buffer'});136test('.iterable() uses Uint8Arrays with "binary: true" and .setEncoding("utf8")', testObjectMode, simpleChunksUint8Array, 'iterable', 'utf8', false, false, true);137test('.iterable() uses Uint8Arrays with "binary: true", .setEncoding("utf8") and "encoding: buffer"', testObjectMode, simpleChunksUint8Array, 'iterable', 'utf8', false, false, true, {encoding: 'buffer'});138test('.iterable() uses strings in objectMode with "binary: true" and object transforms', testObjectMode, foobarObjectChunks, 'iterable', null, true, true, true, {stdout: outputObjectGenerator()});139test('.iterable() uses strings in objectMode with "binary: false"', testObjectMode, simpleLines, 'iterable', null, false, true, false);140test('.iterable() uses strings in objectMode with "binary: false" and .setEncoding("utf8")', testObjectMode, simpleLines, 'iterable', 'utf8', false, true, false);141test('.iterable() uses strings in objectMode with "binary: false" and "encoding: buffer"', testObjectMode, simpleChunks, 'iterable', 'utf8', false, true, false, {encoding: 'buffer'});141test('.iterable() uses Uint8Arrays in objectMode with "binary: false", .setEncoding("utf8") and "encoding: buffer"', testObjectMode, simpleChunksUint8Array, 'iterable', 'utf8', false, true, false, {encoding: 'buffer'});142test('.iterable() uses strings in objectMode with "binary: false" and object transforms', testObjectMode, foobarObjectChunks, 'iterable', null, true, true, false, {stdout: outputObjectGenerator()});143test('.readable() uses Buffers with "binary: true"', testObjectMode, simpleChunksBuffer, 'readable', null, false, false, true);144test('.readable() uses strings with "binary: true" and .setEncoding("utf8")', testObjectMode, simpleChunks, 'readable', 'utf8', false, false, true);145test('.readable() uses strings with "binary: true" and "encoding: buffer"', testObjectMode, simpleChunks, 'readable', 'utf8', false, false, true, {encoding: 'buffer'});145test('.readable() uses strings with "binary: true", .setEncoding("utf8") and "encoding: buffer"', testObjectMode, simpleChunks, 'readable', 'utf8', false, false, true, {encoding: 'buffer'});146test('.readable() uses strings in objectMode with "binary: true" and object transforms', testObjectMode, foobarObjectChunks, 'readable', null, true, true, true, {stdout: outputObjectGenerator()});147test('.readable() uses strings in objectMode with "binary: false"', testObjectMode, simpleLines, 'readable', null, false, true, false);148test('.readable() uses strings in objectMode with "binary: false" and .setEncoding("utf8")', testObjectMode, simpleLines, 'readable', 'utf8', false, true, false);149test('.readable() uses strings in objectMode with "binary: false" and "encoding: buffer"', testObjectMode, simpleChunks, 'readable', 'utf8', false, false, false, {encoding: 'buffer'});149test('.readable() uses strings in objectMode with "binary: false", .setEncoding("utf8") and "encoding: buffer"', testObjectMode, simpleChunks, 'readable', 'utf8', false, false, false, {encoding: 'buffer'});150test('.readable() uses strings in objectMode with "binary: false" and object transforms', testObjectMode, foobarObjectChunks, 'readable', null, true, true, false, {stdout: outputObjectGenerator()});151test('.duplex() uses Buffers with "binary: true"', testObjectMode, simpleChunksBuffer, 'duplex', null, false, false, true);152test('.duplex() uses strings with "binary: true" and .setEncoding("utf8")', testObjectMode, simpleChunks, 'duplex', 'utf8', false, false, true);153test('.duplex() uses strings with "binary: true" and "encoding: buffer"', testObjectMode, simpleChunks, 'duplex', 'utf8', false, false, true, {encoding: 'buffer'});153test('.duplex() uses strings with "binary: true", .setEncoding("utf8") and "encoding: buffer"', testObjectMode, simpleChunks, 'duplex', 'utf8', false, false, true, {encoding: 'buffer'});154test('.duplex() uses strings in objectMode with "binary: true" and object transforms', testObjectMode, foobarObjectChunks, 'duplex', null, true, true, true, {stdout: outputObjectGenerator()});155test('.duplex() uses strings in objectMode with "binary: false"', testObjectMode, simpleLines, 'duplex', null, false, true, false);156test('.duplex() uses strings in objectMode with "binary: false" and .setEncoding("utf8")', testObjectMode, simpleLines, 'duplex', 'utf8', false, true, false);157test('.duplex() uses strings in objectMode with "binary: false" and "encoding: buffer"', testObjectMode, simpleChunks, 'duplex', 'utf8', false, false, false, {encoding: 'buffer'});157test('.duplex() uses strings in objectMode with "binary: false", .setEncoding("utf8") and "encoding: buffer"', testObjectMode, simpleChunks, 'duplex', 'utf8', false, false, false, {encoding: 'buffer'});158test('.duplex() uses strings in objectMode with "binary: false" and object transforms', testObjectMode, foobarObjectChunks, 'duplex', null, true, true, false, {stdout: outputObjectGenerator()});159160const testObjectSplit = async (t, methodName) => {161 const subprocess = getSubprocess(methodName, foobarString, {stdout: getOutputGenerator(simpleFull)(true)});
22 unmodified lines
modified:test/convert/writable.js+3 added-3 removed
22 unmodified lines
23import {foobarString, foobarBuffer, foobarObject, foobarObjectString} from '../helpers/input.js';24import {prematureClose, fullReadableStdio} from '../helpers/stdio.js';25import {26 throwingGenerator,27 GENERATOR_ERROR_REGEXP,27 serializeGenerator,28 noopAsyncGenerator,29} from '../helpers/generator.js';30import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';
305 unmodified lines
336 await assertSubprocessOutput(t, subprocess, expectedOutput);337});338339const testPropagateError = async (t, methodName) => {340 const cause = new Error(foobarString);341 const subprocess = getReadWriteSubprocess({stdin: throwingGenerator()});341 const subprocess = getReadWriteSubprocess({stdin: throwingGenerator(cause)()});342 const stream = subprocess[methodName]();343 stream.end('.');344 await t.throwsAsync(finishedStream(stream), {message: GENERATOR_ERROR_REGEXP});344 await assertStreamError(t, stream, {cause});345};346347test('.writable() propagates write errors', testPropagateError, 'writable');348test('.duplex() propagates write errors', testPropagateError, 'duplex');
41 unmodified lines
modified:test/helpers/duplex.js+2 added-2 removed
45 unmodified lines
46export 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');50export const throwingDuplex = cause => getDuplex(() => {51 throw cause;52});5354export const appendDuplex = getDuplex(string => `${string}${casedSuffix}`);55
4 unmodified lines
modified:test/helpers/generator.js+6 added-4 removed
85 unmodified lines
86 yield string.toUpperCase();87});8889// eslint-disable-next-line require-yield90export const throwingGenerator = getGenerator(function * () {91 throw new Error('Generator error');90export const throwingGenerator = error => getGenerator(function * () {91 throw error;92});9394export const GENERATOR_ERROR_REGEXP = /Generator error/;9594export const appendGenerator = getGenerator(function * (string) {95 yield `${string}${casedSuffix}`;96});9798export const appendAsyncGenerator = getGenerator(async function * (string) {99 yield `${string}${casedSuffix}`;100});101102export const casedSuffix = 'k';103104export const resultGenerator = inputs => getGenerator(function * (input) {105 inputs.push(input);
7 unmodified lines
modified:test/helpers/web-transform.js+2 added-2 removed
43 unmodified lines
44export const uppercaseBufferWebTransform = getWebTransform((string, controller) => {45 controller.enqueue(string.toString().toUpperCase());46});4748export const throwingWebTransform = getWebTransform(() => {49 throw new Error('Generator error');48export const throwingWebTransform = cause => getWebTransform(() => {49 throw cause;50});5152export const appendWebTransform = getWebTransform((string, controller) => {53 controller.enqueue(`${string}${casedSuffix}`);
6 unmodified lines
modified:test/stdio/encoding-final.js+90 added-49 removed
6 unmodified lines
7import {execa, execaSync} from '../../index.js';8import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';9import {fullStdio} from '../helpers/stdio.js';10import {outputObjectGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';11import {foobarObject} from '../helpers/input.js';11import {foobarString, foobarUint8Array, foobarObject, foobarHex} from '../helpers/input.js';1213const pExec = promisify(exec);1415setFixtureDir();
81 unmodified lines
97test('can pass encoding "base64url" to stdio[*] - sync', checkEncoding, 'base64url', 3, execaSync);9899const foobarArray = ['fo', 'ob', 'ar', '..'];100101const testMultibyteCharacters = async (t, objectMode, addNoopTransform) => {102 const {stdout} = await execa('noop.js', {101const testMultibyteCharacters = async (t, objectMode, addNoopTransform, execaMethod) => {102 const {stdout} = await execaMethod('noop.js', {103 stdout: addNoopGenerator(getOutputsGenerator(foobarArray)(objectMode, true), addNoopTransform, objectMode),104 encoding: 'base64',105 });106 if (objectMode) {
2 unmodified lines
109 t.is(stdout, btoa(foobarArray.join('')));110 }111};112113test('Handle multibyte characters', testMultibyteCharacters, false, false);114test('Handle multibyte characters, noop transform', testMultibyteCharacters, false, true);115test('Handle multibyte characters, with objectMode', testMultibyteCharacters, true, false);116test('Handle multibyte characters, with objectMode, noop transform', testMultibyteCharacters, true, true);113test('Handle multibyte characters', testMultibyteCharacters, false, false, execa);114test('Handle multibyte characters, noop transform', testMultibyteCharacters, false, true, execa);115test('Handle multibyte characters, with objectMode', testMultibyteCharacters, true, false, execa);116test('Handle multibyte characters, with objectMode, noop transform', testMultibyteCharacters, true, true, execa);117test('Handle multibyte characters, sync', testMultibyteCharacters, false, false, execaSync);118test('Handle multibyte characters, noop transform, sync', testMultibyteCharacters, false, true, execaSync);119test('Handle multibyte characters, with objectMode, sync', testMultibyteCharacters, true, false, execaSync);120test('Handle multibyte characters, with objectMode, noop transform, sync', testMultibyteCharacters, true, true, execaSync);121118const testObjectMode = async (t, addNoopTransform) => {119 const {stdout} = await execa('noop.js', {stdout: addNoopGenerator(outputObjectGenerator(), addNoopTransform, true), encoding: 'base64'});122const testObjectMode = async (t, addNoopTransform, execaMethod) => {123 const {stdout} = await execaMethod('noop.js', {124 stdout: addNoopGenerator(outputObjectGenerator(), addNoopTransform, true),125 encoding: 'base64',126 });127 t.deepEqual(stdout, [foobarObject]);128};129123test('Other encodings work with transforms that return objects', testObjectMode, false);124test('Other encodings work with transforms that return objects, noop transform', testObjectMode, true);130test('Other encodings work with transforms that return objects', testObjectMode, false, execa);131test('Other encodings work with transforms that return objects, noop transform', testObjectMode, true, execa);132test('Other encodings work with transforms that return objects, sync', testObjectMode, false, execaSync);133test('Other encodings work with transforms that return objects, noop transform, sync', testObjectMode, true, execaSync);134135// eslint-disable-next-line max-params126const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options) => {127 const {stdout} = await execa('empty.js', {stdout: stdoutOption, ...options});136const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options, execaMethod) => {137 const {stdout} = await execaMethod('empty.js', {stdout: stdoutOption, ...options});138 t.is(stdout === undefined, isUndefined);139};140141const base64Options = {encoding: 'base64'};142const linesOptions = {lines: true};133test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options);134test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options);135test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options);136test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options);137test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options);138test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options);139test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options);140test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options);141test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options);142test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options);143test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options);144test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options);145test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options);146test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options);147test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options);148test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options);149test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options);150test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions);151test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions);152test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions);153test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions);154test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions);155test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions);156test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions);157test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions);158test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions);159test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions);160test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions);161test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions);162test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions);163test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions);164test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions);165test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions);166test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions);167test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions});168test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions});143test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options, execa);144test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options, execa);145test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options, execa);146test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options, execa);147test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options, execa);148test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options, execa);149test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options, execa);150test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options, execa);151test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options, execa);152test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options, execa);153test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options, execa);154test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options, execa);155test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options, execa);156test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options, execa);157test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options, execa);158test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options, execa);159test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options, execa);160test('Is ignored with other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, base64Options, execaSync);161test('Is ignored with other encodings and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, base64Options, execaSync);162test('Is ignored with other encodings and "inherit", sync', testIgnoredEncoding, 'inherit', true, base64Options, execaSync);163test('Is ignored with other encodings and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, base64Options, execaSync);164test('Is ignored with other encodings and 1, sync', testIgnoredEncoding, 1, true, base64Options, execaSync);165test('Is ignored with other encodings and [1], sync', testIgnoredEncoding, [1], true, base64Options, execaSync);166test('Is ignored with other encodings and process.stdout, sync', testIgnoredEncoding, process.stdout, true, base64Options, execaSync);167test('Is ignored with other encodings and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, base64Options, execaSync);168test('Is not ignored with other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, base64Options, execaSync);169test('Is not ignored with other encodings and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, base64Options, execaSync);170test('Is not ignored with other encodings and undefined, sync', testIgnoredEncoding, undefined, false, base64Options, execaSync);171test('Is not ignored with other encodings and null, sync', testIgnoredEncoding, null, false, base64Options, execaSync);172test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions, execa);173test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions, execa);174test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions, execa);175test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions, execa);176test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions, execa);177test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions, execa);178test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions, execa);179test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions, execa);180test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions, execa);181test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions, execa);182test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions, execa);183test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions, execa);184test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions, execa);185test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions, execa);186test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions, execa);187test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions, execa);188test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions, execa);189test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execa);190test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execa);191192// eslint-disable-next-line max-params193const testEncodingInput = async (t, input, expectedStdout, encoding, execaMethod) => {194 const {stdout} = await execaMethod('stdin.js', {input, encoding});195 t.deepEqual(stdout, expectedStdout);196};197198test('Can use string input', testEncodingInput, foobarString, foobarString, 'utf8', execa);199test('Can use Uint8Array input', testEncodingInput, foobarUint8Array, foobarString, 'utf8', execa);200test('Can use string input, encoding "buffer"', testEncodingInput, foobarString, foobarUint8Array, 'buffer', execa);201test('Can use Uint8Array input, encoding "buffer"', testEncodingInput, foobarUint8Array, foobarUint8Array, 'buffer', execa);202test('Can use string input, encoding "hex"', testEncodingInput, foobarString, foobarHex, 'hex', execa);203test('Can use Uint8Array input, encoding "hex"', testEncodingInput, foobarUint8Array, foobarHex, 'hex', execa);204test('Can use string input, sync', testEncodingInput, foobarString, foobarString, 'utf8', execaSync);205test('Can use Uint8Array input, sync', testEncodingInput, foobarUint8Array, foobarString, 'utf8', execaSync);206test('Can use string input, encoding "buffer", sync', testEncodingInput, foobarString, foobarUint8Array, 'buffer', execaSync);207test('Can use Uint8Array input, encoding "buffer", sync', testEncodingInput, foobarUint8Array, foobarUint8Array, 'buffer', execaSync);208test('Can use string input, encoding "hex", sync', testEncodingInput, foobarString, foobarHex, 'hex', execaSync);209test('Can use Uint8Array input, encoding "hex", sync', testEncodingInput, foobarUint8Array, foobarHex, 'hex', execaSync);
modified:test/stdio/encoding-transform.js+193 added-88 removed
1import {Buffer} from 'node:buffer';2import {scheduler} from 'node:timers/promises';2import test from 'ava';4import {execa} from '../../index.js';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {getStdio} from '../helpers/stdio.js';6import {foobarString, foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';8import {noopGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';7import {noopGenerator, getOutputGenerator, getOutputsGenerator, convertTransformToFinal} from '../helpers/generator.js';8import {multibyteChar, multibyteString, multibyteUint8Array, breakingLength, brokenSymbol} from '../helpers/encoding.js';910setFixtureDir();11
35 unmodified lines
47test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false, true);48test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, false);49test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, true);5051// eslint-disable-next-line max-params52const testGeneratorFirstEncodingSync = (t, input, encoding, expectedType, objectMode, binary) => {53 const {stdout} = execaSync('stdin.js', {stdin: [[input], getTypeofGenerator(objectMode, binary)], encoding});54 assertTypeofChunk(t, stdout, encoding, expectedType);55};5657test('First generator argument is string with default encoding, with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', false);58test('First generator argument is string with default encoding, with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'utf8', 'String', false);59test('First generator argument is Uint8Array with encoding "buffer", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false);60test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'buffer', 'Uint8Array', false);61test('First generator argument is Uint8Array with encoding "hex", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false);62test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'hex', 'Uint8Array', false);63test('First generator argument can be string with objectMode, sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', true);64test('First generator argument can be objects with objectMode, sync', testGeneratorFirstEncodingSync, foobarObject, 'utf8', 'Object', true);65test('First generator argument is string with default encoding, with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', false, false);66test('First generator argument is Uint8Array with default encoding, with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'Uint8Array', false, true);67test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false, false);68test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false, true);69test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false, false);70test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false, true);7172const testEncodingIgnored = async (t, encoding) => {73 const input = Buffer.from(foobarString).toString(encoding);74 const subprocess = execa('stdin.js', {stdin: noopGenerator(true)});75 subprocess.stdin.end(input, encoding);
6 unmodified lines
82test('Write call encoding "hex" is ignored with objectMode', testEncodingIgnored, 'hex');83test('Write call encoding "base64" is ignored with objectMode', testEncodingIgnored, 'base64');8485// eslint-disable-next-line max-params66const testGeneratorNextEncoding = async (t, input, encoding, firstObjectMode, secondObjectMode, expectedType) => {67 const {stdout} = await execa('noop.js', ['other'], {86const testGeneratorNextEncoding = async (t, input, encoding, firstObjectMode, secondObjectMode, expectedType, execaMethod) => {87 const {stdout} = await execaMethod('noop.js', ['other'], {88 stdout: [89 getOutputGenerator(input)(firstObjectMode),90 getTypeofGenerator(secondObjectMode),91 ],
2 unmodified lines
94 const output = Array.isArray(stdout) ? stdout[0] : stdout;95 assertTypeofChunk(t, output, encoding, expectedType);96};9778test('Next generator argument is string with default encoding, with string writes', testGeneratorNextEncoding, foobarString, 'utf8', false, false, 'String');79test('Next generator argument is string with default encoding, with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'utf8', true, false, 'String');80test('Next generator argument is string with default encoding, with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String');81test('Next generator argument is string with default encoding, with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String');82test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'Uint8Array');83test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'Uint8Array');84test('Next generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array');85test('Next generator argument is string with encoding "buffer", with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'String');86test('Next generator argument is string with encoding "buffer", with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'String');87test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array');88test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, false, 'Uint8Array');89test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, true, 'Uint8Array');90test('Next generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'Uint8Array');91test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'Uint8Array');92test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object');93test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object');98test('Next generator argument is string with default encoding, with string writes', testGeneratorNextEncoding, foobarString, 'utf8', false, false, 'String', execa);99test('Next generator argument is string with default encoding, with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'utf8', true, false, 'String', execa);100test('Next generator argument is string with default encoding, with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String', execa);101test('Next generator argument is string with default encoding, with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String', execa);102test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'Uint8Array', execa);103test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'Uint8Array', execa);104test('Next generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array', execa);105test('Next generator argument is string with encoding "buffer", with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'String', execa);106test('Next generator argument is string with encoding "buffer", with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'String', execa);107test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array', execa);108test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, false, 'Uint8Array', execa);109test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, true, 'Uint8Array', execa);110test('Next generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'Uint8Array', execa);111test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'Uint8Array', execa);112test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object', execa);113test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object', execa);114test('Next generator argument is string with default encoding, with string writes, sync', testGeneratorNextEncoding, foobarString, 'utf8', false, false, 'String', execaSync);115test('Next generator argument is string with default encoding, with string writes, objectMode first, sync', testGeneratorNextEncoding, foobarString, 'utf8', true, false, 'String', execaSync);116test('Next generator argument is string with default encoding, with string writes, objectMode both, sync', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String', execaSync);117test('Next generator argument is string with default encoding, with Uint8Array writes, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String', execaSync);118test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'Uint8Array', execaSync);119test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'Uint8Array', execaSync);120test('Next generator argument is Uint8Array with encoding "buffer", with string writes, sync', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array', execaSync);121test('Next generator argument is string with encoding "buffer", with string writes, objectMode first, sync', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'String', execaSync);122test('Next generator argument is string with encoding "buffer", with string writes, objectMode both, sync', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'String', execaSync);123test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array', execaSync);124test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first, sync', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, false, 'Uint8Array', execaSync);125test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both, sync', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, true, 'Uint8Array', execaSync);126test('Next generator argument is Uint8Array with encoding "hex", with string writes, sync', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'Uint8Array', execaSync);127test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes, sync', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'Uint8Array', execaSync);128test('Next generator argument is object with default encoding, with object writes, objectMode first, sync', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object', execaSync);129test('Next generator argument is object with default encoding, with object writes, objectMode both, sync', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object', execaSync);13095const testFirstOutputGeneratorArgument = async (t, fdNumber) => {96 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));131const testFirstOutputGeneratorArgument = async (t, fdNumber, execaMethod) => {132 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));133 t.deepEqual(stdio[fdNumber], ['[object String]']);134};135100test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1);101test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2);102test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 3);136test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1, execa);137test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2, execa);138test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 3, execa);139test('The first generator with result.stdout does not receive an object argument even in objectMode, sync', testFirstOutputGeneratorArgument, 1, execaSync);140test('The first generator with result.stderr does not receive an object argument even in objectMode, sync', testFirstOutputGeneratorArgument, 2, execaSync);141test('The first generator with result.stdio[*] does not receive an object argument even in objectMode, sync', testFirstOutputGeneratorArgument, 3, execaSync);142143// eslint-disable-next-line max-params105const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final) => {144const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final, execaMethod) => {145 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';107 const {stdout} = await execa(fixtureName, ['1', foobarString], {146 const {stdout} = await execaMethod(fixtureName, ['1', foobarString], {147 stdout: convertTransformToFinal(getOutputGenerator(input)(objectMode, true), final),148 encoding,149 reject,150 });
1 unmodified line
152 const output = Buffer.from(typeofChunk, encoding === 'buffer' || objectMode ? undefined : encoding).toString();153 t.is(output, foobarString);154};155117test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false);118test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false);119test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false);120test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false);121test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false);122test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false);123test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false);124test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false);125test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false);126test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false);127test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false);128test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false);129test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false);130test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false);131test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false);132test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false);133test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false);134test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false);135test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false);136test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false);137test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false);138test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false);139test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false);140test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false);141test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true);142test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true);143test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true);144test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true);145test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true);146test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true);147test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true);148test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true);149test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true);150test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true);151test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true);152test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true);153test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true);154test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true);155test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true);156test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true);157test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true);158test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true);159test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true);160test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true);161test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true);162test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true);163test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true);164test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true);156test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false, execa);157test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false, execa);158test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false, execa);159test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false, execa);160test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false, execa);161test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false, execa);162test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false, execa);163test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false, execa);164test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false, execa);165test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false, execa);166test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false, execa);167test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false, execa);168test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false, execa);169test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false, execa);170test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false, execa);171test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false, execa);172test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false, execa);173test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false, execa);174test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false, execa);175test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false, execa);176test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false, execa);177test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false, execa);178test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false, execa);179test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false, execa);180test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true, execa);181test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true, execa);182test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true, execa);183test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true, execa);184test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true, execa);185test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true, execa);186test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true, execa);187test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true, execa);188test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true, execa);189test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true, execa);190test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true, execa);191test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true, execa);192test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true, execa);193test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true, execa);194test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true, execa);195test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true, execa);196test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true, execa);197test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true, execa);198test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true, execa);199test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true, execa);200test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true, execa);201test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true, execa);202test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true, execa);203test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true, execa);204test('Generator can return string with default encoding, sync', testGeneratorReturnType, foobarString, 'utf8', true, false, false, execaSync);205test('Generator can return Uint8Array with default encoding, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false, execaSync);206test('Generator can return string with encoding "buffer", sync', testGeneratorReturnType, foobarString, 'buffer', true, false, false, execaSync);207test('Generator can return Uint8Array with encoding "buffer", sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false, execaSync);208test('Generator can return string with encoding "hex", sync', testGeneratorReturnType, foobarString, 'hex', true, false, false, execaSync);209test('Generator can return Uint8Array with encoding "hex", sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false, execaSync);210test('Generator can return string with default encoding, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, false, false, execaSync);211test('Generator can return Uint8Array with default encoding, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false, execaSync);212test('Generator can return string with encoding "buffer", failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, false, false, execaSync);213test('Generator can return Uint8Array with encoding "buffer", failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false, execaSync);214test('Generator can return string with encoding "hex", failure, sync', testGeneratorReturnType, foobarString, 'hex', false, false, false, execaSync);215test('Generator can return Uint8Array with encoding "hex", failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false, execaSync);216test('Generator can return string with default encoding, objectMode, sync', testGeneratorReturnType, foobarString, 'utf8', true, true, false, execaSync);217test('Generator can return Uint8Array with default encoding, objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false, execaSync);218test('Generator can return string with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarString, 'buffer', true, true, false, execaSync);219test('Generator can return Uint8Array with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false, execaSync);220test('Generator can return string with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarString, 'hex', true, true, false, execaSync);221test('Generator can return Uint8Array with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false, execaSync);222test('Generator can return string with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, true, false, execaSync);223test('Generator can return Uint8Array with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false, execaSync);224test('Generator can return string with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, true, false, execaSync);225test('Generator can return Uint8Array with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false, execaSync);226test('Generator can return string with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'hex', false, true, false, execaSync);227test('Generator can return Uint8Array with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false, execaSync);228test('Generator can return final string with default encoding, sync', testGeneratorReturnType, foobarString, 'utf8', true, false, true, execaSync);229test('Generator can return final Uint8Array with default encoding, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true, execaSync);230test('Generator can return final string with encoding "buffer", sync', testGeneratorReturnType, foobarString, 'buffer', true, false, true, execaSync);231test('Generator can return final Uint8Array with encoding "buffer", sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true, execaSync);232test('Generator can return final string with encoding "hex", sync', testGeneratorReturnType, foobarString, 'hex', true, false, true, execaSync);233test('Generator can return final Uint8Array with encoding "hex", sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true, execaSync);234test('Generator can return final string with default encoding, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, false, true, execaSync);235test('Generator can return final Uint8Array with default encoding, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true, execaSync);236test('Generator can return final string with encoding "buffer", failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, false, true, execaSync);237test('Generator can return final Uint8Array with encoding "buffer", failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true, execaSync);238test('Generator can return final string with encoding "hex", failure, sync', testGeneratorReturnType, foobarString, 'hex', false, false, true, execaSync);239test('Generator can return final Uint8Array with encoding "hex", failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true, execaSync);240test('Generator can return final string with default encoding, objectMode, sync', testGeneratorReturnType, foobarString, 'utf8', true, true, true, execaSync);241test('Generator can return final Uint8Array with default encoding, objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true, execaSync);242test('Generator can return final string with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarString, 'buffer', true, true, true, execaSync);243test('Generator can return final Uint8Array with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true, execaSync);244test('Generator can return final string with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarString, 'hex', true, true, true, execaSync);245test('Generator can return final Uint8Array with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true, execaSync);246test('Generator can return final string with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, true, true, execaSync);247test('Generator can return final Uint8Array with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true, execaSync);248test('Generator can return final string with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, true, true, execaSync);249test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true, execaSync);250test('Generator can return final string with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'hex', false, true, true, execaSync);251test('Generator can return final Uint8Array with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true, execaSync);252166const testMultibyte = async (t, objectMode) => {167 const subprocess = execa('stdin.js', {stdin: noopGenerator(objectMode, true)});168 subprocess.stdin.write(multibyteUint8Array.slice(0, breakingLength));169 await scheduler.yield();170 subprocess.stdin.end(multibyteUint8Array.slice(breakingLength));171 const {stdout} = await subprocess;253const testMultibyte = async (t, objectMode, execaMethod) => {254 const {stdout} = await execaMethod('stdin.js', {255 stdin: [256 [multibyteUint8Array.slice(0, breakingLength), multibyteUint8Array.slice(breakingLength)],257 noopGenerator(objectMode, true),258 ],259 });260 t.is(stdout, multibyteString);261};262175test('Generator handles multibyte characters with Uint8Array', testMultibyte, false);176test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true);263test('Generator handles multibyte characters with Uint8Array', testMultibyte, false, execa);264test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true, execa);265test('Generator handles multibyte characters with Uint8Array, sync', testMultibyte, false, execaSync);266test('Generator handles multibyte characters with Uint8Array, objectMode, sync', testMultibyte, true, execaSync);267178const testMultibytePartial = async (t, objectMode) => {179 const {stdout} = await execa('stdin.js', {268const testMultibytePartial = async (t, objectMode, execaMethod) => {269 const {stdout} = await execaMethod('stdin.js', {270 stdin: [271 [multibyteUint8Array.slice(0, breakingLength)],272 noopGenerator(objectMode, true),273 ],274 });275 t.is(stdout, `${multibyteChar}${brokenSymbol}`);276};277188test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false);189test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true);278test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false, execa);279test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true, execa);280test('Generator handles partial multibyte characters with Uint8Array, sync', testMultibytePartial, false, execaSync);281test('Generator handles partial multibyte characters with Uint8Array, objectMode, sync', testMultibytePartial, true, execaSync);282283const testMultibytePartialOutput = async (t, execaMethod) => {284 const {stdout} = await execaMethod('noop.js', {285 stdout: getOutputsGenerator([286 multibyteUint8Array.slice(0, breakingLength),287 multibyteUint8Array.slice(breakingLength),288 ])(false, true),289 });290 t.is(stdout, multibyteString);291};292293test('Generator handles output multibyte characters with Uint8Array', testMultibytePartialOutput, execa);294test('Generator handles output multibyte characters with Uint8Array, sync', testMultibytePartialOutput, execaSync);
modified:test/stdio/file-path.js+122 added-1 removed
1 unmodified line
2import {relative, dirname, basename} from 'node:path';3import process from 'node:process';4import {pathToFileURL} from 'node:url';5import test from 'ava';6import {pathExists} from 'path-exists';7import tempfile from 'tempfile';8import {execa, execaSync} from '../../index.js';9import {setFixtureDir} from '../helpers/fixtures-dir.js';10import {identity, getStdio} from '../helpers/stdio.js';11import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';11import {foobarString, foobarUint8Array} from '../helpers/input.js';12import {foobarString, foobarUint8Array, foobarUppercase} from '../helpers/input.js';13import {outputObjectGenerator, uppercaseGenerator, serializeGenerator, throwingGenerator} from '../helpers/generator.js';1415setFixtureDir();1617const nonFileUrl = new URL('https://example.com');
216 unmodified lines
234};235236test('Passing an input file path when subprocess exits does not make promise hang', testInputFileHanging, getAbsolutePath);237test('Passing an input file URL when subprocess exits does not make promise hang', testInputFileHanging, pathToFileURL);238239const testInputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {240 const filePath = tempfile();241 await writeFile(filePath, foobarString);242 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [243 new Uint8Array(),244 mapFile(filePath),245 uppercaseGenerator(),246 ]));247 t.is(stdout, foobarUppercase);248 await rm(filePath);249};250251test('stdin can use generators together with input file paths', testInputFileTransform, 0, getAbsolutePath, execa);252test('stdin can use generators together with input file URLs', testInputFileTransform, 0, pathToFileURL, execa);253test('stdio[*] can use generators together with input file paths', testInputFileTransform, 3, getAbsolutePath, execa);254test('stdio[*] can use generators together with input file URLs', testInputFileTransform, 3, pathToFileURL, execa);255test('stdin can use generators together with input file paths, sync', testInputFileTransform, 0, getAbsolutePath, execaSync);256test('stdin can use generators together with input file URLs, sync', testInputFileTransform, 0, pathToFileURL, execaSync);257258const testInputFileObject = async (t, fdNumber, mapFile, execaMethod) => {259 const filePath = tempfile();260 await writeFile(filePath, foobarString);261 t.throws(() => {262 execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [263 new Uint8Array(),264 mapFile(filePath),265 serializeGenerator(true),266 ]));267 }, {message: /cannot use both files and transforms in objectMode/});268 await rm(filePath);269};270271test('stdin cannot use objectMode together with input file paths', testInputFileObject, 0, getAbsolutePath, execa);272test('stdin cannot use objectMode together with input file URLs', testInputFileObject, 0, pathToFileURL, execa);273test('stdio[*] cannot use objectMode together with input file paths', testInputFileObject, 3, getAbsolutePath, execa);274test('stdio[*] cannot use objectMode together with input file URLs', testInputFileObject, 3, pathToFileURL, execa);275test('stdin cannot use objectMode together with input file paths, sync', testInputFileObject, 0, getAbsolutePath, execaSync);276test('stdin cannot use objectMode together with input file URLs, sync', testInputFileObject, 0, pathToFileURL, execaSync);277278const testOutputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {279 const filePath = tempfile();280 await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [281 uppercaseGenerator(),282 mapFile(filePath),283 ]));284 t.is(await readFile(filePath, 'utf8'), `${foobarUppercase}\n`);285 await rm(filePath);286};287288test('stdout can use generators together with output file paths', testOutputFileTransform, 1, getAbsolutePath, execa);289test('stdout can use generators together with output file URLs', testOutputFileTransform, 1, pathToFileURL, execa);290test('stderr can use generators together with output file paths', testOutputFileTransform, 2, getAbsolutePath, execa);291test('stderr can use generators together with output file URLs', testOutputFileTransform, 2, pathToFileURL, execa);292test('stdio[*] can use generators together with output file paths', testOutputFileTransform, 3, getAbsolutePath, execa);293test('stdio[*] can use generators together with output file URLs', testOutputFileTransform, 3, pathToFileURL, execa);294test('stdout can use generators together with output file paths, sync', testOutputFileTransform, 1, getAbsolutePath, execaSync);295test('stdout can use generators together with output file URLs, sync', testOutputFileTransform, 1, pathToFileURL, execaSync);296test('stderr can use generators together with output file paths, sync', testOutputFileTransform, 2, getAbsolutePath, execaSync);297test('stderr can use generators together with output file URLs, sync', testOutputFileTransform, 2, pathToFileURL, execaSync);298test('stdio[*] can use generators together with output file paths, sync', testOutputFileTransform, 3, getAbsolutePath, execaSync);299test('stdio[*] can use generators together with output file URLs, sync', testOutputFileTransform, 3, pathToFileURL, execaSync);300301const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {302 const filePath = tempfile();303 t.throws(() => {304 execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [305 outputObjectGenerator(),306 mapFile(filePath),307 ]));308 }, {message: /cannot use both files and transforms in objectMode/});309 t.false(await pathExists(filePath));310};311312test('stdout cannot use objectMode together with output file paths', testOutputFileObject, 1, getAbsolutePath, execa);313test('stdout cannot use objectMode together with output file URLs', testOutputFileObject, 1, pathToFileURL, execa);314test('stderr cannot use objectMode together with output file paths', testOutputFileObject, 2, getAbsolutePath, execa);315test('stderr cannot use objectMode together with output file URLs', testOutputFileObject, 2, pathToFileURL, execa);316test('stdio[*] cannot use objectMode together with output file paths', testOutputFileObject, 3, getAbsolutePath, execa);317test('stdio[*] cannot use objectMode together with output file URLs', testOutputFileObject, 3, pathToFileURL, execa);318test('stdout cannot use objectMode together with output file paths, sync', testOutputFileObject, 1, getAbsolutePath, execaSync);319test('stdout cannot use objectMode together with output file URLs, sync', testOutputFileObject, 1, pathToFileURL, execaSync);320test('stderr cannot use objectMode together with output file paths, sync', testOutputFileObject, 2, getAbsolutePath, execaSync);321test('stderr cannot use objectMode together with output file URLs, sync', testOutputFileObject, 2, pathToFileURL, execaSync);322test('stdio[*] cannot use objectMode together with output file paths, sync', testOutputFileObject, 3, getAbsolutePath, execaSync);323test('stdio[*] cannot use objectMode together with output file URLs, sync', testOutputFileObject, 3, pathToFileURL, execaSync);324325test('Generator error stops writing to output file', async t => {326 const filePath = tempfile();327 const cause = new Error(foobarString);328 const error = await t.throwsAsync(execa('noop.js', {329 stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],330 }));331 t.is(error.cause, cause);332 t.is(await readFile(filePath, 'utf8'), '');333});334335test('Generator error does not create output file, sync', async t => {336 const filePath = tempfile();337 const cause = new Error(foobarString);338 const error = t.throws(() => {339 execaSync('noop.js', {340 stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],341 });342 });343 t.is(error.cause, cause);344 t.false(await pathExists(filePath));345});346347test('Output file error still returns transformed output, sync', async t => {348 const filePath = tempfile();349 const {stdout} = t.throws(() => {350 execaSync('noop-fd.js', ['1', foobarString], {351 stdout: [uppercaseGenerator(), getAbsolutePath('./unknown/file')],352 });353 }, {code: 'ENOENT'});354 t.false(await pathExists(filePath));355 t.is(stdout, foobarUppercase);356});
modified:test/stdio/generator.js+271 added-206 removed
2 unmodified lines
3import {PassThrough} from 'node:stream';4import test from 'ava';5import getStream, {getStreamAsArray} from 'get-stream';6import tempfile from 'tempfile';7import {execa} from '../../index.js';7import {execa, execaSync} from '../../index.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {getStdio} from '../helpers/stdio.js';10import {11 foobarString,
8 unmodified lines
20 outputObjectGenerator,21 uppercaseGenerator,22 uppercaseBufferGenerator,23 appendGenerator,24 appendAsyncGenerator,25 casedSuffix,26} from '../helpers/generator.js';27import {appendDuplex, uppercaseBufferDuplex} from '../helpers/duplex.js';28import {appendWebTransform, uppercaseBufferWebTransform} from '../helpers/web-transform.js';
27 unmodified lines
56 getStreamMethod: getStream,57 };5859// eslint-disable-next-line max-params59const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform, type) => {60const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform, type, execaMethod) => {61 const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);61 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, ...generators]));62 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, ...generators]));63 t.is(stdout, output);64};6565test('Can use generators with result.stdin', testGeneratorInput, 0, false, false, 'generator');66test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'generator');67test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'generator');68test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'generator');69test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'generator');70test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'generator');71test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'generator');72test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'generator');73test('Can use duplexes with result.stdin', testGeneratorInput, 0, false, false, 'duplex');74test('Can use duplexes with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'duplex');75test('Can use duplexes with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'duplex');76test('Can use duplexes with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'duplex');77test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex');78test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex');79test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex');80test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex');81test('Can use webTransforms with result.stdin', testGeneratorInput, 0, false, false, 'webTransform');82test('Can use webTransforms with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'webTransform');83test('Can use webTransforms with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'webTransform');84test('Can use webTransforms with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'webTransform');85test('Can use webTransforms with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'webTransform');86test('Can use webTransforms with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'webTransform');87test('Can use webTransforms with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'webTransform');88test('Can use webTransforms with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'webTransform');66test('Can use generators with result.stdin', testGeneratorInput, 0, false, false, 'generator', execa);67test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'generator', execa);68test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'generator', execa);69test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'generator', execa);70test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'generator', execa);71test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'generator', execa);72test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'generator', execa);73test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'generator', execa);74test('Can use generators with result.stdin, sync', testGeneratorInput, 0, false, false, 'generator', execaSync);75test('Can use generators with result.stdin, objectMode, sync', testGeneratorInput, 0, true, false, 'generator', execaSync);76test('Can use generators with result.stdin, noop transform, sync', testGeneratorInput, 0, false, true, 'generator', execaSync);77test('Can use generators with result.stdin, objectMode, noop transform, sync', testGeneratorInput, 0, true, true, 'generator', execaSync);78test('Can use duplexes with result.stdin', testGeneratorInput, 0, false, false, 'duplex', execa);79test('Can use duplexes with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'duplex', execa);80test('Can use duplexes with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'duplex', execa);81test('Can use duplexes with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'duplex', execa);82test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex', execa);83test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex', execa);84test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex', execa);85test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex', execa);86test('Can use webTransforms with result.stdin', testGeneratorInput, 0, false, false, 'webTransform', execa);87test('Can use webTransforms with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'webTransform', execa);88test('Can use webTransforms with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'webTransform', execa);89test('Can use webTransforms with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'webTransform', execa);90test('Can use webTransforms with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'webTransform', execa);91test('Can use webTransforms with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'webTransform', execa);92test('Can use webTransforms with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'webTransform', execa);93test('Can use webTransforms with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'webTransform', execa);9495// eslint-disable-next-line max-params96const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {97 const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);
74 unmodified lines
172test('Can use webTransforms with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'webTransform');173test('Can use webTransforms with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'webTransform');174175// eslint-disable-next-line max-params171const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type) => {176const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type, execaMethod) => {177 const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);178 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';174 const {stdout, stderr, stdio} = await execa(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generators), reject});179 const {stdout, stderr, stdio} = await execaMethod(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generators), reject});180 const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];181 t.deepEqual(result, output);182};183179test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'generator');180test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'generator');181test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'generator');182test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'generator');183test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'generator');184test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'generator');185test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'generator');186test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'generator');187test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'generator');188test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'generator');189test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'generator');190test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'generator');191test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'generator');192test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'generator');193test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'generator');194test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'generator');195test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'generator');196test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'generator');197test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'generator');198test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'generator');199test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'generator');200test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'generator');201test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'generator');202test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'generator');203test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'generator');204test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'generator');205test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'generator');206test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'generator');207test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'generator');208test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'generator');209test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'generator');210test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'generator');211test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'generator');212test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'generator');213test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'generator');214test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'generator');215test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'generator');216test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'generator');217test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'generator');218test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'generator');219test('Can use duplexes with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'duplex');220test('Can use duplexes with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'duplex');221test('Can use duplexes with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'duplex');222test('Can use duplexes with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'duplex');223test('Can use duplexes with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'duplex');224test('Can use duplexes with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'duplex');225test('Can use duplexes with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'duplex');226test('Can use duplexes with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'duplex');227test('Can use duplexes with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'duplex');228test('Can use duplexes with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'duplex');229test('Can use duplexes with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'duplex');230test('Can use duplexes with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'duplex');231test('Can use duplexes with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'duplex');232test('Can use duplexes with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'duplex');233test('Can use duplexes with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'duplex');234test('Can use duplexes with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'duplex');235test('Can use duplexes with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'duplex');236test('Can use duplexes with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'duplex');237test('Can use duplexes with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'duplex');238test('Can use duplexes with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'duplex');239test('Can use duplexes with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'duplex');240test('Can use duplexes with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'duplex');241test('Can use duplexes with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'duplex');242test('Can use duplexes with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'duplex');243test('Can use duplexes with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'duplex');244test('Can use duplexes with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'duplex');245test('Can use duplexes with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'duplex');246test('Can use duplexes with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'duplex');247test('Can use duplexes with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'duplex');248test('Can use duplexes with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'duplex');249test('Can use duplexes with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'duplex');250test('Can use duplexes with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'duplex');251test('Can use duplexes with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'duplex');252test('Can use duplexes with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'duplex');253test('Can use duplexes with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'duplex');254test('Can use duplexes with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'duplex');255test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex');256test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex');257test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex');258test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex');259test('Can use webTransforms with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'webTransform');260test('Can use webTransforms with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'webTransform');261test('Can use webTransforms with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'webTransform');262test('Can use webTransforms with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'webTransform');263test('Can use webTransforms with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'webTransform');264test('Can use webTransforms with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'webTransform');265test('Can use webTransforms with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'webTransform');266test('Can use webTransforms with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'webTransform');267test('Can use webTransforms with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'webTransform');268test('Can use webTransforms with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'webTransform');269test('Can use webTransforms with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'webTransform');270test('Can use webTransforms with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'webTransform');271test('Can use webTransforms with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'webTransform');272test('Can use webTransforms with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'webTransform');273test('Can use webTransforms with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'webTransform');274test('Can use webTransforms with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'webTransform');275test('Can use webTransforms with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'webTransform');276test('Can use webTransforms with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'webTransform');277test('Can use webTransforms with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'webTransform');278test('Can use webTransforms with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'webTransform');279test('Can use webTransforms with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'webTransform');280test('Can use webTransforms with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'webTransform');281test('Can use webTransforms with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'webTransform');282test('Can use webTransforms with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'webTransform');283test('Can use webTransforms with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'webTransform');284test('Can use webTransforms with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'webTransform');285test('Can use webTransforms with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'webTransform');286test('Can use webTransforms with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'webTransform');287test('Can use webTransforms with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'webTransform');288test('Can use webTransforms with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'webTransform');289test('Can use webTransforms with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'webTransform');290test('Can use webTransforms with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'webTransform');291test('Can use webTransforms with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'webTransform');292test('Can use webTransforms with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'webTransform');293test('Can use webTransforms with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'webTransform');294test('Can use webTransforms with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'webTransform');295test('Can use webTransforms with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'webTransform');296test('Can use webTransforms with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'webTransform');297test('Can use webTransforms with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'webTransform');298test('Can use webTransforms with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'webTransform');184test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'generator', execa);185test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'generator', execa);186test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'generator', execa);187test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'generator', execa);188test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'generator', execa);189test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'generator', execa);190test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'generator', execa);191test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'generator', execa);192test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'generator', execa);193test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'generator', execa);194test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'generator', execa);195test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'generator', execa);196test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'generator', execa);197test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'generator', execa);198test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'generator', execa);199test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'generator', execa);200test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'generator', execa);201test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'generator', execa);202test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'generator', execa);203test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'generator', execa);204test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'generator', execa);205test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'generator', execa);206test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'generator', execa);207test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'generator', execa);208test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'generator', execa);209test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'generator', execa);210test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'generator', execa);211test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'generator', execa);212test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'generator', execa);213test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'generator', execa);214test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'generator', execa);215test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'generator', execa);216test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'generator', execa);217test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'generator', execa);218test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'generator', execa);219test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'generator', execa);220test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'generator', execa);221test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'generator', execa);222test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'generator', execa);223test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'generator', execa);224test('Can use generators with result.stdio[1], sync', testGeneratorOutput, 1, true, false, false, false, 'generator', execaSync);225test('Can use generators with result.stdout, sync', testGeneratorOutput, 1, true, true, false, false, 'generator', execaSync);226test('Can use generators with result.stdio[2], sync', testGeneratorOutput, 2, true, false, false, false, 'generator', execaSync);227test('Can use generators with result.stderr, sync', testGeneratorOutput, 2, true, true, false, false, 'generator', execaSync);228test('Can use generators with result.stdio[*] as output, sync', testGeneratorOutput, 3, true, false, false, false, 'generator', execaSync);229test('Can use generators with error.stdio[1], sync', testGeneratorOutput, 1, false, false, false, false, 'generator', execaSync);230test('Can use generators with error.stdout, sync', testGeneratorOutput, 1, false, true, false, false, 'generator', execaSync);231test('Can use generators with error.stdio[2], sync', testGeneratorOutput, 2, false, false, false, false, 'generator', execaSync);232test('Can use generators with error.stderr, sync', testGeneratorOutput, 2, false, true, false, false, 'generator', execaSync);233test('Can use generators with error.stdio[*] as output, sync', testGeneratorOutput, 3, false, false, false, false, 'generator', execaSync);234test('Can use generators with result.stdio[1], objectMode, sync', testGeneratorOutput, 1, true, false, true, false, 'generator', execaSync);235test('Can use generators with result.stdout, objectMode, sync', testGeneratorOutput, 1, true, true, true, false, 'generator', execaSync);236test('Can use generators with result.stdio[2], objectMode, sync', testGeneratorOutput, 2, true, false, true, false, 'generator', execaSync);237test('Can use generators with result.stderr, objectMode, sync', testGeneratorOutput, 2, true, true, true, false, 'generator', execaSync);238test('Can use generators with result.stdio[*] as output, objectMode, sync', testGeneratorOutput, 3, true, false, true, false, 'generator', execaSync);239test('Can use generators with error.stdio[1], objectMode, sync', testGeneratorOutput, 1, false, false, true, false, 'generator', execaSync);240test('Can use generators with error.stdout, objectMode, sync', testGeneratorOutput, 1, false, true, true, false, 'generator', execaSync);241test('Can use generators with error.stdio[2], objectMode, sync', testGeneratorOutput, 2, false, false, true, false, 'generator', execaSync);242test('Can use generators with error.stderr, objectMode, sync', testGeneratorOutput, 2, false, true, true, false, 'generator', execaSync);243test('Can use generators with error.stdio[*] as output, objectMode, sync', testGeneratorOutput, 3, false, false, true, false, 'generator', execaSync);244test('Can use generators with result.stdio[1], noop transform, sync', testGeneratorOutput, 1, true, false, false, true, 'generator', execaSync);245test('Can use generators with result.stdout, noop transform, sync', testGeneratorOutput, 1, true, true, false, true, 'generator', execaSync);246test('Can use generators with result.stdio[2], noop transform, sync', testGeneratorOutput, 2, true, false, false, true, 'generator', execaSync);247test('Can use generators with result.stderr, noop transform, sync', testGeneratorOutput, 2, true, true, false, true, 'generator', execaSync);248test('Can use generators with result.stdio[*] as output, noop transform, sync', testGeneratorOutput, 3, true, false, false, true, 'generator', execaSync);249test('Can use generators with error.stdio[1], noop transform, sync', testGeneratorOutput, 1, false, false, false, true, 'generator', execaSync);250test('Can use generators with error.stdout, noop transform, sync', testGeneratorOutput, 1, false, true, false, true, 'generator', execaSync);251test('Can use generators with error.stdio[2], noop transform, sync', testGeneratorOutput, 2, false, false, false, true, 'generator', execaSync);252test('Can use generators with error.stderr, noop transform, sync', testGeneratorOutput, 2, false, true, false, true, 'generator', execaSync);253test('Can use generators with error.stdio[*] as output, noop transform, sync', testGeneratorOutput, 3, false, false, false, true, 'generator', execaSync);254test('Can use generators with result.stdio[1], objectMode, noop transform, sync', testGeneratorOutput, 1, true, false, true, true, 'generator', execaSync);255test('Can use generators with result.stdout, objectMode, noop transform, sync', testGeneratorOutput, 1, true, true, true, true, 'generator', execaSync);256test('Can use generators with result.stdio[2], objectMode, noop transform, sync', testGeneratorOutput, 2, true, false, true, true, 'generator', execaSync);257test('Can use generators with result.stderr, objectMode, noop transform, sync', testGeneratorOutput, 2, true, true, true, true, 'generator', execaSync);258test('Can use generators with result.stdio[*] as output, objectMode, noop transform, sync', testGeneratorOutput, 3, true, false, true, true, 'generator', execaSync);259test('Can use generators with error.stdio[1], objectMode, noop transform, sync', testGeneratorOutput, 1, false, false, true, true, 'generator', execaSync);260test('Can use generators with error.stdout, objectMode, noop transform, sync', testGeneratorOutput, 1, false, true, true, true, 'generator', execaSync);261test('Can use generators with error.stdio[2], objectMode, noop transform, sync', testGeneratorOutput, 2, false, false, true, true, 'generator', execaSync);262test('Can use generators with error.stderr, objectMode, noop transform, sync', testGeneratorOutput, 2, false, true, true, true, 'generator', execaSync);263test('Can use generators with error.stdio[*] as output, objectMode, noop transform, sync', testGeneratorOutput, 3, false, false, true, true, 'generator', execaSync);264test('Can use duplexes with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'duplex', execa);265test('Can use duplexes with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'duplex', execa);266test('Can use duplexes with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'duplex', execa);267test('Can use duplexes with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'duplex', execa);268test('Can use duplexes with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'duplex', execa);269test('Can use duplexes with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'duplex', execa);270test('Can use duplexes with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'duplex', execa);271test('Can use duplexes with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'duplex', execa);272test('Can use duplexes with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'duplex', execa);273test('Can use duplexes with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'duplex', execa);274test('Can use duplexes with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'duplex', execa);275test('Can use duplexes with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'duplex', execa);276test('Can use duplexes with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'duplex', execa);277test('Can use duplexes with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'duplex', execa);278test('Can use duplexes with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'duplex', execa);279test('Can use duplexes with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'duplex', execa);280test('Can use duplexes with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'duplex', execa);281test('Can use duplexes with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'duplex', execa);282test('Can use duplexes with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'duplex', execa);283test('Can use duplexes with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'duplex', execa);284test('Can use duplexes with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'duplex', execa);285test('Can use duplexes with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'duplex', execa);286test('Can use duplexes with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'duplex', execa);287test('Can use duplexes with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'duplex', execa);288test('Can use duplexes with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'duplex', execa);289test('Can use duplexes with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'duplex', execa);290test('Can use duplexes with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'duplex', execa);291test('Can use duplexes with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'duplex', execa);292test('Can use duplexes with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'duplex', execa);293test('Can use duplexes with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'duplex', execa);294test('Can use duplexes with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'duplex', execa);295test('Can use duplexes with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'duplex', execa);296test('Can use duplexes with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'duplex', execa);297test('Can use duplexes with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'duplex', execa);298test('Can use duplexes with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'duplex', execa);299test('Can use duplexes with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'duplex', execa);300test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex', execa);301test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex', execa);302test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex', execa);303test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex', execa);304test('Can use webTransforms with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'webTransform', execa);305test('Can use webTransforms with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'webTransform', execa);306test('Can use webTransforms with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'webTransform', execa);307test('Can use webTransforms with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'webTransform', execa);308test('Can use webTransforms with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'webTransform', execa);309test('Can use webTransforms with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'webTransform', execa);310test('Can use webTransforms with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'webTransform', execa);311test('Can use webTransforms with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'webTransform', execa);312test('Can use webTransforms with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'webTransform', execa);313test('Can use webTransforms with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'webTransform', execa);314test('Can use webTransforms with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'webTransform', execa);315test('Can use webTransforms with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'webTransform', execa);316test('Can use webTransforms with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'webTransform', execa);317test('Can use webTransforms with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'webTransform', execa);318test('Can use webTransforms with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'webTransform', execa);319test('Can use webTransforms with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'webTransform', execa);320test('Can use webTransforms with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'webTransform', execa);321test('Can use webTransforms with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'webTransform', execa);322test('Can use webTransforms with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'webTransform', execa);323test('Can use webTransforms with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'webTransform', execa);324test('Can use webTransforms with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'webTransform', execa);325test('Can use webTransforms with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'webTransform', execa);326test('Can use webTransforms with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'webTransform', execa);327test('Can use webTransforms with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'webTransform', execa);328test('Can use webTransforms with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'webTransform', execa);329test('Can use webTransforms with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'webTransform', execa);330test('Can use webTransforms with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'webTransform', execa);331test('Can use webTransforms with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'webTransform', execa);332test('Can use webTransforms with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'webTransform', execa);333test('Can use webTransforms with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'webTransform', execa);334test('Can use webTransforms with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'webTransform', execa);335test('Can use webTransforms with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'webTransform', execa);336test('Can use webTransforms with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'webTransform', execa);337test('Can use webTransforms with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'webTransform', execa);338test('Can use webTransforms with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'webTransform', execa);339test('Can use webTransforms with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'webTransform', execa);340test('Can use webTransforms with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'webTransform', execa);341test('Can use webTransforms with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'webTransform', execa);342test('Can use webTransforms with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'webTransform', execa);343test('Can use webTransforms with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'webTransform', execa);344345// eslint-disable-next-line max-params346const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {347 const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);
156 unmodified lines
504test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false);505test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false);506test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false);507463const testInputOption = async (t, type) => {464 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});508const testInputOption = async (t, type, execaMethod) => {509 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});510 t.is(stdout, foobarUppercase);511};512468test('Can use generators with input option', testInputOption, 'generator');469test('Can use duplexes with input option', testInputOption, 'duplex');470test('Can use webTransforms with input option', testInputOption, 'webTransform');513test('Can use generators with input option', testInputOption, 'generator', execa);514test('Can use generators with input option, sync', testInputOption, 'generator', execaSync);515test('Can use duplexes with input option', testInputOption, 'duplex', execa);516test('Can use webTransforms with input option', testInputOption, 'webTransform', execa);517472const testInputFile = async (t, getOptions, reversed) => {518// eslint-disable-next-line max-params519const testInputFile = async (t, stdinOption, useInputFile, reversed, execaMethod) => {520 const filePath = tempfile();521 await writeFile(filePath, foobarString);475 const {stdin, ...options} = getOptions(filePath);476 const reversedStdin = reversed ? stdin.reverse() : stdin;477 const {stdout} = await execa('stdin-fd.js', ['0'], {...options, stdin: reversedStdin});522 const options = useInputFile523 ? {inputFile: filePath, stdin: stdinOption}524 : {stdin: [{file: filePath}, stdinOption]};525 options.stdin = reversed ? options.stdin.reverse() : options.stdin;526 const {stdout} = await execaMethod('stdin-fd.js', ['0'], options);527 t.is(stdout, foobarUppercase);528 await rm(filePath);529};530482test('Can use generators with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseGenerator()]}), false);483test('Can use generators with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseGenerator()]}), true);484test('Can use generators with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseGenerator()}), false);485test('Can use duplexes with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), false);486test('Can use duplexes with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferDuplex()]}), true);487test('Can use duplexes with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferDuplex()}), false);488test('Can use webTransforms with a file as input', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferWebTransform()]}), false);489test('Can use webTransforms with a file as input, reversed', testInputFile, filePath => ({stdin: [{file: filePath}, uppercaseBufferWebTransform()]}), true);490test('Can use webTransforms with inputFile option', testInputFile, filePath => ({inputFile: filePath, stdin: uppercaseBufferWebTransform()}), false);531test('Can use generators with a file as input', testInputFile, uppercaseGenerator(), false, false, execa);532test('Can use generators with a file as input, reversed', testInputFile, uppercaseGenerator(), false, true, execa);533test('Can use generators with inputFile option', testInputFile, uppercaseGenerator(), true, false, execa);534test('Can use generators with a file as input, sync', testInputFile, uppercaseGenerator(), false, false, execaSync);535test('Can use generators with a file as input, reversed, sync', testInputFile, uppercaseGenerator(), false, true, execaSync);536test('Can use generators with inputFile option, sync', testInputFile, uppercaseGenerator(), true, false, execaSync);537test('Can use duplexes with a file as input', testInputFile, uppercaseBufferDuplex(), false, false, execa);538test('Can use duplexes with a file as input, reversed', testInputFile, uppercaseBufferDuplex(), false, true, execa);539test('Can use duplexes with inputFile option', testInputFile, uppercaseBufferDuplex(), true, false, execa);540test('Can use webTransforms with a file as input', testInputFile, uppercaseBufferWebTransform(), false, false, execa);541test('Can use webTransforms with a file as input, reversed', testInputFile, uppercaseBufferWebTransform(), false, true, execa);542test('Can use webTransforms with inputFile option', testInputFile, uppercaseBufferWebTransform(), true, false, execa);543492const testOutputFile = async (t, reversed, type) => {544const testOutputFile = async (t, reversed, type, execaMethod) => {545 const filePath = tempfile();546 const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];547 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;496 const {stdout} = await execa('noop-fd.js', ['1'], {stdout: reversedStdoutOption});548 const {stdout} = await execaMethod('noop-fd.js', ['1'], {stdout: reversedStdoutOption});549 t.is(stdout, foobarUppercase);550 t.is(await readFile(filePath, 'utf8'), foobarUppercase);551 await rm(filePath);552};553502test('Can use generators with a file as output', testOutputFile, false, 'generator');503test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator');504test('Can use duplexes with a file as output', testOutputFile, false, 'duplex');505test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex');506test('Can use webTransforms with a file as output', testOutputFile, false, 'webTransform');507test('Can use webTransforms with a file as output, reversed', testOutputFile, true, 'webTransform');554test('Can use generators with a file as output', testOutputFile, false, 'generator', execa);555test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator', execa);556test('Can use generators with a file as output, sync', testOutputFile, false, 'generator', execaSync);557test('Can use generators with a file as output, reversed, sync', testOutputFile, true, 'generator', execaSync);558test('Can use duplexes with a file as output', testOutputFile, false, 'duplex', execa);559test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex', execa);560test('Can use webTransforms with a file as output', testOutputFile, false, 'webTransform', execa);561test('Can use webTransforms with a file as output, reversed', testOutputFile, true, 'webTransform', execa);562563const testWritableDestination = async (t, type) => {564 const passThrough = new PassThrough();565 const [{stdout}, streamOutput] = await Promise.all([
28 unmodified lines
594test('Can use generators with "inherit"', testInherit, 'generator');595test('Can use duplexes with "inherit"', testInherit, 'duplex');596test('Can use webTransforms with "inherit"', testInherit, 'webTransform');597544const testAppendInput = async (t, reversed, type) => {598const testAppendInput = async (t, reversed, type, execaMethod) => {599 const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];600 const reversedStdin = reversed ? stdin.reverse() : stdin;547 const {stdout} = await execa('stdin-fd.js', ['0'], {stdin: reversedStdin});601 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: reversedStdin});602 const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;603 t.is(stdout, `${foobarUppercase}${reversedSuffix}`);604};605552test('Can use multiple generators as input', testAppendInput, false, 'generator');553test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator');554test('Can use multiple duplexes as input', testAppendInput, false, 'duplex');555test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex');556test('Can use multiple webTransforms as input', testAppendInput, false, 'webTransform');557test('Can use multiple webTransforms as input, reversed', testAppendInput, true, 'webTransform');606test('Can use multiple generators as input', testAppendInput, false, 'generator', execa);607test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator', execa);608test('Can use multiple generators as input, sync', testAppendInput, false, 'generator', execaSync);609test('Can use multiple generators as input, reversed, sync', testAppendInput, true, 'generator', execaSync);610test('Can use multiple duplexes as input', testAppendInput, false, 'duplex', execa);611test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex', execa);612test('Can use multiple webTransforms as input', testAppendInput, false, 'webTransform', execa);613test('Can use multiple webTransforms as input, reversed', testAppendInput, true, 'webTransform', execa);614559const testAppendOutput = async (t, reversed, type) => {615const testAppendOutput = async (t, reversed, type, execaMethod) => {616 const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];617 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;562 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: reversedStdoutOption});618 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: reversedStdoutOption});619 const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;620 t.is(stdout, `${foobarUppercase}${reversedSuffix}`);621};622567test('Can use multiple generators as output', testAppendOutput, false, 'generator');568test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator');569test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex');570test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex');571test('Can use multiple webTransforms as output', testAppendOutput, false, 'webTransform');572test('Can use multiple webTransforms as output, reversed', testAppendOutput, true, 'webTransform');623test('Can use multiple generators as output', testAppendOutput, false, 'generator', execa);624test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator', execa);625test('Can use multiple generators as output, sync', testAppendOutput, false, 'generator', execaSync);626test('Can use multiple generators as output, reversed, sync', testAppendOutput, true, 'generator', execaSync);627test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex', execa);628test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex', execa);629test('Can use multiple webTransforms as output', testAppendOutput, false, 'webTransform', execa);630test('Can use multiple webTransforms as output, reversed', testAppendOutput, true, 'webTransform', execa);631632// eslint-disable-next-line max-params574const testTwoGenerators = async (t, producesTwo, firstGenerator, secondGenerator = firstGenerator) => {575 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});633const testTwoGenerators = async (t, producesTwo, execaMethod, firstGenerator, secondGenerator = firstGenerator) => {634 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});635 const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;636 t.is(stdout, `${foobarString}${expectedSuffix}`);637};638639test('Can use multiple identical generators', testTwoGenerators, true, execa, appendGenerator().transform);640test('Can use multiple identical generators, options object', testTwoGenerators, true, execa, appendGenerator());641test('Can use multiple identical generators, async', testTwoGenerators, true, execa, appendAsyncGenerator().transform);642test('Can use multiple identical generators, options object, async', testTwoGenerators, true, execa, appendAsyncGenerator());580test('Can use multiple identical generators', testTwoGenerators, true, appendGenerator().transform);581test('Can use multiple identical generators, options object', testTwoGenerators, true, appendGenerator());582test('Ignore duplicate identical duplexes', testTwoGenerators, false, appendDuplex());583test('Ignore duplicate identical webTransforms', testTwoGenerators, false, appendWebTransform());584test('Can use multiple generators with duplexes', testTwoGenerators, true, appendGenerator(false, false, true), appendDuplex());585test('Can use multiple generators with webTransforms', testTwoGenerators, true, appendGenerator(false, false, true), appendWebTransform());586test('Can use multiple duplexes with webTransforms', testTwoGenerators, true, appendDuplex(), appendWebTransform());643test('Can use multiple identical generators, sync', testTwoGenerators, true, execaSync, appendGenerator().transform);644test('Can use multiple identical generators, options object, sync', testTwoGenerators, true, execaSync, appendGenerator());645test('Ignore duplicate identical duplexes', testTwoGenerators, false, execa, appendDuplex());646test('Ignore duplicate identical webTransforms', testTwoGenerators, false, execa, appendWebTransform());647test('Can use multiple generators with duplexes', testTwoGenerators, true, execa, appendGenerator(false, false, true), appendDuplex());648test('Can use multiple generators with webTransforms', testTwoGenerators, true, execa, appendGenerator(false, false, true), appendWebTransform());649test('Can use multiple duplexes with webTransforms', testTwoGenerators, true, execa, appendDuplex(), appendWebTransform());650588const testGeneratorSyntax = async (t, type, usePlainObject) => {651const testGeneratorSyntax = async (t, type, usePlainObject, execaMethod) => {652 const transform = generatorsMap[type].uppercase();590 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: usePlainObject ? transform : transform.transform});653 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: usePlainObject ? transform : transform.transform});654 t.is(stdout, foobarUppercase);655};656594test('Can pass generators with an options plain object', testGeneratorSyntax, 'generator', false);595test('Can pass generators without an options plain object', testGeneratorSyntax, 'generator', true);596test('Can pass webTransforms with an options plain object', testGeneratorSyntax, 'webTransform', true);597test('Can pass webTransforms without an options plain object', testGeneratorSyntax, 'webTransform', false);657test('Can pass generators with an options plain object', testGeneratorSyntax, 'generator', false, execa);658test('Can pass generators without an options plain object', testGeneratorSyntax, 'generator', true, execa);659test('Can pass generators with an options plain object, sync', testGeneratorSyntax, 'generator', false, execaSync);660test('Can pass generators without an options plain object, sync', testGeneratorSyntax, 'generator', true, execaSync);661test('Can pass webTransforms with an options plain object', testGeneratorSyntax, 'webTransform', true, execa);662test('Can pass webTransforms without an options plain object', testGeneratorSyntax, 'webTransform', false, execa);
added:test/stdio/input-sync.js+18 added
1import test from 'ava';2import {execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {getStdio} from '../helpers/stdio.js';56setFixtureDir();78const getFd3InputMessage = type => `not \`stdio[3]\`, can be ${type}`;910const testFd3InputSync = (t, stdioOption, expectedMessage) => {11 const {message} = t.throws(() => {12 execaSync('empty.js', getStdio(3, stdioOption));13 });14 t.true(message.includes(expectedMessage));15};1617test('Cannot use Uint8Array with stdio[*], sync', testFd3InputSync, new Uint8Array(), getFd3InputMessage('a Uint8Array'));18test('Cannot use iterable with stdio[*], sync', testFd3InputSync, [[]], getFd3InputMessage('an iterable'));
modified:test/stdio/iterable.js+44 added-30 removed
2 unmodified lines
3import test from 'ava';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {getStdio} from '../helpers/stdio.js';7import {foobarObject, foobarObjectString, foobarArray} from '../helpers/input.js';8import {serializeGenerator, infiniteGenerator, throwingGenerator} from '../helpers/generator.js';7import {foobarString, foobarObject, foobarObjectString, foobarArray} from '../helpers/input.js';8import {noopGenerator, serializeGenerator, infiniteGenerator, throwingGenerator} from '../helpers/generator.js';910const stringGenerator = function * () {11 yield * foobarArray;12};
50 unmodified lines
63const foobarAsyncObjectGenerator = async function * () {64 yield foobarObject;65};6667const testObjectIterable = async (t, stdioOption, fdNumber) => {68 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stdioOption, serializeGenerator(true)]));67const testObjectIterable = async (t, stdioOption, fdNumber, execaMethod) => {68 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stdioOption, serializeGenerator(true)]));69 t.is(stdout, foobarObjectString);70};7172test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0);73test('stdio[*] option can be an array of objects', testObjectIterable, [foobarObject], 3);74test('stdin option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 0);75test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3);76test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0);77test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3);72test('stdin option can be an array of objects', testObjectIterable, [foobarObject], 0, execa);73test('stdio[*] option can be an array of objects', testObjectIterable, [foobarObject], 3, execa);74test('stdin option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 0, execa);75test('stdio[*] option can be an iterable of objects', testObjectIterable, foobarObjectGenerator(), 3, execa);76test('stdin option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 0, execa);77test('stdio[*] option can be an async iterable of objects', testObjectIterable, foobarAsyncObjectGenerator(), 3, execa);78test('stdin option can be an array of objects - sync', testObjectIterable, [foobarObject], 0, execaSync);79test('stdin option can be an iterable of objects - sync', testObjectIterable, foobarObjectGenerator(), 0, execaSync);8081const testIterableNoGeneratorsSync = (t, stdioOption, fdNumber) => {82 t.throws(() => {83 execaSync('empty.js', getStdio(fdNumber, stdioOption));84 }, {message: /must be used to serialize/});85};8687test('stdin option cannot be an array of objects without generators - sync', testIterableNoGeneratorsSync, [[foobarObject]], 0);88test('stdin option cannot be an iterable of objects without generators - sync', testIterableNoGeneratorsSync, foobarObjectGenerator(), 0);8990const testIterableNoSerializeSync = (t, stdioOption, fdNumber) => {91 t.throws(() => {92 execaSync('empty.js', getStdio(fdNumber, [stdioOption, noopGenerator()]));93 }, {message: /The `stdin` option's transform must use "objectMode: true" to receive as input: object/});94};9596test('stdin option cannot be an array of objects without serializing - sync', testIterableNoSerializeSync, [foobarObject], 0);97test('stdin option cannot be an iterable of objects without serializing - sync', testIterableNoSerializeSync, foobarObjectGenerator(), 0);9899const testIterableSync = (t, stdioOption, fdNumber) => {100 t.throws(() => {101 execaSync('empty.js', getStdio(fdNumber, stdioOption));102 }, {message: /an iterable with synchronous methods/});
6 unmodified lines
109test('stdio[*] option cannot be an iterable of Uint8Arrays - sync', testIterableSync, binaryGenerator(), 3);110test('stdio[*] option cannot be an iterable of objects - sync', testIterableSync, foobarObjectGenerator(), 3);111test('stdio[*] option cannot be multiple iterables - sync', testIterableSync, [stringGenerator(), stringGenerator()], 3);11293const testIterableObjectSync = (t, stdioOption, fdNumber) => {94 t.throws(() => {95 execaSync('empty.js', getStdio(fdNumber, stdioOption));96 }, {message: /only strings or Uint8Arrays/});97};9899test('stdin option cannot be an array of objects - sync', testIterableObjectSync, [[foobarObject]], 0);100test('stdin option cannot be an iterable of objects - sync', testIterableObjectSync, foobarObjectGenerator(), 0);101113const testAsyncIterableSync = (t, stdioOption, fdNumber) => {114 t.throws(() => {115 execaSync('empty.js', getStdio(fdNumber, stdioOption));116 }, {message: /an async iterable with synchronous method/});
3 unmodified lines
120test('stdio[*] option cannot be an async iterable - sync', testAsyncIterableSync, asyncGenerator(), 3);121test('stdin option cannot be an async iterable of objects - sync', testAsyncIterableSync, foobarAsyncObjectGenerator(), 0);122test('stdio[*] option cannot be an async iterable of objects - sync', testAsyncIterableSync, foobarAsyncObjectGenerator(), 3);123113const testIterableError = async (t, fdNumber, execaMethod) => {114 const {originalMessage} = await t.throwsAsync(execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator().transform())));115 t.is(originalMessage, 'Generator error');124const testIterableError = async (t, fdNumber) => {125 const cause = new Error(foobarString);126 const error = await t.throwsAsync(execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator(cause)().transform())));127 t.is(error.cause, cause);128};129118test('stdin option handles errors in iterables', testIterableError, 0, execa);119test('stdio[*] option handles errors in iterables', testIterableError, 3, execa);130test('stdin option handles errors in iterables', testIterableError, 0);131test('stdio[*] option handles errors in iterables', testIterableError, 3);132121const testIterableErrorSync = (t, fdNumber, execaMethod) => {122 t.throws(() => {123 execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator().transform()));124 }, {message: 'Generator error'});133const testIterableErrorSync = (t, fdNumber) => {134 const cause = new Error(foobarString);135 const error = t.throws(() => {136 execaSync('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, throwingGenerator(cause)().transform()));137 });138 t.is(error, cause);139};140127test('stdin option handles errors in iterables - sync', testIterableErrorSync, 0, execaSync);128test('stdio[*] option handles errors in iterables - sync', testIterableErrorSync, 3, execaSync);141test('stdin option handles errors in iterables - sync', testIterableErrorSync, 0);142test('stdio[*] option handles errors in iterables - sync', testIterableErrorSync, 3);143144const testNoIterableOutput = (t, stdioOption, fdNumber, execaMethod) => {145 t.throws(() => {146 execaMethod('empty.js', getStdio(fdNumber, stdioOption));
46 unmodified lines
added:test/stdio/output-sync.js+33 added
1import test from 'ava';2import {execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {throwingGenerator} from '../helpers/generator.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();89test('Handles errors with stdout generator, sync', t => {10 const cause = new Error(foobarString);11 const error = t.throws(() => {12 execaSync('noop.js', {stdout: throwingGenerator(cause)()});13 });14 t.is(error.cause, cause);15});1617test('Handles errors with stdout generator, spawn failure, sync', t => {18 const cause = new Error(foobarString);19 const error = t.throws(() => {20 execaSync('noop.js', {cwd: 'does_not_exist', stdout: throwingGenerator(cause)()});21 });22 t.true(error.failed);23 t.is(error.cause.code, 'ENOENT');24});2526test('Handles errors with stdout generator, subprocess failure, sync', t => {27 const cause = new Error(foobarString);28 const error = t.throws(() => {29 execaSync('noop-fail.js', ['1'], {stdout: throwingGenerator(cause)()});30 });31 t.true(error.failed);32 t.is(error.cause, cause);33});
modified:test/stdio/split.js+183 added-98 removed
1import test from 'ava';2import {execa} from '../../index.js';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {getStdio} from '../helpers/stdio.js';5import {6 getOutputsGenerator,
50 unmodified lines
57const manyLines = [manyFull];58const mixedNewlines = '.\n.\r\n.\n.\r\n.\n';5960// eslint-disable-next-line max-params61const testLines = async (t, fdNumber, input, expectedLines, expectedOutput, objectMode, preserveNewlines) => {61const testLines = async (t, fdNumber, input, expectedLines, expectedOutput, objectMode, preserveNewlines, execaMethod) => {62 const lines = [];63 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], {63 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`], {64 ...getStdio(fdNumber, [65 getOutputsGenerator(input)(false, true),66 resultGenerator(lines)(objectMode, false, preserveNewlines),67 ]),
2 unmodified lines
70 t.deepEqual(lines, expectedLines);71 t.deepEqual(stdio[fdNumber], expectedOutput);72};7374test('Split stdout - n newlines, 1 chunk', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true);75test('Split stderr - n newlines, 1 chunk', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true);76test('Split stdio[*] - n newlines, 1 chunk', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true);77test('Split stdout - preserveNewlines, n chunks', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true);78test('Split stdout - 0 newlines, 1 chunk', testLines, 1, singleChunks, singleChunks, singleFull, false, true);79test('Split stdout - empty, 1 chunk', testLines, 1, emptyChunks, noLines, emptyFull, false, true);80test('Split stdout - Windows newlines', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true);81test('Split stdout - chunk ends with newline', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true);82test('Split stdout - single newline', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true);83test('Split stdout - only newlines', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true);84test('Split stdout - only Windows newlines', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true);85test('Split stdout - line split over multiple chunks', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true);86test('Split stdout - 0 newlines, big line', testLines, 1, bigChunks, bigChunks, bigFull, false, true);87test('Split stdout - 0 newlines, many chunks', testLines, 1, manyChunks, manyLines, manyFull, false, true);88test('Split stdout - n newlines, 1 chunk, objectMode', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true);89test('Split stderr - n newlines, 1 chunk, objectMode', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true);90test('Split stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true);91test('Split stdout - preserveNewlines, n chunks, objectMode', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true);92test('Split stdout - empty, 1 chunk, objectMode', testLines, 1, emptyChunks, noLines, noLines, true, true);93test('Split stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, singleChunks, singleChunks, singleChunks, true, true);94test('Split stdout - Windows newlines, objectMode', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true);95test('Split stdout - chunk ends with newline, objectMode', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true);96test('Split stdout - single newline, objectMode', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true);97test('Split stdout - only newlines, objectMode', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true);98test('Split stdout - only Windows newlines, objectMode', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true);99test('Split stdout - line split over multiple chunks, objectMode', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true);100test('Split stdout - 0 newlines, big line, objectMode', testLines, 1, bigChunks, bigChunks, bigChunks, true, true);101test('Split stdout - 0 newlines, many chunks, objectMode', testLines, 1, manyChunks, manyLines, manyLines, true, true);102test('Split stdout - n newlines, 1 chunk, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false);103test('Split stderr - n newlines, 1 chunk, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false);104test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false);105test('Split stdout - preserveNewlines, n chunks, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false);106test('Split stdout - empty, 1 chunk, preserveNewlines', testLines, 1, emptyChunks, noLines, emptyFull, false, false);107test('Split stdout - 0 newlines, 1 chunk, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false);108test('Split stdout - Windows newlines, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false);109test('Split stdout - chunk ends with newline, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false);110test('Split stdout - single newline, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false);111test('Split stdout - only newlines, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false);112test('Split stdout - only Windows newlines, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false);113test('Split stdout - line split over multiple chunks, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false);114test('Split stdout - 0 newlines, big line, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false);115test('Split stdout - 0 newlines, many chunks, preserveNewlines', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false);116test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);117test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);118test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);119test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false);120test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines', testLines, 1, emptyChunks, noLines, noLines, true, false);121test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleChunks, true, false);122test('Split stdout - Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false);123test('Split stdout - chunk ends with newline, objectMode, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false);124test('Split stdout - single newline, objectMode, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false);125test('Split stdout - only newlines, objectMode, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false);126test('Split stdout - only Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false);127test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false);128test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigChunks, true, false);129test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines', testLines, 1, manyChunks, manyLines, manyLines, true, false);74test('Split stdout - n newlines, 1 chunk', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true, execa);75test('Split stderr - n newlines, 1 chunk', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true, execa);76test('Split stdio[*] - n newlines, 1 chunk', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true, execa);77test('Split stdout - preserveNewlines, n chunks', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true, execa);78test('Split stdout - 0 newlines, 1 chunk', testLines, 1, singleChunks, singleChunks, singleFull, false, true, execa);79test('Split stdout - empty, 1 chunk', testLines, 1, emptyChunks, noLines, emptyFull, false, true, execa);80test('Split stdout - Windows newlines', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true, execa);81test('Split stdout - chunk ends with newline', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true, execa);82test('Split stdout - single newline', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true, execa);83test('Split stdout - only newlines', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true, execa);84test('Split stdout - only Windows newlines', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true, execa);85test('Split stdout - line split over multiple chunks', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true, execa);86test('Split stdout - 0 newlines, big line', testLines, 1, bigChunks, bigChunks, bigFull, false, true, execa);87test('Split stdout - 0 newlines, many chunks', testLines, 1, manyChunks, manyLines, manyFull, false, true, execa);88test('Split stdout - n newlines, 1 chunk, objectMode', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true, execa);89test('Split stderr - n newlines, 1 chunk, objectMode', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true, execa);90test('Split stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true, execa);91test('Split stdout - preserveNewlines, n chunks, objectMode', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true, execa);92test('Split stdout - empty, 1 chunk, objectMode', testLines, 1, emptyChunks, noLines, noLines, true, true, execa);93test('Split stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, singleChunks, singleChunks, singleChunks, true, true, execa);94test('Split stdout - Windows newlines, objectMode', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true, execa);95test('Split stdout - chunk ends with newline, objectMode', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true, execa);96test('Split stdout - single newline, objectMode', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true, execa);97test('Split stdout - only newlines, objectMode', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true, execa);98test('Split stdout - only Windows newlines, objectMode', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true, execa);99test('Split stdout - line split over multiple chunks, objectMode', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true, execa);100test('Split stdout - 0 newlines, big line, objectMode', testLines, 1, bigChunks, bigChunks, bigChunks, true, true, execa);101test('Split stdout - 0 newlines, many chunks, objectMode', testLines, 1, manyChunks, manyLines, manyLines, true, true, execa);102test('Split stdout - n newlines, 1 chunk, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);103test('Split stderr - n newlines, 1 chunk, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);104test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);105test('Split stdout - preserveNewlines, n chunks, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false, execa);106test('Split stdout - empty, 1 chunk, preserveNewlines', testLines, 1, emptyChunks, noLines, emptyFull, false, false, execa);107test('Split stdout - 0 newlines, 1 chunk, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false, execa);108test('Split stdout - Windows newlines, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false, execa);109test('Split stdout - chunk ends with newline, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);110test('Split stdout - single newline, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false, execa);111test('Split stdout - only newlines, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false, execa);112test('Split stdout - only Windows newlines, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false, execa);113test('Split stdout - line split over multiple chunks, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);114test('Split stdout - 0 newlines, big line, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false, execa);115test('Split stdout - 0 newlines, many chunks, preserveNewlines', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false, execa);116test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);117test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);118test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);119test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false, execa);120test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines', testLines, 1, emptyChunks, noLines, noLines, true, false, execa);121test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleChunks, true, false, execa);122test('Split stdout - Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);123test('Split stdout - chunk ends with newline, objectMode, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);124test('Split stdout - single newline, objectMode, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false, execa);125test('Split stdout - only newlines, objectMode, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execa);126test('Split stdout - only Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execa);127test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);128test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigChunks, true, false, execa);129test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines', testLines, 1, manyChunks, manyLines, manyLines, true, false, execa);130test('Split stdout - n newlines, 1 chunk, sync', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true, execaSync);131test('Split stderr - n newlines, 1 chunk, sync', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true, execaSync);132test('Split stdio[*] - n newlines, 1 chunk, sync', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true, execaSync);133test('Split stdout - preserveNewlines, n chunks, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true, execaSync);134test('Split stdout - 0 newlines, 1 chunk, sync', testLines, 1, singleChunks, singleChunks, singleFull, false, true, execaSync);135test('Split stdout - empty, 1 chunk, sync', testLines, 1, emptyChunks, noLines, emptyFull, false, true, execaSync);136test('Split stdout - Windows newlines, sync', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true, execaSync);137test('Split stdout - chunk ends with newline, sync', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true, execaSync);138test('Split stdout - single newline, sync', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true, execaSync);139test('Split stdout - only newlines, sync', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true, execaSync);140test('Split stdout - only Windows newlines, sync', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true, execaSync);141test('Split stdout - line split over multiple chunks, sync', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true, execaSync);142test('Split stdout - 0 newlines, big line, sync', testLines, 1, bigChunks, bigChunks, bigFull, false, true, execaSync);143test('Split stdout - 0 newlines, many chunks, sync', testLines, 1, manyChunks, manyLines, manyFull, false, true, execaSync);144test('Split stdout - n newlines, 1 chunk, objectMode, sync', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true, execaSync);145test('Split stderr - n newlines, 1 chunk, objectMode, sync', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true, execaSync);146test('Split stdio[*] - n newlines, 1 chunk, objectMode, sync', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true, execaSync);147test('Split stdout - preserveNewlines, n chunks, objectMode, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true, execaSync);148test('Split stdout - empty, 1 chunk, objectMode, sync', testLines, 1, emptyChunks, noLines, noLines, true, true, execaSync);149test('Split stdout - 0 newlines, 1 chunk, objectMode, sync', testLines, 1, singleChunks, singleChunks, singleChunks, true, true, execaSync);150test('Split stdout - Windows newlines, objectMode, sync', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true, execaSync);151test('Split stdout - chunk ends with newline, objectMode, sync', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true, execaSync);152test('Split stdout - single newline, objectMode, sync', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true, execaSync);153test('Split stdout - only newlines, objectMode, sync', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true, execaSync);154test('Split stdout - only Windows newlines, objectMode, sync', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true, execaSync);155test('Split stdout - line split over multiple chunks, objectMode, sync', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true, execaSync);156test('Split stdout - 0 newlines, big line, objectMode, sync', testLines, 1, bigChunks, bigChunks, bigChunks, true, true, execaSync);157test('Split stdout - 0 newlines, many chunks, objectMode, sync', testLines, 1, manyChunks, manyLines, manyLines, true, true, execaSync);158test('Split stdout - n newlines, 1 chunk, preserveNewlines, sync', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);159test('Split stderr - n newlines, 1 chunk, preserveNewlines, sync', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);160test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines, sync', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);161test('Split stdout - preserveNewlines, n chunks, preserveNewlines, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false, execaSync);162test('Split stdout - empty, 1 chunk, preserveNewlines, sync', testLines, 1, emptyChunks, noLines, emptyFull, false, false, execaSync);163test('Split stdout - 0 newlines, 1 chunk, preserveNewlines, sync', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false, execaSync);164test('Split stdout - Windows newlines, preserveNewlines, sync', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false, execaSync);165test('Split stdout - chunk ends with newline, preserveNewlines, sync', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);166test('Split stdout - single newline, preserveNewlines, sync', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false, execaSync);167test('Split stdout - only newlines, preserveNewlines, sync', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false, execaSync);168test('Split stdout - only Windows newlines, preserveNewlines, sync', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false, execaSync);169test('Split stdout - line split over multiple chunks, preserveNewlines, sync', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);170test('Split stdout - 0 newlines, big line, preserveNewlines, sync', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false, execaSync);171test('Split stdout - 0 newlines, many chunks, preserveNewlines, sync', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false, execaSync);172test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);173test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);174test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);175test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false, execaSync);176test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, emptyChunks, noLines, noLines, true, false, execaSync);177test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, singleChunks, singleChunks, singleChunks, true, false, execaSync);178test('Split stdout - Windows newlines, objectMode, preserveNewlines, sync', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);179test('Split stdout - chunk ends with newline, objectMode, preserveNewlines, sync', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);180test('Split stdout - single newline, objectMode, preserveNewlines, sync', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false, execaSync);181test('Split stdout - only newlines, objectMode, preserveNewlines, sync', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execaSync);182test('Split stdout - only Windows newlines, objectMode, preserveNewlines, sync', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execaSync);183test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines, sync', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);184test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines, sync', testLines, 1, bigChunks, bigChunks, bigChunks, true, false, execaSync);185test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines, sync', testLines, 1, manyChunks, manyLines, manyLines, true, false, execaSync);186187// eslint-disable-next-line max-params132const testBinaryOption = async (t, binary, input, expectedLines, expectedOutput, objectMode, preserveNewlines, encoding) => {188const testBinaryOption = async (t, binary, input, expectedLines, expectedOutput, objectMode, preserveNewlines, encoding, execaMethod) => {189 const lines = [];134 const {stdout} = await execa('noop.js', {190 const {stdout} = await execaMethod('noop.js', {191 stdout: [192 getOutputsGenerator(input)(false, true),193 resultGenerator(lines)(objectMode, binary, preserveNewlines),194 ],
3 unmodified lines
198 t.deepEqual(lines, expectedLines);199 t.deepEqual(stdout, expectedOutput);200};201146test('Does not split lines when "binary" is true', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true);147test('Splits lines when "binary" is false', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true);148test('Splits lines when "binary" is undefined', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true);149test('Does not split lines when "binary" is undefined, encoding "buffer"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer');150test('Does not split lines when "binary" is false, encoding "buffer"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer');151test('Does not split lines when "binary" is undefined, encoding "hex"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex');152test('Does not split lines when "binary" is false, encoding "hex"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex');153test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true);154test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true);155test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true);156test('Does not split lines when "binary" is true, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false);157test('Splits lines when "binary" is false, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false);158test('Splits lines when "binary" is undefined, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false);159test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer');160test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer');161test('Does not split lines when "binary" is true, objectMode, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false);162test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex');163test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex');164test('Splits lines when "binary" is false, objectMode, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);165test('Splits lines when "binary" is undefined, objectMode, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false);202test('Does not split lines when "binary" is true', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true, 'utf8', execa);203test('Splits lines when "binary" is false', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execa);204test('Splits lines when "binary" is undefined', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execa);205test('Does not split lines when "binary" is undefined, encoding "buffer"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);206test('Does not split lines when "binary" is false, encoding "buffer"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);207test('Does not split lines when "binary" is undefined, encoding "hex"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);208test('Does not split lines when "binary" is false, encoding "hex"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);209test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true, 'utf8', execa);210test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execa);211test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execa);212test('Does not split lines when "binary" is true, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false, 'utf8', execa);213test('Splits lines when "binary" is false, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execa);214test('Splits lines when "binary" is undefined, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execa);215test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);216test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);217test('Does not split lines when "binary" is true, objectMode, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false, 'utf8', execa);218test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);219test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);220test('Splits lines when "binary" is false, objectMode, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execa);221test('Splits lines when "binary" is undefined, objectMode, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execa);222test('Does not split lines when "binary" is true, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true, 'utf8', execaSync);223test('Splits lines when "binary" is false, sync', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execaSync);224test('Splits lines when "binary" is undefined, sync', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execaSync);225test('Does not split lines when "binary" is undefined, encoding "buffer", sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);226test('Does not split lines when "binary" is false, encoding "buffer", sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);227test('Does not split lines when "binary" is undefined, encoding "hex", sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);228test('Does not split lines when "binary" is false, encoding "hex", sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);229test('Does not split lines when "binary" is true, objectMode, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true, 'utf8', execaSync);230test('Splits lines when "binary" is false, objectMode, sync', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execaSync);231test('Splits lines when "binary" is undefined, objectMode, sync', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execaSync);232test('Does not split lines when "binary" is true, preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false, 'utf8', execaSync);233test('Splits lines when "binary" is false, preserveNewlines, sync', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execaSync);234test('Splits lines when "binary" is undefined, preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execaSync);235test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);236test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines, sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);237test('Does not split lines when "binary" is true, objectMode, preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false, 'utf8', execaSync);238test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);239test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines, sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);240test('Splits lines when "binary" is false, objectMode, preserveNewlines, sync', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execaSync);241test('Splits lines when "binary" is undefined, objectMode, preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execaSync);242243const resultUint8ArrayGenerator = function * (lines, chunk) {244 lines.push(chunk);245 yield new TextEncoder().encode(chunk);
17 unmodified lines
263test('Line splitting when converting from string to Uint8Array, objectMode', testStringToUint8Array, [foobarUint8Array], true, true);264test('Line splitting when converting from string to Uint8Array, preserveNewlines', testStringToUint8Array, [foobarString], false, false);265test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines', testStringToUint8Array, [foobarUint8Array], true, false);266191const testStripNewline = async (t, input, expectedOutput) => {192 const {stdout} = await execa('noop.js', {267const testStripNewline = async (t, input, expectedOutput, execaMethod) => {268 const {stdout} = await execaMethod('noop.js', {269 stdout: getOutputsGenerator([input])(),270 stripFinalNewline: false,271 });272 t.is(stdout, expectedOutput);273};274199test('Strips newline when user do not mistakenly yield one at the end', testStripNewline, singleFull, singleFullEnd);200test('Strips newline when user mistakenly yielded one at the end', testStripNewline, singleFullEnd, singleFullEnd);201test('Strips newline when user mistakenly yielded one at the end, Windows newline', testStripNewline, singleFullEndWindows, singleFullEndWindows);275test('Strips newline when user do not mistakenly yield one at the end', testStripNewline, singleFull, singleFullEnd, execa);276test('Strips newline when user mistakenly yielded one at the end', testStripNewline, singleFullEnd, singleFullEnd, execa);277test('Strips newline when user mistakenly yielded one at the end, Windows newline', testStripNewline, singleFullEndWindows, singleFullEndWindows, execa);278test('Strips newline when user do not mistakenly yield one at the end, sync', testStripNewline, singleFull, singleFullEnd, execaSync);279test('Strips newline when user mistakenly yielded one at the end, sync', testStripNewline, singleFullEnd, singleFullEnd, execaSync);280test('Strips newline when user mistakenly yielded one at the end, Windows newline, sync', testStripNewline, singleFullEndWindows, singleFullEndWindows, execaSync);281203const testMixNewlines = async (t, generator) => {204 const {stdout} = await execa('noop-fd.js', ['1', mixedNewlines], {282const testMixNewlines = async (t, generator, execaMethod) => {283 const {stdout} = await execaMethod('noop-fd.js', ['1', mixedNewlines], {284 stdout: generator(),285 stripFinalNewline: false,286 });287 t.is(stdout, mixedNewlines);288};289211test('Can mix Unix and Windows newlines', testMixNewlines, noopGenerator);212test('Can mix Unix and Windows newlines, async', testMixNewlines, noopAsyncGenerator);290test('Can mix Unix and Windows newlines', testMixNewlines, noopGenerator, execa);291test('Can mix Unix and Windows newlines, sync', testMixNewlines, noopGenerator, execaSync);292test('Can mix Unix and Windows newlines, async', testMixNewlines, noopAsyncGenerator, execa);293294const serializeResultGenerator = function * (lines, chunk) {295 lines.push(chunk);296 yield JSON.stringify(chunk);297};298219const testUnsetObjectMode = async (t, expectedOutput, preserveNewlines) => {299const testUnsetObjectMode = async (t, expectedOutput, preserveNewlines, execaMethod) => {300 const lines = [];221 const {stdout} = await execa('noop.js', {301 const {stdout} = await execaMethod('noop.js', {302 stdout: [303 getOutputsGenerator([foobarObject])(true),304 {transform: serializeResultGenerator.bind(undefined, lines), preserveNewlines, objectMode: false},305 ],
2 unmodified lines
308 t.deepEqual(lines, [foobarObject]);309 t.is(stdout, expectedOutput);310};311232test('Can switch from objectMode to non-objectMode', testUnsetObjectMode, `${foobarObjectString}\n`, false);233test('Can switch from objectMode to non-objectMode, preserveNewlines', testUnsetObjectMode, foobarObjectString, true);312test('Can switch from objectMode to non-objectMode', testUnsetObjectMode, `${foobarObjectString}\n`, false, execa);313test('Can switch from objectMode to non-objectMode, preserveNewlines', testUnsetObjectMode, foobarObjectString, true, execa);314test('Can switch from objectMode to non-objectMode, sync', testUnsetObjectMode, `${foobarObjectString}\n`, false, execaSync);315test('Can switch from objectMode to non-objectMode, preserveNewlines, sync', testUnsetObjectMode, foobarObjectString, true, execaSync);316317// eslint-disable-next-line max-params235const testYieldArray = async (t, input, expectedLines, expectedOutput) => {318const testYieldArray = async (t, input, expectedLines, expectedOutput, execaMethod) => {319 const lines = [];237 const {stdout} = await execa('noop.js', {320 const {stdout} = await execaMethod('noop.js', {321 stdout: [322 getOutputsGenerator(input)(),323 resultGenerator(lines)(),324 ],
2 unmodified lines
327 t.deepEqual(lines, expectedLines);328 t.deepEqual(stdout, expectedOutput);329};330248test('Can use "yield* array" to produce multiple lines', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`);249test('Can use "yield* array" to produce empty lines', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`);331test('Can use "yield* array" to produce multiple lines', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execa);332test('Can use "yield* array" to produce empty lines', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execa);333test('Can use "yield* array" to produce multiple lines, sync', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execaSync);334test('Can use "yield* array" to produce empty lines, sync', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execaSync);
modified:test/stdio/sync.js-11 removed
8 unmodified lines
9setFixtureDir();1011const getArrayMessage = singleValueName => `The \`${singleValueName}\` option cannot be set as an array`;12const getInputMessage = (singleValueName, inputName) => `The \`${singleValueName}\` and the \`${inputName}\` options cannot be both set`;13const getFd3InputMessage = type => `not \`stdio[3]\`, can be ${type}`;1314const inputOptions = {input: ''};15const inputFileOptions = {inputFile: fileURLToPath(import.meta.url)};16
27 unmodified lines
44test('Cannot use [Writable, "pipe"] with stderr, sync', testInvalidStdioArraySync, 2, [noopWritable(), 'pipe'], {}, getArrayMessage('stderr: Stream'));45test('Cannot use ["inherit", "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, ['inherit', 'pipe'], {}, getArrayMessage('stdio[3]: "inherit"'));46test('Cannot use [3, "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, [3, 'pipe'], {}, getArrayMessage('stdio[3]: 3'));47test('Cannot use [Writable, "pipe"] with stdio[*], sync', testInvalidStdioArraySync, 3, [noopWritable(), 'pipe'], {}, getArrayMessage('stdio[3]: Stream'));4950const testFd3InputSync = (t, stdioOption, expectedMessage) => {51 const {message} = t.throws(() => {52 execaSync('empty.js', getStdio(3, stdioOption));53 });54 t.true(message.includes(expectedMessage));55};5657test('Cannot use Uint8Array with stdio[*], sync', testFd3InputSync, new Uint8Array(), getFd3InputMessage('a Uint8Array'));58test('Cannot use iterable with stdio[*], sync', testFd3InputSync, [[]], getFd3InputMessage('an iterable'));
modified:test/stdio/transform.js+88 added-54 removed
1 unmodified line
2import {once} from 'node:events';3import {scheduler} from 'node:timers/promises';4import test from 'ava';5import {getStreamAsArray} from 'get-stream';6import {execa} from '../../index.js';6import {execa, execaSync} from '../../index.js';7import {foobarString} from '../helpers/input.js';8import {9 noopGenerator,10 getOutputAsyncGenerator,
2 unmodified lines
13 outputObjectGenerator,14 convertTransformToFinal,15 prefix,16 suffix,17 GENERATOR_ERROR_REGEXP,17} from '../helpers/generator.js';18import {generatorsMap} from '../helpers/map.js';19import {defaultHighWaterMark} from '../helpers/stream.js';20import {setFixtureDir} from '../helpers/fixtures-dir.js';2122setFixtureDir();2325const testGeneratorFinal = async (t, fixtureName) => {26 const {stdout} = await execa(fixtureName, {stdout: convertTransformToFinal(getOutputGenerator(foobarString)(), true)});24const testGeneratorFinal = async (t, fixtureName, execaMethod) => {25 const {stdout} = await execaMethod(fixtureName, {stdout: convertTransformToFinal(getOutputGenerator(foobarString)(), true)});26 t.is(stdout, foobarString);27};2830test('Generators "final" can be used', testGeneratorFinal, 'noop.js');31test('Generators "final" is used even on empty streams', testGeneratorFinal, 'empty.js');29test('Generators "final" can be used', testGeneratorFinal, 'noop.js', execa);30test('Generators "final" is used even on empty streams', testGeneratorFinal, 'empty.js', execa);31test('Generators "final" can be used, sync', testGeneratorFinal, 'noop.js', execaSync);32test('Generators "final" is used even on empty streams, sync', testGeneratorFinal, 'empty.js', execaSync);3333const testFinalAlone = async (t, final) => {34 const {stdout} = await execa('noop-fd.js', ['1', '.'], {stdout: {final: final(foobarString)().transform, binary: true}});34const testFinalAlone = async (t, final, execaMethod) => {35 const {stdout} = await execaMethod('noop-fd.js', ['1', '.'], {stdout: {final: final(foobarString)().transform, binary: true}});36 t.is(stdout, `.${foobarString}`);37};3838test('Generators "final" can be used without "transform"', testFinalAlone, getOutputGenerator);39test('Generators "final" can be used without "transform", async', testFinalAlone, getOutputAsyncGenerator);39test('Generators "final" can be used without "transform"', testFinalAlone, getOutputGenerator, execa);40test('Generators "final" can be used without "transform", sync', testFinalAlone, getOutputGenerator, execaSync);41test('Generators "final" can be used without "transform", async', testFinalAlone, getOutputAsyncGenerator, execa);4241const testFinalNoOutput = async (t, final) => {42 const {stdout} = await execa('empty.js', {stdout: {final: final(foobarString)().transform}});43const testFinalNoOutput = async (t, final, execaMethod) => {44 const {stdout} = await execaMethod('empty.js', {stdout: {final: final(foobarString)().transform}});45 t.is(stdout, foobarString);46};4746test('Generators "final" can be used without "transform" nor output', testFinalNoOutput, getOutputGenerator);47test('Generators "final" can be used without "transform" nor output, async', testFinalNoOutput, getOutputAsyncGenerator);48test('Generators "final" can be used without "transform" nor output', testFinalNoOutput, getOutputGenerator, execa);49test('Generators "final" can be used without "transform" nor output, sync', testFinalNoOutput, getOutputGenerator, execaSync);50test('Generators "final" can be used without "transform" nor output, async', testFinalNoOutput, getOutputAsyncGenerator, execa);5152const repeatCount = defaultHighWaterMark * 3;5354const writerGenerator = function * () {
6 unmodified lines
61 t.is(chunk.length, 1);62 yield chunk;63};6465// eslint-disable-next-line max-params62const testHighWaterMark = async (t, passThrough, binary, objectMode) => {63 const {stdout} = await execa('noop.js', {66const testHighWaterMark = async (t, passThrough, binary, objectMode, execaMethod) => {67 const {stdout} = await execaMethod('noop.js', {68 stdout: [69 ...(objectMode ? [outputObjectGenerator()] : []),70 writerGenerator,71 ...(passThrough ? [noopGenerator(false, binary)] : []),
3 unmodified lines
75 t.is(stdout.length, repeatCount);76 t.true(stdout.every(chunk => chunk === '\n'));77};7875test('Synchronous yields are not buffered, no passThrough', testHighWaterMark, false, false, false);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);79test('Synchronous yields are not buffered, no passThrough', testHighWaterMark, false, false, false, execa);80test('Synchronous yields are not buffered, line-wise passThrough', testHighWaterMark, true, false, false, execa);81test('Synchronous yields are not buffered, binary passThrough', testHighWaterMark, true, true, false, execa);82test('Synchronous yields are not buffered, objectMode as input but not output', testHighWaterMark, false, false, true, execa);83test('Synchronous yields are not buffered, no passThrough, sync', testHighWaterMark, false, false, false, execaSync);84test('Synchronous yields are not buffered, line-wise passThrough, sync', testHighWaterMark, true, false, false, execaSync);85test('Synchronous yields are not buffered, binary passThrough, sync', testHighWaterMark, true, true, false, execaSync);86test('Synchronous yields are not buffered, objectMode as input but not output, sync', testHighWaterMark, false, false, true, execaSync);8788// eslint-disable-next-line max-params81const testNoYield = async (t, type, objectMode, final, output) => {82 const {stdout} = await execa('noop.js', {stdout: convertTransformToFinal(generatorsMap[type].noYield(objectMode), final)});89const testNoYield = async (t, type, objectMode, final, output, execaMethod) => {90 const {stdout} = await execaMethod('noop.js', {stdout: convertTransformToFinal(generatorsMap[type].noYield(objectMode), final)});91 t.deepEqual(stdout, output);92};9386test('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, []);92test('WebTransform can filter by not calling push', testNoYield, 'webTransform', false, false, '');93test('WebTransform can filter by not calling push, objectMode', testNoYield, 'webTransform', true, false, []);94test('Generator can filter "transform" by not calling yield', testNoYield, 'generator', false, false, '', execa);95test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, 'generator', true, false, [], execa);96test('Generator can filter "final" by not calling yield', testNoYield, 'generator', false, true, '', execa);97test('Generator can filter "final" by not calling yield, objectMode', testNoYield, 'generator', true, true, [], execa);98test('Generator can filter "transform" by not calling yield, sync', testNoYield, 'generator', false, false, '', execaSync);99test('Generator can filter "transform" by not calling yield, objectMode, sync', testNoYield, 'generator', true, false, [], execaSync);100test('Generator can filter "final" by not calling yield, sync', testNoYield, 'generator', false, true, '', execaSync);101test('Generator can filter "final" by not calling yield, objectMode, sync', testNoYield, 'generator', true, true, [], execaSync);102test('Duplex can filter by not calling push', testNoYield, 'duplex', false, false, '', execa);103test('Duplex can filter by not calling push, objectMode', testNoYield, 'duplex', true, false, [], execa);104test('WebTransform can filter by not calling push', testNoYield, 'webTransform', false, false, '', execa);105test('WebTransform can filter by not calling push, objectMode', testNoYield, 'webTransform', true, false, [], execa);106107const testMultipleYields = async (t, type, final, binary) => {108 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});109 const newline = binary ? '' : '\n';
76 unmodified lines
186test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);187test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);188test('WebTransform is awaited on success', testAsyncGenerators, 'webTransform', false);189178const testThrowingGenerator = async (t, type, final) => {179 await t.throwsAsync(180 execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].throwing(), final)}),181 {message: GENERATOR_ERROR_REGEXP},182 );190const assertProcessError = async (t, type, execaMethod, getSubprocess) => {191 const cause = new Error(foobarString);192 const transform = generatorsMap[type].throwing(cause)();193 const error = execaMethod === execa194 ? await t.throwsAsync(getSubprocess(transform))195 : t.throws(() => {196 getSubprocess(transform);197 });198 t.is(error.cause, cause);199};200185test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false);186test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true);187test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false);188test('WebTransform "transform" errors make subprocess fail', testThrowingGenerator, 'webTransform', false);201const testThrowingGenerator = async (t, type, final, execaMethod) => {202 await assertProcessError(t, type, execaMethod, transform => execaMethod('noop.js', {203 stdout: convertTransformToFinal(transform, final),204 }));205};206190const testSingleErrorOutput = async (t, type) => {191 await t.throwsAsync(192 execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]}),193 {message: GENERATOR_ERROR_REGEXP},194 );207test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false, execa);208test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true, execa);209test('Generators "transform" errors make subprocess fail, sync', testThrowingGenerator, 'generator', false, execaSync);210test('Generators "final" errors make subprocess fail, sync', testThrowingGenerator, 'generator', true, execaSync);211test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false, execa);212test('WebTransform "transform" errors make subprocess fail', testThrowingGenerator, 'webTransform', false, execa);213214const testSingleErrorOutput = async (t, type, execaMethod) => {215 await assertProcessError(t, type, execaMethod, transform => execaMethod('noop.js', {216 stdout: [217 generatorsMap[type].noop(false),218 transform,219 generatorsMap[type].noop(false),220 ],221 }));222};223197test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator');198test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex');199test('WebTransform errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'webTransform');224test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator', execa);225test('Generators errors make subprocess fail even when other output generators do not throw, sync', testSingleErrorOutput, 'generator', execaSync);226test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex', execa);227test('WebTransform errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'webTransform', execa);228201const testSingleErrorInput = async (t, type) => {202 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [generatorsMap[type].noop(false), generatorsMap[type].throwing(), generatorsMap[type].noop(false)]});203 subprocess.stdin.write('foobar\n');204 await t.throwsAsync(subprocess, {message: GENERATOR_ERROR_REGEXP});229const testSingleErrorInput = async (t, type, execaMethod) => {230 await assertProcessError(t, type, execaMethod, transform => execaMethod('stdin.js', {231 stdin: [232 ['foobar\n'],233 generatorsMap[type].noop(false),234 transform,235 generatorsMap[type].noop(false),236 ],237 }));238};239207test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator');208test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex');209test('WebTransform errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'webTransform');240test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator', execa);241test('Generators errors make subprocess fail even when other input generators do not throw, sync', testSingleErrorInput, 'generator', execaSync);242test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex', execa);243test('WebTransform errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'webTransform', execa);244245const testGeneratorCancel = async (t, error) => {246 const subprocess = execa('noop.js', {stdout: infiniteGenerator()});247 await once(subprocess.stdout, 'data');
21 unmodified lines
modified:test/stdio/type.js+45 added-39 removed
7 unmodified lines
8import {setFixtureDir} from '../helpers/fixtures-dir.js';910setFixtureDir();1112const testInvalidGenerator = (t, fdNumber, stdioOption) => {12const testInvalidGenerator = (t, fdNumber, stdioOption, execaMethod) => {13 t.throws(() => {14 execa('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));14 execaMethod('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));15 }, {message: 'final' in stdioOption ? /must be a generator/ : /must be a generator, a Duplex stream or a web TransformStream/});16};1718test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true});19test('Cannot use invalid "transform" with stdout', testInvalidGenerator, 1, {transform: true});20test('Cannot use invalid "transform" with stderr', testInvalidGenerator, 2, {transform: true});21test('Cannot use invalid "transform" with stdio[*]', testInvalidGenerator, 3, {transform: true});22test('Cannot use invalid "final" with stdin', testInvalidGenerator, 0, {final: true});23test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true});24test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true});25test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true});18test('Cannot use invalid "transform" with stdin', testInvalidGenerator, 0, {transform: true}, execa);19test('Cannot use invalid "transform" with stdout', testInvalidGenerator, 1, {transform: true}, execa);20test('Cannot use invalid "transform" with stderr', testInvalidGenerator, 2, {transform: true}, execa);21test('Cannot use invalid "transform" with stdio[*]', testInvalidGenerator, 3, {transform: true}, execa);22test('Cannot use invalid "final" with stdin', testInvalidGenerator, 0, {final: true}, execa);23test('Cannot use invalid "final" with stdout', testInvalidGenerator, 1, {final: true}, execa);24test('Cannot use invalid "final" with stderr', testInvalidGenerator, 2, {final: true}, execa);25test('Cannot use invalid "final" with stdio[*]', testInvalidGenerator, 3, {final: true}, execa);26test('Cannot use invalid "transform" with stdin, sync', testInvalidGenerator, 0, {transform: true}, execaSync);27test('Cannot use invalid "transform" with stdout, sync', testInvalidGenerator, 1, {transform: true}, execaSync);28test('Cannot use invalid "transform" with stderr, sync', testInvalidGenerator, 2, {transform: true}, execaSync);29test('Cannot use invalid "transform" with stdio[*], sync', testInvalidGenerator, 3, {transform: true}, execaSync);30test('Cannot use invalid "final" with stdin, sync', testInvalidGenerator, 0, {final: true}, execaSync);31test('Cannot use invalid "final" with stdout, sync', testInvalidGenerator, 1, {final: true}, execaSync);32test('Cannot use invalid "final" with stderr, sync', testInvalidGenerator, 2, {final: true}, execaSync);33test('Cannot use invalid "final" with stdio[*], sync', testInvalidGenerator, 3, {final: true}, execaSync);3435// eslint-disable-next-line max-params27const testInvalidBinary = (t, fdNumber, optionName, type) => {36const testInvalidBinary = (t, fdNumber, optionName, type, execaMethod) => {37 t.throws(() => {29 execa('empty.js', getStdio(fdNumber, {...generatorsMap[type].uppercase(), [optionName]: 'true'}));38 execaMethod('empty.js', getStdio(fdNumber, {...generatorsMap[type].uppercase(), [optionName]: 'true'}));39 }, {message: /a boolean/});40};4133test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary', 'generator');34test('Cannot use invalid "binary" with stdout', testInvalidBinary, 1, 'binary', 'generator');35test('Cannot use invalid "binary" with stderr', testInvalidBinary, 2, 'binary', 'generator');36test('Cannot use invalid "binary" with stdio[*]', testInvalidBinary, 3, 'binary', 'generator');37test('Cannot use invalid "objectMode" with stdin, generators', testInvalidBinary, 0, 'objectMode', 'generator');38test('Cannot use invalid "objectMode" with stdout, generators', testInvalidBinary, 1, 'objectMode', 'generator');39test('Cannot use invalid "objectMode" with stderr, generators', testInvalidBinary, 2, 'objectMode', 'generator');40test('Cannot use invalid "objectMode" with stdio[*], generators', testInvalidBinary, 3, 'objectMode', 'generator');41test('Cannot use invalid "objectMode" with stdin, duplexes', testInvalidBinary, 0, 'objectMode', 'duplex');42test('Cannot use invalid "objectMode" with stdout, duplexes', testInvalidBinary, 1, 'objectMode', 'duplex');43test('Cannot use invalid "objectMode" with stderr, duplexes', testInvalidBinary, 2, 'objectMode', 'duplex');44test('Cannot use invalid "objectMode" with stdio[*], duplexes', testInvalidBinary, 3, 'objectMode', 'duplex');45test('Cannot use invalid "objectMode" with stdin, webTransforms', testInvalidBinary, 0, 'objectMode', 'webTransform');46test('Cannot use invalid "objectMode" with stdout, webTransforms', testInvalidBinary, 1, 'objectMode', 'webTransform');47test('Cannot use invalid "objectMode" with stderr, webTransforms', testInvalidBinary, 2, 'objectMode', 'webTransform');48test('Cannot use invalid "objectMode" with stdio[*], webTransforms', testInvalidBinary, 3, 'objectMode', 'webTransform');42test('Cannot use invalid "binary" with stdin', testInvalidBinary, 0, 'binary', 'generator', execa);43test('Cannot use invalid "binary" with stdout', testInvalidBinary, 1, 'binary', 'generator', execa);44test('Cannot use invalid "binary" with stderr', testInvalidBinary, 2, 'binary', 'generator', execa);45test('Cannot use invalid "binary" with stdio[*]', testInvalidBinary, 3, 'binary', 'generator', execa);46test('Cannot use invalid "objectMode" with stdin, generators', testInvalidBinary, 0, 'objectMode', 'generator', execa);47test('Cannot use invalid "objectMode" with stdout, generators', testInvalidBinary, 1, 'objectMode', 'generator', execa);48test('Cannot use invalid "objectMode" with stderr, generators', testInvalidBinary, 2, 'objectMode', 'generator', execa);49test('Cannot use invalid "objectMode" with stdio[*], generators', testInvalidBinary, 3, 'objectMode', 'generator', execa);50test('Cannot use invalid "binary" with stdin, sync', testInvalidBinary, 0, 'binary', 'generator', execaSync);51test('Cannot use invalid "binary" with stdout, sync', testInvalidBinary, 1, 'binary', 'generator', execaSync);52test('Cannot use invalid "binary" with stderr, sync', testInvalidBinary, 2, 'binary', 'generator', execaSync);53test('Cannot use invalid "binary" with stdio[*], sync', testInvalidBinary, 3, 'binary', 'generator', execaSync);54test('Cannot use invalid "objectMode" with stdin, generators, sync', testInvalidBinary, 0, 'objectMode', 'generator', execaSync);55test('Cannot use invalid "objectMode" with stdout, generators, sync', testInvalidBinary, 1, 'objectMode', 'generator', execaSync);56test('Cannot use invalid "objectMode" with stderr, generators, sync', testInvalidBinary, 2, 'objectMode', 'generator', execaSync);57test('Cannot use invalid "objectMode" with stdio[*], generators, sync', testInvalidBinary, 3, 'objectMode', 'generator', execaSync);58test('Cannot use invalid "objectMode" with stdin, duplexes', testInvalidBinary, 0, 'objectMode', 'duplex', execa);59test('Cannot use invalid "objectMode" with stdout, duplexes', testInvalidBinary, 1, 'objectMode', 'duplex', execa);60test('Cannot use invalid "objectMode" with stderr, duplexes', testInvalidBinary, 2, 'objectMode', 'duplex', execa);61test('Cannot use invalid "objectMode" with stdio[*], duplexes', testInvalidBinary, 3, 'objectMode', 'duplex', execa);62test('Cannot use invalid "objectMode" with stdin, webTransforms', testInvalidBinary, 0, 'objectMode', 'webTransform', execa);63test('Cannot use invalid "objectMode" with stdout, webTransforms', testInvalidBinary, 1, 'objectMode', 'webTransform', execa);64test('Cannot use invalid "objectMode" with stderr, webTransforms', testInvalidBinary, 2, 'objectMode', 'webTransform', execa);65test('Cannot use invalid "objectMode" with stdio[*], webTransforms', testInvalidBinary, 3, 'objectMode', 'webTransform', execa);6667// eslint-disable-next-line max-params68const testUndefinedOption = (t, fdNumber, optionName, type, optionValue) => {69 t.throws(() => {
43 unmodified lines
113test('Cannot use "final" with webTransforms and stdout, with transform', testUndefinedFinal, 1, 'webTransform', true);114test('Cannot use "final" with webTransforms and stderr, with transform', testUndefinedFinal, 2, 'webTransform', true);115test('Cannot use "final" with webTransforms and stdio[*], with transform', testUndefinedFinal, 3, 'webTransform', true);116100const testSyncMethodsGenerator = (t, fdNumber) => {101 t.throws(() => {102 execaSync('empty.js', getStdio(fdNumber, uppercaseGenerator()));103 }, {message: /cannot be a generator/});104};105106test('Cannot use generators with sync methods and stdin', testSyncMethodsGenerator, 0);107test('Cannot use generators with sync methods and stdout', testSyncMethodsGenerator, 1);108test('Cannot use generators with sync methods and stderr', testSyncMethodsGenerator, 2);109test('Cannot use generators with sync methods and stdio[*]', testSyncMethodsGenerator, 3);110117const testSyncMethodsDuplex = (t, fdNumber, type) => {118 t.throws(() => {119 execaSync('empty.js', getStdio(fdNumber, generatorsMap[type].uppercase()));120 }, {message: type === 'duplex' ? /cannot be a Duplex stream/ : /cannot be a web TransformStream/});
10 unmodified lines
modified:test/stdio/typed-array.js+7 added-8 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {getStdio} from '../helpers/stdio.js';5import {foobarUint8Array} from '../helpers/input.js';5import {foobarUint8Array, foobarString} from '../helpers/input.js';67setFixtureDir();89const testUint8Array = async (t, fdNumber) => {10 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, foobarUint8Array));11 t.is(stdout, 'foobar');9const testUint8Array = async (t, fdNumber, execaMethod) => {10 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, foobarUint8Array));11 t.is(stdout, foobarString);12};1314test('stdin option can be a Uint8Array', testUint8Array, 0);15test('stdio[*] option can be a Uint8Array', testUint8Array, 3);16test('stdin option can be a Uint8Array - sync', testUint8Array, 0);17test('stdio[*] option can be a Uint8Array - sync', testUint8Array, 3);14test('stdin option can be a Uint8Array', testUint8Array, 0, execa);15test('stdio[*] option can be a Uint8Array', testUint8Array, 3, execa);16test('stdin option can be a Uint8Array - sync', testUint8Array, 0, execaSync);1718const testNoUint8ArrayOutput = (t, fdNumber, execaMethod) => {19 t.throws(() => {20 execaMethod('empty.js', getStdio(fdNumber, foobarUint8Array));
7 unmodified lines
modified:test/stdio/validate.js+46 added-11 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import {execa} from '../../index.js';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {getStdio} from '../helpers/stdio.js';6import {foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';7import {serializeGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';89setFixtureDir();1011// eslint-disable-next-line max-params12const testGeneratorReturn = async (t, fdNumber, generator, input, objectMode, isInput) => {13 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';14 const subprocess = execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode)));15 const {message} = await t.throwsAsync(subprocess);16 t.true(message.includes(getMessage(input)));17};1811const getMessage = input => {12 if (input === null || input === undefined) {13 return 'not be called at all';14 }
7 unmodified lines
2223const lastInputGenerator = input => objectMode => [foobarUint8Array, getOutputGenerator(input)(objectMode)];24const inputGenerator = input => objectMode => [...lastInputGenerator(input)(objectMode), serializeGenerator(true)];2526// eslint-disable-next-line max-params27const testGeneratorReturn = async (t, fdNumber, generator, input, objectMode, isInput) => {28 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';29 const {message} = await t.throwsAsync(execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode))));30 t.true(message.includes(getMessage(input)));31};3233test('Generators with result.stdin cannot return an object if not in objectMode', testGeneratorReturn, 0, inputGenerator, foobarObject, false, true);34test('Generators with result.stdio[*] as input cannot return an object if not in objectMode', testGeneratorReturn, 3, inputGenerator, foobarObject, false, true);35test('The last generator with result.stdin cannot return an object even in objectMode', testGeneratorReturn, 0, lastInputGenerator, foobarObject, true, true);36test('The last generator with result.stdio[*] as input cannot return an object even in objectMode', testGeneratorReturn, 3, lastInputGenerator, foobarObject, true, true);
15 unmodified lines
52test('Generators with result.stdin cannot return undefined if in objectMode', testGeneratorReturn, 0, inputGenerator, undefined, true, true);53test('Generators with result.stdout cannot return undefined if not in objectMode', testGeneratorReturn, 1, getOutputGenerator, undefined, false, false);54test('Generators with result.stdout cannot return undefined if in objectMode', testGeneratorReturn, 1, getOutputGenerator, undefined, true, false);5556// eslint-disable-next-line max-params57const testGeneratorReturnSync = (t, fdNumber, generator, input, objectMode, isInput) => {58 const fixtureName = isInput ? 'stdin-fd.js' : 'noop-fd.js';59 const {message} = t.throws(() => {60 execaSync(fixtureName, [`${fdNumber}`], getStdio(fdNumber, generator(input)(objectMode)));61 });62 t.true(message.includes(getMessage(input)));63};6465test('Generators with result.stdin cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, foobarObject, false, true);66test('The last generator with result.stdin cannot return an object even in objectMode, sync', testGeneratorReturnSync, 0, lastInputGenerator, foobarObject, true, true);67test('Generators with result.stdout cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, foobarObject, false, false);68test('Generators with result.stderr cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 2, getOutputGenerator, foobarObject, false, false);69test('Generators with result.stdio[*] as output cannot return an object if not in objectMode, sync', testGeneratorReturnSync, 3, getOutputGenerator, foobarObject, false, false);70test('Generators with result.stdin cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, foobarBuffer, false, true);71test('The last generator with result.stdin cannot return a Buffer even in objectMode, sync', testGeneratorReturnSync, 0, lastInputGenerator, foobarBuffer, true, true);72test('Generators with result.stdout cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, foobarBuffer, false, false);73test('Generators with result.stderr cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 2, getOutputGenerator, foobarBuffer, false, false);74test('Generators with result.stdio[*] as output cannot return a Buffer if not in objectMode, sync', testGeneratorReturnSync, 3, getOutputGenerator, foobarBuffer, false, false);75test('Generators with result.stdin cannot return null if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, null, false, true);76test('Generators with result.stdin cannot return null if in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, null, true, true);77test('Generators with result.stdout cannot return null if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, null, false, false);78test('Generators with result.stdout cannot return null if in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, null, true, false);79test('Generators with result.stdin cannot return undefined if not in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, undefined, false, true);80test('Generators with result.stdin cannot return undefined if in objectMode, sync', testGeneratorReturnSync, 0, inputGenerator, undefined, true, true);81test('Generators with result.stdout cannot return undefined if not in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, undefined, false, false);82test('Generators with result.stdout cannot return undefined if in objectMode, sync', testGeneratorReturnSync, 1, getOutputGenerator, undefined, true, false);8384test('Generators "final" return value is validated', async t => {58 const subprocess = execa('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)});59 await t.throwsAsync(subprocess, {message: /not be called at all/});85 await t.throwsAsync(86 execa('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)}),87 {message: /not be called at all/},88 );89});9091test('Generators "final" return value is validated, sync', t => {92 t.throws(() => {93 execaSync('noop.js', {stdout: convertTransformToFinal(getOutputGenerator(null)(true), true)});94 }, {message: /not be called at all/});95});
modified:index.d.ts+16 added-15 removed
29 unmodified lines
30 | Unless<IsSync, 'overlapped'>;3132// @todo Use `string`, `Uint8Array` or `unknown` for both the argument and the return type, based on whether `encoding: 'buffer'` and `objectMode: true` are used.33// See https://github.com/sindresorhus/execa/issues/69434type GeneratorTransform = (chunk: unknown) => AsyncGenerator<unknown, void, void> | Generator<unknown, void, void>;35type GeneratorFinal = () => AsyncGenerator<unknown, void, void> | Generator<unknown, void, void>;34type GeneratorTransform<IsSync extends boolean> = (chunk: unknown) =>35| Unless<IsSync, AsyncGenerator<unknown, void, void>>36| Generator<unknown, void, void>;37type GeneratorFinal<IsSync extends boolean> = () =>38| Unless<IsSync, AsyncGenerator<unknown, void, void>>39| Generator<unknown, void, void>;4037type GeneratorTransformFull = {38 transform: GeneratorTransform;39 final?: GeneratorFinal;41type GeneratorTransformFull<IsSync extends boolean> = {42 transform: GeneratorTransform<IsSync>;43 final?: GeneratorFinal<IsSync>;44 binary?: boolean;45 preserveNewlines?: boolean;46 objectMode?: boolean;47};
14 unmodified lines
62> =63 | BaseStdioOption<IsSync, IsArray>64 | URL65 | {file: string}66 | GeneratorTransform<IsSync>67 | GeneratorTransformFull<IsSync>68 | Unless<And<IsSync, IsArray>, number>69 | Unless<Or<IsSync, IsArray>, 'ipc'>70 | Unless<IsSync,65 | GeneratorTransform66 | GeneratorTransformFull71 | DuplexTransform72 | WebTransform73 | TransformStream>;7475// Synchronous iterables excluding strings, Uint8Arrays and Arrays72type IterableObject<73 IsSync extends boolean = boolean,74 IsArray extends boolean = boolean,75> = Iterable<Unless<IsSync, unknown, string | Uint8Array>>76type IterableObject<IsArray extends boolean = boolean> = Iterable<unknown>77& object78& {readonly BYTES_PER_ELEMENT?: never}79& AndUnless<IsArray, {readonly lastIndexOf?: never}>;80
1 unmodified line
82 IsSync extends boolean = boolean,83 IsExtra extends boolean = boolean,84 IsArray extends boolean = boolean,85> =85 | Unless<And<IsSync, IsExtra>, Uint8Array | IterableObject<IsSync, IsArray>>86 | Unless<And<IsSync, IsExtra>, Uint8Array | IterableObject<IsArray>>87 | Unless<And<IsSync, IsArray>, Readable>88 | Unless<IsSync, AsyncIterable<unknown> | ReadableStream>;8990type OutputStdioOption<
90 unmodified lines
181 ? OutputOptions[number]182 : OutputOptions183>;184184type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull | WebTransform185type IsObjectOutputOption<OutputOption extends StdioSingleOption> = OutputOption extends GeneratorTransformFull<boolean> | WebTransform186 ? BooleanObjectMode<OutputOption['objectMode']>187 : OutputOption extends DuplexTransform188 ? DuplexObjectMode<OutputOption>189 : false;
1212 unmodified lines
1402Same as `execa()` but synchronous.14031404Returns 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.14051405Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an iterable of objects, a transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1406Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14071408@param file - The program/script to execute, as a string or file URL1409@param arguments - Arguments to pass to `file` on execution.1410@returns A `subprocessResult` object
105 unmodified lines
1516Same as `execaCommand()` but synchronous.15171518Returns 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.15191519Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an iterable of objects, a transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1520Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.15211522@param command - The program/script to execute and its arguments.1523@returns A `subprocessResult` object1524@throws A `subprocessResult` error
128 unmodified lines
modified:index.test-d.ts+137 added-137 removed
160 unmodified lines
161const preserveNewlinesOnly = {preserveNewlines: true} as const;162const objectModeOnly = {objectMode: true} as const;163const finalOnly = {final: unknownFinal} as const;164165type AnySyncChunk = string | Uint8Array | undefined;166type AnyChunk = AnySyncChunk | string[] | unknown[];165type AnySyncChunk = string | Uint8Array | unknown[] | undefined;166type AnyChunk = AnySyncChunk | string[];167expectType<Writable | null>({} as ExecaSubprocess['stdin']);168expectType<Readable | null>({} as ExecaSubprocess['stdout']);169expectType<Readable | null>({} as ExecaSubprocess['stderr']);170expectType<Readable | undefined>({} as ExecaSubprocess['all']);
1872 unmodified lines
2043expectNotAssignable<StdoutStderrOptionSync>([binaryArray]);2044expectAssignable<StdioOption>([binaryArray]);2045expectAssignable<StdioOptionSync>([binaryArray]);2046execa('unicorns', {stdin: [objectArray]});2047expectError(execaSync('unicorns', {stdin: [objectArray]}));2047execaSync('unicorns', {stdin: [objectArray]});2048expectError(execa('unicorns', {stdout: [objectArray]}));2049expectError(execaSync('unicorns', {stdout: [objectArray]}));2050expectError(execa('unicorns', {stderr: [objectArray]}));2051expectError(execaSync('unicorns', {stderr: [objectArray]}));
1 unmodified line
2053expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectArray]]}));2054execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [[objectArray]]]});2055expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [[objectArray]]]}));2056expectAssignable<StdinOption>([objectArray]);2057expectNotAssignable<StdinOptionSync>([objectArray]);2057expectAssignable<StdinOptionSync>([objectArray]);2058expectNotAssignable<StdoutStderrOption>([objectArray]);2059expectNotAssignable<StdoutStderrOptionSync>([objectArray]);2060expectAssignable<StdioOption>([objectArray]);2061expectNotAssignable<StdioOptionSync>([objectArray]);2061expectAssignable<StdioOptionSync>([objectArray]);2062execa('unicorns', {stdin: stringIterable});2063execaSync('unicorns', {stdin: stringIterable});2064execa('unicorns', {stdin: [stringIterable]});2065execaSync('unicorns', {stdin: [stringIterable]});
53 unmodified lines
2119expectAssignable<StdioOptionSync>(binaryIterable);2120expectAssignable<StdioOption>([binaryIterable]);2121expectAssignable<StdioOptionSync>([binaryIterable]);2122execa('unicorns', {stdin: objectIterable});2123expectError(execaSync('unicorns', {stdin: objectIterable}));2123execaSync('unicorns', {stdin: objectIterable});2124execa('unicorns', {stdin: [objectIterable]});2125expectError(execaSync('unicorns', {stdin: [objectIterable]}));2125execaSync('unicorns', {stdin: [objectIterable]});2126expectError(execa('unicorns', {stdout: objectIterable}));2127expectError(execaSync('unicorns', {stdout: objectIterable}));2128expectError(execa('unicorns', {stdout: [objectIterable]}));2129expectError(execaSync('unicorns', {stdout: [objectIterable]}));
7 unmodified lines
2137expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectIterable]}));2138execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectIterable]]});2139expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectIterable]]}));2140expectAssignable<StdinOption>(objectIterable);2141expectNotAssignable<StdinOptionSync>(objectIterable);2141expectAssignable<StdinOptionSync>(objectIterable);2142expectAssignable<StdinOption>([objectIterable]);2143expectNotAssignable<StdinOptionSync>([objectIterable]);2143expectAssignable<StdinOptionSync>([objectIterable]);2144expectNotAssignable<StdoutStderrOption>(objectIterable);2145expectNotAssignable<StdoutStderrOptionSync>(objectIterable);2146expectNotAssignable<StdoutStderrOption>([objectIterable]);2147expectNotAssignable<StdoutStderrOptionSync>([objectIterable]);2148expectAssignable<StdioOption>(objectIterable);2149expectNotAssignable<StdioOptionSync>(objectIterable);2149expectAssignable<StdioOptionSync>(objectIterable);2150expectAssignable<StdioOption>([objectIterable]);2151expectNotAssignable<StdioOptionSync>([objectIterable]);2151expectAssignable<StdioOptionSync>([objectIterable]);2152execa('unicorns', {stdin: asyncStringIterable});2153expectError(execaSync('unicorns', {stdin: asyncStringIterable}));2154execa('unicorns', {stdin: [asyncStringIterable]});2155expectError(execaSync('unicorns', {stdin: [asyncStringIterable]}));
323 unmodified lines
2479expectNotAssignable<StdioOptionSync>(webTransformWithInvalidObjectMode);2480expectNotAssignable<StdioOption>([webTransformWithInvalidObjectMode]);2481expectNotAssignable<StdioOptionSync>([webTransformWithInvalidObjectMode]);2482execa('unicorns', {stdin: unknownGenerator});2483expectError(execaSync('unicorns', {stdin: unknownGenerator}));2483execaSync('unicorns', {stdin: unknownGenerator});2484execa('unicorns', {stdin: [unknownGenerator]});2485expectError(execaSync('unicorns', {stdin: [unknownGenerator]}));2485execaSync('unicorns', {stdin: [unknownGenerator]});2486execa('unicorns', {stdout: unknownGenerator});2487expectError(execaSync('unicorns', {stdout: unknownGenerator}));2487execaSync('unicorns', {stdout: unknownGenerator});2488execa('unicorns', {stdout: [unknownGenerator]});2489expectError(execaSync('unicorns', {stdout: [unknownGenerator]}));2489execaSync('unicorns', {stdout: [unknownGenerator]});2490execa('unicorns', {stderr: unknownGenerator});2491expectError(execaSync('unicorns', {stderr: unknownGenerator}));2491execaSync('unicorns', {stderr: unknownGenerator});2492execa('unicorns', {stderr: [unknownGenerator]});2493expectError(execaSync('unicorns', {stderr: [unknownGenerator]}));2493execaSync('unicorns', {stderr: [unknownGenerator]});2494expectError(execa('unicorns', {stdio: unknownGenerator}));2495expectError(execaSync('unicorns', {stdio: unknownGenerator}));2496execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownGenerator]});2497expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownGenerator]}));2497execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownGenerator]});2498execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownGenerator]]});2499expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownGenerator]]}));2499execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownGenerator]]});2500expectAssignable<StdinOption>(unknownGenerator);2501expectNotAssignable<StdinOptionSync>(unknownGenerator);2501expectAssignable<StdinOptionSync>(unknownGenerator);2502expectAssignable<StdinOption>([unknownGenerator]);2503expectNotAssignable<StdinOptionSync>([unknownGenerator]);2503expectAssignable<StdinOptionSync>([unknownGenerator]);2504expectAssignable<StdoutStderrOption>(unknownGenerator);2505expectNotAssignable<StdoutStderrOptionSync>(unknownGenerator);2505expectAssignable<StdoutStderrOptionSync>(unknownGenerator);2506expectAssignable<StdoutStderrOption>([unknownGenerator]);2507expectNotAssignable<StdoutStderrOptionSync>([unknownGenerator]);2507expectAssignable<StdoutStderrOptionSync>([unknownGenerator]);2508expectAssignable<StdioOption>(unknownGenerator);2509expectNotAssignable<StdioOptionSync>(unknownGenerator);2509expectAssignable<StdioOptionSync>(unknownGenerator);2510expectAssignable<StdioOption>([unknownGenerator]);2511expectNotAssignable<StdioOptionSync>([unknownGenerator]);2511expectAssignable<StdioOptionSync>([unknownGenerator]);2512execa('unicorns', {stdin: unknownGeneratorFull});2513expectError(execaSync('unicorns', {stdin: unknownGeneratorFull}));2513execaSync('unicorns', {stdin: unknownGeneratorFull});2514execa('unicorns', {stdin: [unknownGeneratorFull]});2515expectError(execaSync('unicorns', {stdin: [unknownGeneratorFull]}));2515execaSync('unicorns', {stdin: [unknownGeneratorFull]});2516execa('unicorns', {stdout: unknownGeneratorFull});2517expectError(execaSync('unicorns', {stdout: unknownGeneratorFull}));2517execaSync('unicorns', {stdout: unknownGeneratorFull});2518execa('unicorns', {stdout: [unknownGeneratorFull]});2519expectError(execaSync('unicorns', {stdout: [unknownGeneratorFull]}));2519execaSync('unicorns', {stdout: [unknownGeneratorFull]});2520execa('unicorns', {stderr: unknownGeneratorFull});2521expectError(execaSync('unicorns', {stderr: unknownGeneratorFull}));2521execaSync('unicorns', {stderr: unknownGeneratorFull});2522execa('unicorns', {stderr: [unknownGeneratorFull]});2523expectError(execaSync('unicorns', {stderr: [unknownGeneratorFull]}));2523execaSync('unicorns', {stderr: [unknownGeneratorFull]});2524expectError(execa('unicorns', {stdio: unknownGeneratorFull}));2525expectError(execaSync('unicorns', {stdio: unknownGeneratorFull}));2526execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownGeneratorFull]});2527expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownGeneratorFull]}));2527execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownGeneratorFull]});2528execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownGeneratorFull]]});2529expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownGeneratorFull]]}));2529execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownGeneratorFull]]});2530expectAssignable<StdinOption>(unknownGeneratorFull);2531expectNotAssignable<StdinOptionSync>(unknownGeneratorFull);2531expectAssignable<StdinOptionSync>(unknownGeneratorFull);2532expectAssignable<StdinOption>([unknownGeneratorFull]);2533expectNotAssignable<StdinOptionSync>([unknownGeneratorFull]);2533expectAssignable<StdinOptionSync>([unknownGeneratorFull]);2534expectAssignable<StdoutStderrOption>(unknownGeneratorFull);2535expectNotAssignable<StdoutStderrOptionSync>(unknownGeneratorFull);2535expectAssignable<StdoutStderrOptionSync>(unknownGeneratorFull);2536expectAssignable<StdoutStderrOption>([unknownGeneratorFull]);2537expectNotAssignable<StdoutStderrOptionSync>([unknownGeneratorFull]);2537expectAssignable<StdoutStderrOptionSync>([unknownGeneratorFull]);2538expectAssignable<StdioOption>(unknownGeneratorFull);2539expectNotAssignable<StdioOptionSync>(unknownGeneratorFull);2539expectAssignable<StdioOptionSync>(unknownGeneratorFull);2540expectAssignable<StdioOption>([unknownGeneratorFull]);2541expectNotAssignable<StdioOptionSync>([unknownGeneratorFull]);2541expectAssignable<StdioOptionSync>([unknownGeneratorFull]);2542execa('unicorns', {stdin: unknownFinalFull});2543expectError(execaSync('unicorns', {stdin: unknownFinalFull}));2543execaSync('unicorns', {stdin: unknownFinalFull});2544execa('unicorns', {stdin: [unknownFinalFull]});2545expectError(execaSync('unicorns', {stdin: [unknownFinalFull]}));2545execaSync('unicorns', {stdin: [unknownFinalFull]});2546execa('unicorns', {stdout: unknownFinalFull});2547expectError(execaSync('unicorns', {stdout: unknownFinalFull}));2547execaSync('unicorns', {stdout: unknownFinalFull});2548execa('unicorns', {stdout: [unknownFinalFull]});2549expectError(execaSync('unicorns', {stdout: [unknownFinalFull]}));2549execaSync('unicorns', {stdout: [unknownFinalFull]});2550execa('unicorns', {stderr: unknownFinalFull});2551expectError(execaSync('unicorns', {stderr: unknownFinalFull}));2551execaSync('unicorns', {stderr: unknownFinalFull});2552execa('unicorns', {stderr: [unknownFinalFull]});2553expectError(execaSync('unicorns', {stderr: [unknownFinalFull]}));2553execaSync('unicorns', {stderr: [unknownFinalFull]});2554expectError(execa('unicorns', {stdio: unknownFinalFull}));2555expectError(execaSync('unicorns', {stdio: unknownFinalFull}));2556execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownFinalFull]});2557expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownFinalFull]}));2557execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', unknownFinalFull]});2558execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownFinalFull]]});2559expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownFinalFull]]}));2559execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [unknownFinalFull]]});2560expectAssignable<StdinOption>(unknownFinalFull);2561expectNotAssignable<StdinOptionSync>(unknownFinalFull);2561expectAssignable<StdinOptionSync>(unknownFinalFull);2562expectAssignable<StdinOption>([unknownFinalFull]);2563expectNotAssignable<StdinOptionSync>([unknownFinalFull]);2563expectAssignable<StdinOptionSync>([unknownFinalFull]);2564expectAssignable<StdoutStderrOption>(unknownFinalFull);2565expectNotAssignable<StdoutStderrOptionSync>(unknownFinalFull);2565expectAssignable<StdoutStderrOptionSync>(unknownFinalFull);2566expectAssignable<StdoutStderrOption>([unknownFinalFull]);2567expectNotAssignable<StdoutStderrOptionSync>([unknownFinalFull]);2567expectAssignable<StdoutStderrOptionSync>([unknownFinalFull]);2568expectAssignable<StdioOption>(unknownFinalFull);2569expectNotAssignable<StdioOptionSync>(unknownFinalFull);2569expectAssignable<StdioOptionSync>(unknownFinalFull);2570expectAssignable<StdioOption>([unknownFinalFull]);2571expectNotAssignable<StdioOptionSync>([unknownFinalFull]);2571expectAssignable<StdioOptionSync>([unknownFinalFull]);2572execa('unicorns', {stdin: objectGenerator});2573expectError(execaSync('unicorns', {stdin: objectGenerator}));2573execaSync('unicorns', {stdin: objectGenerator});2574execa('unicorns', {stdin: [objectGenerator]});2575expectError(execaSync('unicorns', {stdin: [objectGenerator]}));2575execaSync('unicorns', {stdin: [objectGenerator]});2576execa('unicorns', {stdout: objectGenerator});2577expectError(execaSync('unicorns', {stdout: objectGenerator}));2577execaSync('unicorns', {stdout: objectGenerator});2578execa('unicorns', {stdout: [objectGenerator]});2579expectError(execaSync('unicorns', {stdout: [objectGenerator]}));2579execaSync('unicorns', {stdout: [objectGenerator]});2580execa('unicorns', {stderr: objectGenerator});2581expectError(execaSync('unicorns', {stderr: objectGenerator}));2581execaSync('unicorns', {stderr: objectGenerator});2582execa('unicorns', {stderr: [objectGenerator]});2583expectError(execaSync('unicorns', {stderr: [objectGenerator]}));2583execaSync('unicorns', {stderr: [objectGenerator]});2584expectError(execa('unicorns', {stdio: objectGenerator}));2585expectError(execaSync('unicorns', {stdio: objectGenerator}));2586execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectGenerator]});2587expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectGenerator]}));2587execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectGenerator]});2588execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectGenerator]]});2589expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectGenerator]]}));2589execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectGenerator]]});2590expectAssignable<StdinOption>(objectGenerator);2591expectNotAssignable<StdinOptionSync>(objectGenerator);2591expectAssignable<StdinOptionSync>(objectGenerator);2592expectAssignable<StdinOption>([objectGenerator]);2593expectNotAssignable<StdinOptionSync>([objectGenerator]);2593expectAssignable<StdinOptionSync>([objectGenerator]);2594expectAssignable<StdoutStderrOption>(objectGenerator);2595expectNotAssignable<StdoutStderrOptionSync>(objectGenerator);2595expectAssignable<StdoutStderrOptionSync>(objectGenerator);2596expectAssignable<StdoutStderrOption>([objectGenerator]);2597expectNotAssignable<StdoutStderrOptionSync>([objectGenerator]);2597expectAssignable<StdoutStderrOptionSync>([objectGenerator]);2598expectAssignable<StdioOption>(objectGenerator);2599expectNotAssignable<StdioOptionSync>(objectGenerator);2599expectAssignable<StdioOptionSync>(objectGenerator);2600expectAssignable<StdioOption>([objectGenerator]);2601expectNotAssignable<StdioOptionSync>([objectGenerator]);2601expectAssignable<StdioOptionSync>([objectGenerator]);2602execa('unicorns', {stdin: objectGeneratorFull});2603expectError(execaSync('unicorns', {stdin: objectGeneratorFull}));2603execaSync('unicorns', {stdin: objectGeneratorFull});2604execa('unicorns', {stdin: [objectGeneratorFull]});2605expectError(execaSync('unicorns', {stdin: [objectGeneratorFull]}));2605execaSync('unicorns', {stdin: [objectGeneratorFull]});2606execa('unicorns', {stdout: objectGeneratorFull});2607expectError(execaSync('unicorns', {stdout: objectGeneratorFull}));2607execaSync('unicorns', {stdout: objectGeneratorFull});2608execa('unicorns', {stdout: [objectGeneratorFull]});2609expectError(execaSync('unicorns', {stdout: [objectGeneratorFull]}));2609execaSync('unicorns', {stdout: [objectGeneratorFull]});2610execa('unicorns', {stderr: objectGeneratorFull});2611expectError(execaSync('unicorns', {stderr: objectGeneratorFull}));2611execaSync('unicorns', {stderr: objectGeneratorFull});2612execa('unicorns', {stderr: [objectGeneratorFull]});2613expectError(execaSync('unicorns', {stderr: [objectGeneratorFull]}));2613execaSync('unicorns', {stderr: [objectGeneratorFull]});2614expectError(execa('unicorns', {stdio: objectGeneratorFull}));2615expectError(execaSync('unicorns', {stdio: objectGeneratorFull}));2616execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectGeneratorFull]});2617expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectGeneratorFull]}));2617execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectGeneratorFull]});2618execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectGeneratorFull]]});2619expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectGeneratorFull]]}));2619execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectGeneratorFull]]});2620expectAssignable<StdinOption>(objectGeneratorFull);2621expectNotAssignable<StdinOptionSync>(objectGeneratorFull);2621expectAssignable<StdinOptionSync>(objectGeneratorFull);2622expectAssignable<StdinOption>([objectGeneratorFull]);2623expectNotAssignable<StdinOptionSync>([objectGeneratorFull]);2623expectAssignable<StdinOptionSync>([objectGeneratorFull]);2624expectAssignable<StdoutStderrOption>(objectGeneratorFull);2625expectNotAssignable<StdoutStderrOptionSync>(objectGeneratorFull);2625expectAssignable<StdoutStderrOptionSync>(objectGeneratorFull);2626expectAssignable<StdoutStderrOption>([objectGeneratorFull]);2627expectNotAssignable<StdoutStderrOptionSync>([objectGeneratorFull]);2627expectAssignable<StdoutStderrOptionSync>([objectGeneratorFull]);2628expectAssignable<StdioOption>(objectGeneratorFull);2629expectNotAssignable<StdioOptionSync>(objectGeneratorFull);2629expectAssignable<StdioOptionSync>(objectGeneratorFull);2630expectAssignable<StdioOption>([objectGeneratorFull]);2631expectNotAssignable<StdioOptionSync>([objectGeneratorFull]);2631expectAssignable<StdioOptionSync>([objectGeneratorFull]);2632execa('unicorns', {stdin: objectFinalFull});2633expectError(execaSync('unicorns', {stdin: objectFinalFull}));2633execaSync('unicorns', {stdin: objectFinalFull});2634execa('unicorns', {stdin: [objectFinalFull]});2635expectError(execaSync('unicorns', {stdin: [objectFinalFull]}));2635execaSync('unicorns', {stdin: [objectFinalFull]});2636execa('unicorns', {stdout: objectFinalFull});2637expectError(execaSync('unicorns', {stdout: objectFinalFull}));2637execaSync('unicorns', {stdout: objectFinalFull});2638execa('unicorns', {stdout: [objectFinalFull]});2639expectError(execaSync('unicorns', {stdout: [objectFinalFull]}));2639execaSync('unicorns', {stdout: [objectFinalFull]});2640execa('unicorns', {stderr: objectFinalFull});2641expectError(execaSync('unicorns', {stderr: objectFinalFull}));2641execaSync('unicorns', {stderr: objectFinalFull});2642execa('unicorns', {stderr: [objectFinalFull]});2643expectError(execaSync('unicorns', {stderr: [objectFinalFull]}));2643execaSync('unicorns', {stderr: [objectFinalFull]});2644expectError(execa('unicorns', {stdio: objectFinalFull}));2645expectError(execaSync('unicorns', {stdio: objectFinalFull}));2646execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectFinalFull]});2647expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectFinalFull]}));2647execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', objectFinalFull]});2648execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectFinalFull]]});2649expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectFinalFull]]}));2649execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [objectFinalFull]]});2650expectAssignable<StdinOption>(objectFinalFull);2651expectNotAssignable<StdinOptionSync>(objectFinalFull);2651expectAssignable<StdinOptionSync>(objectFinalFull);2652expectAssignable<StdinOption>([objectFinalFull]);2653expectNotAssignable<StdinOptionSync>([objectFinalFull]);2653expectAssignable<StdinOptionSync>([objectFinalFull]);2654expectAssignable<StdoutStderrOption>(objectFinalFull);2655expectNotAssignable<StdoutStderrOptionSync>(objectFinalFull);2655expectAssignable<StdoutStderrOptionSync>(objectFinalFull);2656expectAssignable<StdoutStderrOption>([objectFinalFull]);2657expectNotAssignable<StdoutStderrOptionSync>([objectFinalFull]);2657expectAssignable<StdoutStderrOptionSync>([objectFinalFull]);2658expectAssignable<StdioOption>(objectFinalFull);2659expectNotAssignable<StdioOptionSync>(objectFinalFull);2659expectAssignable<StdioOptionSync>(objectFinalFull);2660expectAssignable<StdioOption>([objectFinalFull]);2661expectNotAssignable<StdioOptionSync>([objectFinalFull]);2661expectAssignable<StdioOptionSync>([objectFinalFull]);2662expectError(execa('unicorns', {stdin: booleanGenerator}));2663expectError(execaSync('unicorns', {stdin: booleanGenerator}));2664expectError(execa('unicorns', {stdin: [booleanGenerator]}));2665expectError(execaSync('unicorns', {stdin: [booleanGenerator]}));
293 unmodified lines
2959expectNotAssignable<StdioOptionSync>(invalidReturnFinalFull);2960expectNotAssignable<StdioOption>([invalidReturnFinalFull]);2961expectNotAssignable<StdioOptionSync>([invalidReturnFinalFull]);2962execa('unicorns', {stdin: transformWithBinary});2963expectError(execaSync('unicorns', {stdin: transformWithBinary}));2963execaSync('unicorns', {stdin: transformWithBinary});2964execa('unicorns', {stdin: [transformWithBinary]});2965expectError(execaSync('unicorns', {stdin: [transformWithBinary]}));2965execaSync('unicorns', {stdin: [transformWithBinary]});2966execa('unicorns', {stdout: transformWithBinary});2967expectError(execaSync('unicorns', {stdout: transformWithBinary}));2967execaSync('unicorns', {stdout: transformWithBinary});2968execa('unicorns', {stdout: [transformWithBinary]});2969expectError(execaSync('unicorns', {stdout: [transformWithBinary]}));2969execaSync('unicorns', {stdout: [transformWithBinary]});2970execa('unicorns', {stderr: transformWithBinary});2971expectError(execaSync('unicorns', {stderr: transformWithBinary}));2971execaSync('unicorns', {stderr: transformWithBinary});2972execa('unicorns', {stderr: [transformWithBinary]});2973expectError(execaSync('unicorns', {stderr: [transformWithBinary]}));2973execaSync('unicorns', {stderr: [transformWithBinary]});2974expectError(execa('unicorns', {stdio: transformWithBinary}));2975expectError(execaSync('unicorns', {stdio: transformWithBinary}));2976execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithBinary]});2977expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithBinary]}));2977execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithBinary]});2978execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithBinary]]});2979expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithBinary]]}));2979execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithBinary]]});2980expectAssignable<StdinOption>(transformWithBinary);2981expectNotAssignable<StdinOptionSync>(transformWithBinary);2981expectAssignable<StdinOptionSync>(transformWithBinary);2982expectAssignable<StdinOption>([transformWithBinary]);2983expectNotAssignable<StdinOptionSync>([transformWithBinary]);2983expectAssignable<StdinOptionSync>([transformWithBinary]);2984expectAssignable<StdoutStderrOption>(transformWithBinary);2985expectNotAssignable<StdoutStderrOptionSync>(transformWithBinary);2985expectAssignable<StdoutStderrOptionSync>(transformWithBinary);2986expectAssignable<StdoutStderrOption>([transformWithBinary]);2987expectNotAssignable<StdoutStderrOptionSync>([transformWithBinary]);2987expectAssignable<StdoutStderrOptionSync>([transformWithBinary]);2988expectAssignable<StdioOption>(transformWithBinary);2989expectNotAssignable<StdioOptionSync>(transformWithBinary);2989expectAssignable<StdioOptionSync>(transformWithBinary);2990expectAssignable<StdioOption>([transformWithBinary]);2991expectNotAssignable<StdioOptionSync>([transformWithBinary]);2991expectAssignable<StdioOptionSync>([transformWithBinary]);2992expectError(execa('unicorns', {stdin: transformWithInvalidBinary}));2993expectError(execaSync('unicorns', {stdin: transformWithInvalidBinary}));2994expectError(execa('unicorns', {stdin: [transformWithInvalidBinary]}));2995expectError(execaSync('unicorns', {stdin: [transformWithInvalidBinary]}));
23 unmodified lines
3019expectNotAssignable<StdioOptionSync>(transformWithInvalidBinary);3020expectNotAssignable<StdioOption>([transformWithInvalidBinary]);3021expectNotAssignable<StdioOptionSync>([transformWithInvalidBinary]);3022execa('unicorns', {stdin: transformWithPreserveNewlines});3023expectError(execaSync('unicorns', {stdin: transformWithPreserveNewlines}));3023execaSync('unicorns', {stdin: transformWithPreserveNewlines});3024execa('unicorns', {stdin: [transformWithPreserveNewlines]});3025expectError(execaSync('unicorns', {stdin: [transformWithPreserveNewlines]}));3025execaSync('unicorns', {stdin: [transformWithPreserveNewlines]});3026execa('unicorns', {stdout: transformWithPreserveNewlines});3027expectError(execaSync('unicorns', {stdout: transformWithPreserveNewlines}));3027execaSync('unicorns', {stdout: transformWithPreserveNewlines});3028execa('unicorns', {stdout: [transformWithPreserveNewlines]});3029expectError(execaSync('unicorns', {stdout: [transformWithPreserveNewlines]}));3029execaSync('unicorns', {stdout: [transformWithPreserveNewlines]});3030execa('unicorns', {stderr: transformWithPreserveNewlines});3031expectError(execaSync('unicorns', {stderr: transformWithPreserveNewlines}));3031execaSync('unicorns', {stderr: transformWithPreserveNewlines});3032execa('unicorns', {stderr: [transformWithPreserveNewlines]});3033expectError(execaSync('unicorns', {stderr: [transformWithPreserveNewlines]}));3033execaSync('unicorns', {stderr: [transformWithPreserveNewlines]});3034expectError(execa('unicorns', {stdio: transformWithPreserveNewlines}));3035expectError(execaSync('unicorns', {stdio: transformWithPreserveNewlines}));3036execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithPreserveNewlines]});3037expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithPreserveNewlines]}));3037execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithPreserveNewlines]});3038execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithPreserveNewlines]]});3039expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithPreserveNewlines]]}));3039execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithPreserveNewlines]]});3040expectAssignable<StdinOption>(transformWithPreserveNewlines);3041expectNotAssignable<StdinOptionSync>(transformWithPreserveNewlines);3041expectAssignable<StdinOptionSync>(transformWithPreserveNewlines);3042expectAssignable<StdinOption>([transformWithPreserveNewlines]);3043expectNotAssignable<StdinOptionSync>([transformWithPreserveNewlines]);3043expectAssignable<StdinOptionSync>([transformWithPreserveNewlines]);3044expectAssignable<StdoutStderrOption>(transformWithPreserveNewlines);3045expectNotAssignable<StdoutStderrOptionSync>(transformWithPreserveNewlines);3045expectAssignable<StdoutStderrOptionSync>(transformWithPreserveNewlines);3046expectAssignable<StdoutStderrOption>([transformWithPreserveNewlines]);3047expectNotAssignable<StdoutStderrOptionSync>([transformWithPreserveNewlines]);3047expectAssignable<StdoutStderrOptionSync>([transformWithPreserveNewlines]);3048expectAssignable<StdioOption>(transformWithPreserveNewlines);3049expectNotAssignable<StdioOptionSync>(transformWithPreserveNewlines);3049expectAssignable<StdioOptionSync>(transformWithPreserveNewlines);3050expectAssignable<StdioOption>([transformWithPreserveNewlines]);3051expectNotAssignable<StdioOptionSync>([transformWithPreserveNewlines]);3051expectAssignable<StdioOptionSync>([transformWithPreserveNewlines]);3052expectError(execa('unicorns', {stdin: transformWithInvalidPreserveNewlines}));3053expectError(execaSync('unicorns', {stdin: transformWithInvalidPreserveNewlines}));3054expectError(execa('unicorns', {stdin: [transformWithInvalidPreserveNewlines]}));3055expectError(execaSync('unicorns', {stdin: [transformWithInvalidPreserveNewlines]}));
23 unmodified lines
3079expectNotAssignable<StdioOptionSync>(transformWithInvalidPreserveNewlines);3080expectNotAssignable<StdioOption>([transformWithInvalidPreserveNewlines]);3081expectNotAssignable<StdioOptionSync>([transformWithInvalidPreserveNewlines]);3082execa('unicorns', {stdin: transformWithObjectMode});3083expectError(execaSync('unicorns', {stdin: transformWithObjectMode}));3083execaSync('unicorns', {stdin: transformWithObjectMode});3084execa('unicorns', {stdin: [transformWithObjectMode]});3085expectError(execaSync('unicorns', {stdin: [transformWithObjectMode]}));3085execaSync('unicorns', {stdin: [transformWithObjectMode]});3086execa('unicorns', {stdout: transformWithObjectMode});3087expectError(execaSync('unicorns', {stdout: transformWithObjectMode}));3087execaSync('unicorns', {stdout: transformWithObjectMode});3088execa('unicorns', {stdout: [transformWithObjectMode]});3089expectError(execaSync('unicorns', {stdout: [transformWithObjectMode]}));3089execaSync('unicorns', {stdout: [transformWithObjectMode]});3090execa('unicorns', {stderr: transformWithObjectMode});3091expectError(execaSync('unicorns', {stderr: transformWithObjectMode}));3091execaSync('unicorns', {stderr: transformWithObjectMode});3092execa('unicorns', {stderr: [transformWithObjectMode]});3093expectError(execaSync('unicorns', {stderr: [transformWithObjectMode]}));3093execaSync('unicorns', {stderr: [transformWithObjectMode]});3094expectError(execa('unicorns', {stdio: transformWithObjectMode}));3095expectError(execaSync('unicorns', {stdio: transformWithObjectMode}));3096execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithObjectMode]});3097expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithObjectMode]}));3097execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', transformWithObjectMode]});3098execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithObjectMode]]});3099expectError(execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithObjectMode]]}));3099execaSync('unicorns', {stdio: ['pipe', 'pipe', 'pipe', [transformWithObjectMode]]});3100expectAssignable<StdinOption>(transformWithObjectMode);3101expectNotAssignable<StdinOptionSync>(transformWithObjectMode);3101expectAssignable<StdinOptionSync>(transformWithObjectMode);3102expectAssignable<StdinOption>([transformWithObjectMode]);3103expectNotAssignable<StdinOptionSync>([transformWithObjectMode]);3103expectAssignable<StdinOptionSync>([transformWithObjectMode]);3104expectAssignable<StdoutStderrOption>(transformWithObjectMode);3105expectNotAssignable<StdoutStderrOptionSync>(transformWithObjectMode);3105expectAssignable<StdoutStderrOptionSync>(transformWithObjectMode);3106expectAssignable<StdoutStderrOption>([transformWithObjectMode]);3107expectNotAssignable<StdoutStderrOptionSync>([transformWithObjectMode]);3107expectAssignable<StdoutStderrOptionSync>([transformWithObjectMode]);3108expectAssignable<StdioOption>(transformWithObjectMode);3109expectNotAssignable<StdioOptionSync>(transformWithObjectMode);3109expectAssignable<StdioOptionSync>(transformWithObjectMode);3110expectAssignable<StdioOption>([transformWithObjectMode]);3111expectNotAssignable<StdioOptionSync>([transformWithObjectMode]);3111expectAssignable<StdioOptionSync>([transformWithObjectMode]);3112expectError(execa('unicorns', {stdin: transformWithInvalidObjectMode}));3113expectError(execaSync('unicorns', {stdin: transformWithInvalidObjectMode}));3114expectError(execa('unicorns', {stdin: [transformWithInvalidObjectMode]}));3115expectError(execaSync('unicorns', {stdin: [transformWithInvalidObjectMode]}));
556 unmodified lines
modified:package.json+1 added
65 unmodified lines
66 "c8": "^8.0.1",67 "get-node": "^15.0.0",68 "is-running": "^2.1.0",69 "p-event": "^6.0.0",70 "path-exists": "^5.0.0",71 "path-key": "^4.0.0",72 "tempfile": "^5.0.0",73 "tsd": "^0.29.0",74 "which": "^4.0.0",
25 unmodified lines
modified:readme.md+1 added-1 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) and [`stdio`](#stdio-1) cannot be a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an iterable of objects, a [transform](docs/transform.md), a [`Duplex`](docs/transform.md#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.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) and [`stdio`](#stdio-1) cannot be a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#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`\
899 unmodified lines