Split files into smaller ones (#976)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 7faa8f5 · Browse files · 134 files·+6999 added−6655 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
134 files+6999 added−6655 removed
- tests:+6118 added−5808 removed
- other:+881 added−847 removed
Provenance
- Commit
d7c6853- Tree
6d28607- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
7faa8f5
134 files changed+6999 added−6655 removed
added:lib/arguments/command.js+13 added
12345678910111213import {logCommand} from '../verbose/start.js';import {getVerboseInfo} from '../verbose/info.js';import {getStartTime} from '../return/duration.js';import {joinCommand} from './escape.js';import {normalizeFdSpecificOption} from './specific.js';
export const handleCommand = (filePath, rawArgs, rawOptions) => { const startTime = getStartTime(); const {command, escapedCommand} = joinCommand(filePath, rawArgs); const verboseInfo = getVerboseInfo(normalizeFdSpecificOption(rawOptions, 'verbose')); logCommand(escapedCommand, verboseInfo, rawOptions); return {command, escapedCommand, startTime, verboseInfo};};modified:lib/arguments/cwd.js+1 added-13 removed
1233456787 unmodified lines161718192021222324252627282930312021222314 unmodified linesimport {statSync} from 'node:fs';import {resolve} from 'node:path';import {fileURLToPath} from 'node:url';import process from 'node:process';import {safeNormalizeFileUrl} from './file-url.js';
export const normalizeCwd = (cwd = getDefaultCwd()) => { const cwdString = safeNormalizeFileUrl(cwd, 'The "cwd" option'); return resolve(cwdString);7 unmodified lines throw error; }};
export const safeNormalizeFileUrl = (file, name) => { const fileString = normalizeFileUrl(file);
if (typeof fileString !== 'string') { throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`); }
return fileString;};
export const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;
export const fixCwdError = (originalMessage, cwd) => { if (cwd === getDefaultCwd()) { return originalMessage; }14 unmodified linesadded:lib/arguments/file-url.js+13 added
12345678910111213import {fileURLToPath} from 'node:url';
export const safeNormalizeFileUrl = (file, name) => { const fileString = normalizeFileUrl(file);
if (typeof fileString !== 'string') { throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`); }
return fileString;};
export const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;modified:lib/arguments/node.js+1 added-1 removed
1233456735 unmodified linesimport {execPath, execArgv} from 'node:process';import {basename, resolve} from 'node:path';import {safeNormalizeFileUrl} from './cwd.js';import {safeNormalizeFileUrl} from './file-url.js';
export const mapNode = ({options}) => { if (options.node === false) { throw new TypeError('The "node" option cannot be false with `execaNode()`.');35 unmodified linesmodified:lib/arguments/normalize.js+1 added-1 removed
122345623 unmodified linesimport isPlainObject from 'is-plain-obj';import {safeNormalizeFileUrl} from './cwd.js';import {safeNormalizeFileUrl} from './file-url.js';
export const normalizeArguments = (rawFile, rawArgs = [], rawOptions = {}) => { const filePath = safeNormalizeFileUrl(rawFile, 'First argument'); const [args, options] = isPlainObject(rawArgs)23 unmodified linesmodified:lib/arguments/options.js+3 added-14 removed
2 unmodified lines3 import crossSpawn from 'cross-spawn';4 import {npmRunPathEnv} from 'npm-run-path';5 import {normalizeForceKillAfterDelay} from '../exit/kill.js';6 import {validateTimeout} from '../exit/timeout.js';7-import {logCommand} from '../verbose/start.js';8-import {getVerboseInfo} from '../verbose/info.js';9-import {getStartTime} from '../return/duration.js';7 import {validateEncoding, BINARY_ENCODINGS} from './encoding.js';8 import {handleNodeOption} from './node.js';12-import {joinCommand} from './escape.js';13-import {normalizeCwd, normalizeFileUrl} from './cwd.js';14-import {normalizeFdSpecificOptions, normalizeFdSpecificOption} from './specific.js';9+import {normalizeCwd} from './cwd.js';10+import {normalizeFileUrl} from './file-url.js';11+import {normalizeFdSpecificOptions} from './specific.js';12 16-export const handleCommand = (filePath, rawArgs, rawOptions) => {17- const startTime = getStartTime();18- const {command, escapedCommand} = joinCommand(filePath, rawArgs);19- const verboseInfo = getVerboseInfo(normalizeFdSpecificOption(rawOptions, 'verbose'));20- logCommand(escapedCommand, verboseInfo, rawOptions);21- return {command, escapedCommand, startTime, verboseInfo};22-};23-13 export const handleOptions = (filePath, rawArgs, rawOptions) => {14 rawOptions.cwd = normalizeCwd(rawOptions.cwd);15 const [processedFile, processedArgs, processedOptions] = handleNodeOption(filePath, rawArgs, rawOptions);16 60 unmodified linesmodified:lib/arguments/template.js+3 added-1 removed
1+import {ChildProcess} from 'node:child_process';2 import {isUint8Array, uint8ArrayToString} from '../stdio/uint-array.js';2-import {isSubprocess} from '../utils.js';3 4 export const isTemplateString = templates => Array.isArray(templates) && Array.isArray(templates.raw);5 6 export const parseTemplates = (templates, expressions) => {123 unmodified lines130 }131 132 throw new TypeError(`Unexpected "${typeOfExpression}" in template expression`);133 };134+135+const isSubprocess = value => value instanceof ChildProcess;added:lib/convert/fd-options.js+105 added
1+import {parseFd} from '../arguments/specific.js';2+3+export const getWritable = (destination, to = 'stdin') => {4+ const isWritable = true;5+ const {options, fileDescriptors} = SUBPROCESS_OPTIONS.get(destination);6+ const fdNumber = getFdNumber(fileDescriptors, to, isWritable);7+ const destinationStream = destination.stdio[fdNumber];8+9+ if (destinationStream === null) {10+ throw new TypeError(getInvalidStdioOptionMessage(fdNumber, to, options, isWritable));11+ }12+13+ return destinationStream;14+};15+16+export const getReadable = (source, from = 'stdout') => {17+ const isWritable = false;18+ const {options, fileDescriptors} = SUBPROCESS_OPTIONS.get(source);19+ const fdNumber = getFdNumber(fileDescriptors, from, isWritable);20+ const sourceStream = fdNumber === 'all' ? source.all : source.stdio[fdNumber];21+22+ if (sourceStream === null || sourceStream === undefined) {23+ throw new TypeError(getInvalidStdioOptionMessage(fdNumber, from, options, isWritable));24+ }25+26+ return sourceStream;27+};28+29+export const SUBPROCESS_OPTIONS = new WeakMap();30+31+const getFdNumber = (fileDescriptors, fdName, isWritable) => {32+ const fdNumber = parseFdNumber(fdName, isWritable);33+ validateFdNumber(fdNumber, fdName, isWritable, fileDescriptors);34+ return fdNumber;35+};36+37+const parseFdNumber = (fdName, isWritable) => {38+ const fdNumber = parseFd(fdName);39+ if (fdNumber !== undefined) {40+ return fdNumber;41+ }42+43+ const {validOptions, defaultValue} = isWritable44+ ? {validOptions: '"stdin"', defaultValue: 'stdin'}45+ : {validOptions: '"stdout", "stderr", "all"', defaultValue: 'stdout'};46+ throw new TypeError(`"${getOptionName(isWritable)}" must not be "${fdName}".47+It must be ${validOptions} or "fd3", "fd4" (and so on).48+It is optional and defaults to "${defaultValue}".`);49+};50+51+const validateFdNumber = (fdNumber, fdName, isWritable, fileDescriptors) => {52+ const fileDescriptor = fileDescriptors[getUsedDescriptor(fdNumber)];53+ if (fileDescriptor === undefined) {54+ throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. That file descriptor does not exist.55+Please set the "stdio" option to ensure that file descriptor exists.`);56+ }57+58+ if (fileDescriptor.direction === 'input' && !isWritable) {59+ throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a readable stream, not writable.`);60+ }61+62+ if (fileDescriptor.direction !== 'input' && isWritable) {63+ throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a writable stream, not readable.`);64+ }65+};66+67+const getInvalidStdioOptionMessage = (fdNumber, fdName, options, isWritable) => {68+ if (fdNumber === 'all' && !options.all) {69+ return 'The "all" option must be true to use "from: \'all\'".';70+ }71+72+ const {optionName, optionValue} = getInvalidStdioOption(fdNumber, options);73+ return `The "${optionName}: ${serializeOptionValue(optionValue)}" option is incompatible with using "${getOptionName(isWritable)}: ${serializeOptionValue(fdName)}".74+Please set this option with "pipe" instead.`;75+};76+77+const getInvalidStdioOption = (fdNumber, {stdin, stdout, stderr, stdio}) => {78+ const usedDescriptor = getUsedDescriptor(fdNumber);79+80+ if (usedDescriptor === 0 && stdin !== undefined) {81+ return {optionName: 'stdin', optionValue: stdin};82+ }83+84+ if (usedDescriptor === 1 && stdout !== undefined) {85+ return {optionName: 'stdout', optionValue: stdout};86+ }87+88+ if (usedDescriptor === 2 && stderr !== undefined) {89+ return {optionName: 'stderr', optionValue: stderr};90+ }91+92+ return {optionName: `stdio[${usedDescriptor}]`, optionValue: stdio[usedDescriptor]};93+};94+95+const getUsedDescriptor = fdNumber => fdNumber === 'all' ? 1 : fdNumber;96+97+const getOptionName = isWritable => isWritable ? 'to' : 'from';98+99+export const serializeOptionValue = value => {100+ if (typeof value === 'string') {101+ return `'${value}'`;102+ }103+104+ return typeof value === 'number' ? `${value}` : 'Stream';105+};modified:lib/convert/iterable.js+1 added-1 removed
122345620 unmodified linesimport {BINARY_ENCODINGS} from '../arguments/encoding.js';import {getReadable} from '../pipe/validate.js';import {getReadable} from './fd-options.js';import {iterateOnSubprocessStream} from './loop.js';
export const createIterable = (subprocess, encoding, { from,20 unmodified linesmodified:lib/convert/loop.js+1 added-1 removed
1 import {on} from 'node:events';2 import {getEncodingTransformGenerator} from '../stdio/encoding-transform.js';3 import {getSplitLinesGenerator} from '../stdio/split.js';4-import {transformChunkSync, finalChunksSync} from '../stdio/transform.js';4+import {transformChunkSync, finalChunksSync} from '../stdio/transform-sync.js';5 6 // Iterate over lines of `subprocess.stdout`, used by `subprocess.readable|duplex|iterable()`7 export const iterateOnSubprocessStream = ({subprocessStdout, subprocess, binary, shouldEncode, encoding, preserveNewlines}) => {8 const controller = new AbortController();88 unmodified linesmodified:lib/convert/readable.js+1 added-1 removed
1 import {Readable} from 'node:stream';2 import {callbackify} from 'node:util';3 import {BINARY_ENCODINGS} from '../arguments/encoding.js';4-import {getReadable} from '../pipe/validate.js';4+import {getReadable} from './fd-options.js';5 import {addConcurrentStream, waitForConcurrentStreams} from './concurrent.js';6 import {7 createDeferred,8 safeWaitForSubprocessStdin,87 unmodified linesmodified:lib/convert/writable.js+1 added-1 removed
1 import {Writable} from 'node:stream';2 import {callbackify} from 'node:util';3-import {getWritable} from '../pipe/validate.js';3+import {getWritable} from './fd-options.js';4 import {addConcurrentStream, waitForConcurrentStreams} from './concurrent.js';5 import {6 safeWaitForSubprocessStdout,7 waitForSubprocessStdin,78 unmodified linesdeleted:lib/exit/code.js-30 removed
1-import {DiscardedError} from '../return/cause.js';2-import {isMaxBufferSync} from '../stream/max-buffer.js';3-4-export const waitForSuccessfulExit = async exitPromise => {5- const [exitCode, signal] = await exitPromise;6-7- if (!isSubprocessErrorExit(exitCode, signal) && isFailedExit(exitCode, signal)) {8- throw new DiscardedError();9- }10-11- return [exitCode, signal];12-};13-14-export const getSyncExitResult = ({error, status: exitCode, signal, output}, {maxBuffer}) => {15- const resultError = getResultError(error, exitCode, signal);16- const timedOut = resultError?.code === 'ETIMEDOUT';17- const isMaxBuffer = isMaxBufferSync(resultError, output, maxBuffer);18- return {resultError, exitCode, signal, timedOut, isMaxBuffer};19-};20-21-const getResultError = (error, exitCode, signal) => {22- if (error !== undefined) {23- return error;24- }25-26- return isFailedExit(exitCode, signal) ? new DiscardedError() : undefined;27-};28-29-const isSubprocessErrorExit = (exitCode, signal) => exitCode === undefined && signal === undefined;30-const isFailedExit = (exitCode, signal) => exitCode !== 0 || signal !== null;modified:lib/pipe/streaming.js+1 added-1 removed
1 import {finished} from 'node:stream/promises';2 import mergeStreams from '@sindresorhus/merge-streams';3-import {incrementMaxListeners} from '../utils.js';3+import {incrementMaxListeners} from '../max-listener.js';4 import {pipeStreams} from '../stdio/pipeline.js';5 6 // The piping behavior is like Bash.7 // In particular, when one subprocess exits, the other is not terminated by a signal.44 unmodified linesmodified:lib/pipe/validate.js+1 added-98 removed
1 import {normalizeArguments} from '../arguments/normalize.js';2 import {getStartTime} from '../return/duration.js';3-import {serializeOptionValue} from '../stdio/native.js';4-import {parseFd} from '../arguments/specific.js';3+import {SUBPROCESS_OPTIONS, getWritable, getReadable} from '../convert/fd-options.js';4 5 export const normalizePipeArguments = ({source, sourcePromise, boundOptions, createNested}, ...args) => {6 const startTime = getStartTime();7 const {60 unmodified lines68 };69 70 const mapDestinationArguments = ({options}) => ({options: {...options, stdin: 'pipe', piped: true}});71 73-export const SUBPROCESS_OPTIONS = new WeakMap();74-75-export const getWritable = (destination, to = 'stdin') => {76- const isWritable = true;77- const {options, fileDescriptors} = SUBPROCESS_OPTIONS.get(destination);78- const fdNumber = getFdNumber(fileDescriptors, to, isWritable);79- const destinationStream = destination.stdio[fdNumber];80-81- if (destinationStream === null) {82- throw new TypeError(getInvalidStdioOptionMessage(fdNumber, to, options, isWritable));83- }84-85- return destinationStream;86-};87-72 const getSourceStream = (source, from) => {73 try {74 const sourceStream = getReadable(source, from);75 return {sourceStream};76 } catch (error) {77 return {sourceError: error};78 }79 };96-97-export const getReadable = (source, from = 'stdout') => {98- const isWritable = false;99- const {options, fileDescriptors} = SUBPROCESS_OPTIONS.get(source);100- const fdNumber = getFdNumber(fileDescriptors, from, isWritable);101- const sourceStream = fdNumber === 'all' ? source.all : source.stdio[fdNumber];102-103- if (sourceStream === null || sourceStream === undefined) {104- throw new TypeError(getInvalidStdioOptionMessage(fdNumber, from, options, isWritable));105- }106-107- return sourceStream;108-};109-110-const getFdNumber = (fileDescriptors, fdName, isWritable) => {111- const fdNumber = parseFdNumber(fdName, isWritable);112- validateFdNumber(fdNumber, fdName, isWritable, fileDescriptors);113- return fdNumber;114-};115-116-const parseFdNumber = (fdName, isWritable) => {117- const fdNumber = parseFd(fdName);118- if (fdNumber !== undefined) {119- return fdNumber;120- }121-122- const {validOptions, defaultValue} = isWritable123- ? {validOptions: '"stdin"', defaultValue: 'stdin'}124- : {validOptions: '"stdout", "stderr", "all"', defaultValue: 'stdout'};125- throw new TypeError(`"${getOptionName(isWritable)}" must not be "${fdName}".126-It must be ${validOptions} or "fd3", "fd4" (and so on).127-It is optional and defaults to "${defaultValue}".`);128-};129-130-const validateFdNumber = (fdNumber, fdName, isWritable, fileDescriptors) => {131- const fileDescriptor = fileDescriptors[getUsedDescriptor(fdNumber)];132- if (fileDescriptor === undefined) {133- throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. That file descriptor does not exist.134-Please set the "stdio" option to ensure that file descriptor exists.`);135- }136-137- if (fileDescriptor.direction === 'input' && !isWritable) {138- throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a readable stream, not writable.`);139- }140-141- if (fileDescriptor.direction !== 'input' && isWritable) {142- throw new TypeError(`"${getOptionName(isWritable)}" must not be ${fdName}. It must be a writable stream, not readable.`);143- }144-};145-146-const getInvalidStdioOptionMessage = (fdNumber, fdName, options, isWritable) => {147- if (fdNumber === 'all' && !options.all) {148- return 'The "all" option must be true to use "from: \'all\'".';149- }150-151- const {optionName, optionValue} = getInvalidStdioOption(fdNumber, options);152- return `The "${optionName}: ${serializeOptionValue(optionValue)}" option is incompatible with using "${getOptionName(isWritable)}: ${serializeOptionValue(fdName)}".153-Please set this option with "pipe" instead.`;154-};155-156-const getInvalidStdioOption = (fdNumber, {stdin, stdout, stderr, stdio}) => {157- const usedDescriptor = getUsedDescriptor(fdNumber);158-159- if (usedDescriptor === 0 && stdin !== undefined) {160- return {optionName: 'stdin', optionValue: stdin};161- }162-163- if (usedDescriptor === 1 && stdout !== undefined) {164- return {optionName: 'stdout', optionValue: stdout};165- }166-167- if (usedDescriptor === 2 && stderr !== undefined) {168- return {optionName: 'stderr', optionValue: stderr};169- }170-171- return {optionName: `stdio[${usedDescriptor}]`, optionValue: stdio[usedDescriptor]};172-};173-174-const getUsedDescriptor = fdNumber => fdNumber === 'all' ? 1 : fdNumber;175-176-const getOptionName = isWritable => isWritable ? 'to' : 'from';modified:lib/return/early-error.js+1 added-1 removed
1 import {ChildProcess} from 'node:child_process';2 import {PassThrough, Readable, Writable, Duplex} from 'node:stream';3 import {cleanupCustomStreams} from '../stdio/async.js';4 import {makeEarlyError} from './error.js';5-import {handleResult} from './output.js';5+import {handleResult} from './reject.js';6 7 // When the subprocess fails to spawn.8 // We ensure the returned error is always both a promise and a subprocess.9 export const handleEarlyError = ({error, command, escapedCommand, fileDescriptors, options, startTime, verboseInfo}) => {32 unmodified linesmodified:lib/return/error.js+2 added-89 removed
1 import {signalsByName} from 'human-signals';2-import stripFinalNewline from 'strip-final-newline';3-import {isUint8Array, uint8ArrayToString} from '../stdio/uint-array.js';4-import {fixCwdError} from '../arguments/cwd.js';5-import {escapeLines} from '../arguments/escape.js';6-import {getMaxBufferMessage} from '../stream/max-buffer.js';2 import {getDurationMs} from './duration.js';8-import {getFinalError, DiscardedError, isExecaError} from './cause.js';3+import {getFinalError} from './cause.js';4+import {createMessages} from './message.js';5 6 export const makeSuccessResult = ({7 command,8 escapedCommand,110 unmodified lines119 const signal = rawSignal === null ? undefined : rawSignal;120 const signalDescription = signal === undefined ? undefined : signalsByName[rawSignal].description;121 return {exitCode, signal, signalDescription};122 };127-128-const createMessages = ({129- stdio,130- all,131- originalError,132- signal,133- signalDescription,134- exitCode,135- escapedCommand,136- timedOut,137- isCanceled,138- isMaxBuffer,139- maxBuffer,140- timeout,141- cwd,142-}) => {143- const errorCode = originalError?.code;144- const prefix = getErrorPrefix({originalError, timedOut, timeout, isMaxBuffer, maxBuffer, errorCode, signal, signalDescription, exitCode, isCanceled});145- const originalMessage = getOriginalMessage(originalError, cwd);146- const newline = originalMessage === '' ? '' : '\n';147- const shortMessage = `${prefix}: ${escapedCommand}${newline}${originalMessage}`;148- const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];149- const message = [shortMessage, ...messageStdio, ...stdio.slice(3)]150- .map(messagePart => escapeLines(stripFinalNewline(serializeMessagePart(messagePart))))151- .filter(Boolean)152- .join('\n\n');153- return {originalMessage, shortMessage, message};154-};155-156-const getErrorPrefix = ({originalError, timedOut, timeout, isMaxBuffer, maxBuffer, errorCode, signal, signalDescription, exitCode, isCanceled}) => {157- if (timedOut) {158- return `Command timed out after ${timeout} milliseconds`;159- }160-161- if (isCanceled) {162- return 'Command was canceled';163- }164-165- if (isMaxBuffer) {166- return getMaxBufferMessage(originalError, maxBuffer);167- }168-169- if (errorCode !== undefined) {170- return `Command failed with ${errorCode}`;171- }172-173- if (signal !== undefined) {174- return `Command was killed with ${signal} (${signalDescription})`;175- }176-177- if (exitCode !== undefined) {178- return `Command failed with exit code ${exitCode}`;179- }180-181- return 'Command failed';182-};183-184-const getOriginalMessage = (originalError, cwd) => {185- if (originalError instanceof DiscardedError) {186- return '';187- }188-189- const originalMessage = isExecaError(originalError)190- ? originalError.originalMessage191- : String(originalError?.message ?? originalError);192- return escapeLines(fixCwdError(originalMessage, cwd));193-};194-195-const serializeMessagePart = messagePart => Array.isArray(messagePart)196- ? messagePart.map(messageItem => stripFinalNewline(serializeMessageItem(messageItem))).filter(Boolean).join('\n')197- : serializeMessageItem(messagePart);198-199-const serializeMessageItem = messageItem => {200- if (typeof messageItem === 'string') {201- return messageItem;202- }203-204- if (isUint8Array(messageItem)) {205- return uint8ArrayToString(messageItem);206- }207-208- return '';209-};added:lib/return/message.js+89 added
1+import stripFinalNewline from 'strip-final-newline';2+import {isUint8Array, uint8ArrayToString} from '../stdio/uint-array.js';3+import {fixCwdError} from '../arguments/cwd.js';4+import {escapeLines} from '../arguments/escape.js';5+import {getMaxBufferMessage} from '../stream/max-buffer.js';6+import {DiscardedError, isExecaError} from './cause.js';7+8+export const createMessages = ({9+ stdio,10+ all,11+ originalError,12+ signal,13+ signalDescription,14+ exitCode,15+ escapedCommand,16+ timedOut,17+ isCanceled,18+ isMaxBuffer,19+ maxBuffer,20+ timeout,21+ cwd,22+}) => {23+ const errorCode = originalError?.code;24+ const prefix = getErrorPrefix({originalError, timedOut, timeout, isMaxBuffer, maxBuffer, errorCode, signal, signalDescription, exitCode, isCanceled});25+ const originalMessage = getOriginalMessage(originalError, cwd);26+ const newline = originalMessage === '' ? '' : '\n';27+ const shortMessage = `${prefix}: ${escapedCommand}${newline}${originalMessage}`;28+ const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];29+ const message = [shortMessage, ...messageStdio, ...stdio.slice(3)]30+ .map(messagePart => escapeLines(stripFinalNewline(serializeMessagePart(messagePart))))31+ .filter(Boolean)32+ .join('\n\n');33+ return {originalMessage, shortMessage, message};34+};35+36+const getErrorPrefix = ({originalError, timedOut, timeout, isMaxBuffer, maxBuffer, errorCode, signal, signalDescription, exitCode, isCanceled}) => {37+ if (timedOut) {38+ return `Command timed out after ${timeout} milliseconds`;39+ }40+41+ if (isCanceled) {42+ return 'Command was canceled';43+ }44+45+ if (isMaxBuffer) {46+ return getMaxBufferMessage(originalError, maxBuffer);47+ }48+49+ if (errorCode !== undefined) {50+ return `Command failed with ${errorCode}`;51+ }52+53+ if (signal !== undefined) {54+ return `Command was killed with ${signal} (${signalDescription})`;55+ }56+57+ if (exitCode !== undefined) {58+ return `Command failed with exit code ${exitCode}`;59+ }60+61+ return 'Command failed';62+};63+64+const getOriginalMessage = (originalError, cwd) => {65+ if (originalError instanceof DiscardedError) {66+ return '';67+ }68+69+ const originalMessage = isExecaError(originalError)70+ ? originalError.originalMessage71+ : String(originalError?.message ?? originalError);72+ return escapeLines(fixCwdError(originalMessage, cwd));73+};74+75+const serializeMessagePart = messagePart => Array.isArray(messagePart)76+ ? messagePart.map(messageItem => stripFinalNewline(serializeMessageItem(messageItem))).filter(Boolean).join('\n')77+ : serializeMessageItem(messagePart);78+79+const serializeMessageItem = messageItem => {80+ if (typeof messageItem === 'string') {81+ return messageItem;82+ }83+84+ if (isUint8Array(messageItem)) {85+ return uint8ArrayToString(messageItem);86+ }87+88+ return '';89+};deleted:lib/return/output.js-20 removed
1-import stripFinalNewlineFunction from 'strip-final-newline';2-import {logFinalResult} from '../verbose/complete.js';3-4-export const stripNewline = (value, {stripFinalNewline}, fdNumber) => getStripFinalNewline(stripFinalNewline, fdNumber) && value !== undefined && !Array.isArray(value)5- ? stripFinalNewlineFunction(value)6- : value;7-8-export const getStripFinalNewline = (stripFinalNewline, fdNumber) => fdNumber === 'all'9- ? stripFinalNewline[1] || stripFinalNewline[2]10- : stripFinalNewline[fdNumber];11-12-export const handleResult = (result, verboseInfo, {reject}) => {13- logFinalResult(result, reject, verboseInfo);14-15- if (result.failed && reject) {16- throw result;17- }18-19- return result;20-};added:lib/return/reject.js+11 added
1+import {logFinalResult} from '../verbose/complete.js';2+3+export const handleResult = (result, verboseInfo, {reject}) => {4+ logFinalResult(result, reject, verboseInfo);5+6+ if (result.failed && reject) {7+ throw result;8+ }9+10+ return result;11+};added:lib/return/strip-newline.js+9 added
1+import stripFinalNewlineFunction from 'strip-final-newline';2+3+export const stripNewline = (value, {stripFinalNewline}, fdNumber) => getStripFinalNewline(stripFinalNewline, fdNumber) && value !== undefined && !Array.isArray(value)4+ ? stripFinalNewlineFunction(value)5+ : value;6+7+export const getStripFinalNewline = (stripFinalNewline, fdNumber) => fdNumber === 'all'8+ ? stripFinalNewline[1] || stripFinalNewline[2]9+ : stripFinalNewline[fdNumber];added:lib/stdio/all-sync.js+32 added
1+import {stripNewline} from '../return/strip-newline.js';2+import {isUint8Array, concatUint8Arrays} from './uint-array.js';3+4+export const getAllSync = ([, stdout, stderr], options) => {5+ if (!options.all) {6+ return;7+ }8+9+ if (stdout === undefined) {10+ return stderr;11+ }12+13+ if (stderr === undefined) {14+ return stdout;15+ }16+17+ if (Array.isArray(stdout)) {18+ return Array.isArray(stderr)19+ ? [...stdout, ...stderr]20+ : [...stdout, stripNewline(stderr, options, 'all')];21+ }22+23+ if (Array.isArray(stderr)) {24+ return [stripNewline(stdout, options, 'all'), ...stderr];25+ }26+27+ if (isUint8Array(stdout) && isUint8Array(stderr)) {28+ return concatUint8Arrays([stdout, stderr]);29+ }30+31+ return `${stdout}${stderr}`;32+};modified:lib/stdio/async.js+4 added-54 removed
1 import {createReadStream, createWriteStream} from 'node:fs';2 import {Buffer} from 'node:buffer';3 import {Readable, Writable, Duplex} from 'node:stream';4-import mergeStreams from '@sindresorhus/merge-streams';5-import {isStandardStream, incrementMaxListeners} from '../utils.js';4+import {isStandardStream} from '../utils.js';5 import {handleInput} from './handle.js';7-import {pipeStreams} from './pipeline.js';6 import {TYPE_TO_MESSAGE} from './type.js';9-import {generatorToDuplexStream, pipeTransform, TRANSFORM_TYPES} from './generator.js';7+import {generatorToStream} from './transform-run.js';8 9 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode10 export const handleInputAsync = (options, verboseInfo) => handleInput(addPropertiesAsync, options, verboseInfo, false);11 1 unmodified line13 throw new TypeError(`The \`${optionName}\` option cannot be ${TYPE_TO_MESSAGE[type]}.`);14 };15 16 const addProperties = {19- generator: generatorToDuplexStream,20- asyncGenerator: generatorToDuplexStream,17+ generator: generatorToStream,18+ asyncGenerator: generatorToStream,19 nodeStream: ({value}) => ({stream: value}),20 webTransform({value: {transform, writableObjectMode, readableObjectMode}}) {21 const objectMode = writableObjectMode || readableObjectMode;22 const stream = Duplex.fromWeb(transform, {objectMode});25 unmodified lines48 uint8Array: forbiddenIfAsync,49 },50 };51 54-// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async mode55-// When multiple input streams are used, we merge them to ensure the output stream ends only once each input stream has ended56-export const pipeOutputAsync = (subprocess, fileDescriptors, controller) => {57- const inputStreamsGroups = {};58-59- for (const [fdNumber, {stdioItems, direction}] of Object.entries(fileDescriptors)) {60- for (const {stream} of stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type))) {61- pipeTransform(subprocess, stream, direction, fdNumber);62- }63-64- for (const {stream} of stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type))) {65- pipeStdioItem({subprocess, stream, direction, fdNumber, inputStreamsGroups, controller});66- }67- }68-69- for (const [fdNumber, inputStreams] of Object.entries(inputStreamsGroups)) {70- const inputStream = inputStreams.length === 1 ? inputStreams[0] : mergeStreams(inputStreams);71- pipeStreams(inputStream, subprocess.stdio[fdNumber]);72- }73-};74-75-const pipeStdioItem = ({subprocess, stream, direction, fdNumber, inputStreamsGroups, controller}) => {76- if (stream === undefined) {77- return;78- }79-80- setStandardStreamMaxListeners(stream, controller);81-82- if (direction === 'output') {83- pipeStreams(subprocess.stdio[fdNumber], stream);84- } else {85- inputStreamsGroups[fdNumber] = [...(inputStreamsGroups[fdNumber] ?? []), stream];86- }87-};88-89-// Multiple subprocesses might be piping from/to `process.std*` at the same time.90-// This is not necessarily an error and should not print a `maxListeners` warning.91-const setStandardStreamMaxListeners = (stream, {signal}) => {92- if (isStandardStream(stream)) {93- incrementMaxListeners(stream, MAX_LISTENERS_INCREMENT, signal);94- }95-};96-97-// `source.pipe(destination)` adds at most 1 listener for each event.98-// If `stdin` option is an array, the values might be combined with `merge-streams`.99-// That library also listens for `source` end, which adds 1 more listener.100-const MAX_LISTENERS_INCREMENT = 2;101-52 // The stream error handling is performed by the piping logic above, which cannot be performed before subprocess spawning.53 // If the subprocess spawning fails (e.g. due to an invalid command), the streams need to be manually destroyed.54 // We need to create those streams before subprocess spawning, in case their creation fails, e.g. when passing an invalid generator as argument.55 // Like this, an exception would be thrown, which would prevent spawning a subprocess.9 unmodified linesdeleted:lib/stdio/generator.js-198 removed
1-import isPlainObj from 'is-plain-obj';2-import {BINARY_ENCODINGS} from '../arguments/encoding.js';3-import {generatorsToTransform, runTransformSync} from './transform.js';4-import {getEncodingTransformGenerator} from './encoding-transform.js';5-import {getSplitLinesGenerator, getAppendNewlineGenerator} from './split.js';6-import {pipeStreams} from './pipeline.js';7-import {isAsyncGenerator} from './type.js';8-import {getValidateTransformInput, getValidateTransformReturn} from './validate.js';9-10-export const normalizeTransforms = (stdioItems, optionName, direction, options) => [11- ...stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type)),12- ...getTransforms(stdioItems, optionName, direction, options),13-];14-15-const getTransforms = (stdioItems, optionName, direction, {encoding}) => {16- const transforms = stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type));17- const newTransforms = Array.from({length: transforms.length});18-19- for (const [index, stdioItem] of Object.entries(transforms)) {20- newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, optionName, direction, encoding});21- }22-23- return sortTransforms(newTransforms, direction);24-};25-26-export const TRANSFORM_TYPES = new Set(['generator', 'asyncGenerator', 'duplex', 'webTransform']);27-28-const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => {29- if (type === 'duplex') {30- return normalizeDuplex({stdioItem, optionName});31- }32-33- if (type === 'webTransform') {34- return normalizeTransformStream({stdioItem, index, newTransforms, direction});35- }36-37- return normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});38-};39-40-const normalizeDuplex = ({41- stdioItem,42- stdioItem: {43- value: {44- transform,45- transform: {writableObjectMode, readableObjectMode},46- objectMode = readableObjectMode,47- },48- },49- optionName,50-}) => {51- if (objectMode && !readableObjectMode) {52- throw new TypeError(`The \`${optionName}.objectMode\` option can only be \`true\` if \`new Duplex({objectMode: true})\` is used.`);53- }54-55- if (!objectMode && readableObjectMode) {56- throw new TypeError(`The \`${optionName}.objectMode\` option cannot be \`false\` if \`new Duplex({objectMode: true})\` is used.`);57- }58-59- return {60- ...stdioItem,61- value: {transform, writableObjectMode, readableObjectMode},62- };63-};64-65-const normalizeTransformStream = ({stdioItem, stdioItem: {value}, index, newTransforms, direction}) => {66- const {transform, objectMode} = isPlainObj(value) ? value : {transform: value};67- const {writableObjectMode, readableObjectMode} = getObjectModes(objectMode, index, newTransforms, direction);68- return ({69- ...stdioItem,70- value: {transform, writableObjectMode, readableObjectMode},71- });72-};73-74-const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {75- const {76- transform,77- final,78- binary: binaryOption = false,79- preserveNewlines = false,80- objectMode,81- } = isPlainObj(value) ? value : {transform: value};82- const binary = binaryOption || BINARY_ENCODINGS.has(encoding);83- const {writableObjectMode, readableObjectMode} = getObjectModes(objectMode, index, newTransforms, direction);84- return {...stdioItem, value: {transform, final, binary, preserveNewlines, writableObjectMode, readableObjectMode}};85-};86-87-/*88-`objectMode` determines the return value's type, i.e. the `readableObjectMode`.89-The chunk argument's type is based on the previous generator's return value, i.e. the `writableObjectMode` is based on the previous `readableObjectMode`.90-The last input's generator is read by `subprocess.stdin` which:91-- should not be in `objectMode` for performance reasons.92-- can only be strings, Buffers and Uint8Arrays.93-Therefore its `readableObjectMode` must be `false`.94-The same applies to the first output's generator's `writableObjectMode`.95-*/96-const getObjectModes = (objectMode, index, newTransforms, direction) => direction === 'output'97- ? getOutputObjectModes(objectMode, index, newTransforms)98- : getInputObjectModes(objectMode, index, newTransforms);99-100-const getOutputObjectModes = (objectMode, index, newTransforms) => {101- const writableObjectMode = index !== 0 && newTransforms[index - 1].value.readableObjectMode;102- const readableObjectMode = objectMode ?? writableObjectMode;103- return {writableObjectMode, readableObjectMode};104-};105-106-const getInputObjectModes = (objectMode, index, newTransforms) => {107- const writableObjectMode = index === 0108- ? objectMode === true109- : newTransforms[index - 1].value.readableObjectMode;110- const readableObjectMode = index !== newTransforms.length - 1 && (objectMode ?? writableObjectMode);111- return {writableObjectMode, readableObjectMode};112-};113-114-const sortTransforms = (newTransforms, direction) => direction === 'input' ? newTransforms.reverse() : newTransforms;115-116-export const getObjectMode = (stdioItems, direction) => {117- const lastTransform = stdioItems.findLast(({type}) => TRANSFORM_TYPES.has(type));118- if (lastTransform === undefined) {119- return false;120- }121-122- return direction === 'input'123- ? lastTransform.value.writableObjectMode124- : lastTransform.value.readableObjectMode;125-};126-127-/*128-Generators can be used to transform/filter standard streams.129-130-Generators have a simple syntax, yet allows all of the following:131-- Sharing `state` between chunks132-- Flushing logic, by using a `final` function133-- Asynchronous logic134-- Emitting multiple chunks from a single source chunk, even if spaced in time, by using multiple `yield`135-- Filtering, by using no `yield`136-137-Therefore, there is no need to allow Node.js or web transform streams.138-139-The `highWaterMark` is kept as the default value, since this is what `subprocess.std*` uses.140-141-Chunks are currently processed serially. We could add a `concurrency` option to parallelize in the future.142-*/143-export const generatorToDuplexStream = ({144- value,145- value: {transform, final, writableObjectMode, readableObjectMode},146- optionName,147-}, {encoding}) => {148- const generators = addInternalGenerators(value, encoding, optionName);149- const transformAsync = isAsyncGenerator(transform);150- const finalAsync = isAsyncGenerator(final);151- const stream = generatorsToTransform(generators, {transformAsync, finalAsync, writableObjectMode, readableObjectMode});152- return {stream};153-};154-155-export const getGenerators = stdioItems => stdioItems.filter(({type}) => type === 'generator');156-157-export const runGeneratorsSync = (chunks, generators, encoding) => {158- for (const {value, optionName} of generators) {159- const generators = addInternalGenerators(value, encoding, optionName);160- chunks = runTransformSync(generators, chunks);161- }162-163- return chunks;164-};165-166-const addInternalGenerators = (167- {transform, final, binary, writableObjectMode, readableObjectMode, preserveNewlines},168- encoding,169- optionName,170-) => {171- const state = {};172- return [173- {transform: getValidateTransformInput(writableObjectMode, optionName)},174- getEncodingTransformGenerator(binary, encoding, writableObjectMode),175- getSplitLinesGenerator(binary, preserveNewlines, writableObjectMode, state),176- {transform, final},177- {transform: getValidateTransformReturn(readableObjectMode, optionName)},178- getAppendNewlineGenerator({binary, preserveNewlines, readableObjectMode, state}),179- ].filter(Boolean);180-};181-182-// `subprocess.stdin|stdout|stderr|stdio` is directly mutated.183-export const pipeTransform = (subprocess, stream, direction, fdNumber) => {184- if (direction === 'output') {185- pipeStreams(subprocess.stdio[fdNumber], stream);186- } else {187- pipeStreams(stream, subprocess.stdio[fdNumber]);188- }189-190- const streamProperty = SUBPROCESS_STREAM_PROPERTIES[fdNumber];191- if (streamProperty !== undefined) {192- subprocess[streamProperty] = stream;193- }194-195- subprocess.stdio[fdNumber] = stream;196-};197-198-const SUBPROCESS_STREAM_PROPERTIES = ['stdin', 'stdout', 'stderr'];modified:lib/stdio/handle.js+3 added-2 removed
2 unmodified lines3 import {getStreamDirection} from './direction.js';4 import {normalizeStdio} from './option.js';5 import {handleNativeStream} from './native.js';6 import {handleInputOptions} from './input.js';7-import {normalizeTransforms, getObjectMode} from './generator.js';7+import {normalizeTransforms} from './normalize-transform.js';8+import {getFdObjectMode} from './object-mode.js';9 10 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode11 export const handleInput = (addProperties, options, verboseInfo, isSync) => {12 const stdio = normalizeStdio(options, isSync);11 unmodified lines24 const {stdioItems: initialStdioItems, isStdioArray} = initializeStdioItems({stdioOption, fdNumber, options, optionName});25 const direction = getStreamDirection(initialStdioItems, fdNumber, optionName);26 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({stdioItem, isStdioArray, fdNumber, direction, isSync}));27 const normalizedStdioItems = normalizeTransforms(stdioItems, optionName, direction, options);27- const objectMode = getObjectMode(normalizedStdioItems, direction);28+ const objectMode = getFdObjectMode(normalizedStdioItems, direction);29 validateFileObjectMode(normalizedStdioItems, objectMode);30 const finalStdioItems = normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction, options));31 return {direction, objectMode, stdioItems: finalStdioItems};32 };94 unmodified linesmodified:lib/stdio/input-sync.js+2 added-3 removed
1 import {joinToUint8Array, isUint8Array} from './uint-array.js';2 import {TYPE_TO_MESSAGE} from './type.js';3-import {getGenerators, runGeneratorsSync} from './generator.js';3+import {runGeneratorsSync} from './transform-run.js';4 5 // Apply `stdin`/`input`/`inputFile` options, before spawning, in sync mode, by converting it to the `input` option6 export const addInputOptionsSync = (fileDescriptors, options) => {7 for (const fdNumber of getInputFdNumbers(fileDescriptors)) {22 unmodified lines30 options.input = joinToUint8Array(transformedContents);31 };32 33 const applySingleInputGeneratorsSync = (contents, stdioItems) => {34- const generators = getGenerators(stdioItems).reverse();35- const newContents = runGeneratorsSync(contents, generators, 'utf8');34+ const newContents = runGeneratorsSync(contents, stdioItems, 'utf8', true);35 validateSerializable(newContents);36 return joinToUint8Array(newContents);37 };38 6 unmodified linesmodified:lib/stdio/native.js+1 added-8 removed
1 import {readFileSync} from 'node:fs';2 import tty from 'node:tty';3 import {isStream as isNodeStream} from 'is-stream';4 import {STANDARD_STREAMS} from '../utils.js';5+import {serializeOptionValue} from '../convert/fd-options.js';6 import {bufferToUint8Array} from './uint-array.js';7 8 // When we use multiple `stdio` values for the same streams, we pass 'pipe' to `child_process.spawn()`.9 // We then emulate the piping done by core Node.js.56 unmodified lines66 return standardStreamIndex;67 }68 };69 69-export const serializeOptionValue = value => {70- if (typeof value === 'string') {71- return `'${value}'`;72- }73-74- return typeof value === 'number' ? `${value}` : 'Stream';75-};76-70 const handleNativeStreamAsync = ({stdioItem, stdioItem: {value, optionName}, fdNumber}) => {71 if (value === 'inherit') {72 return {type: 'nodeStream', value: getStandardStream(fdNumber, value, optionName), optionName};73 }26 unmodified linesadded:lib/stdio/normalize-transform.js+83 added
1+import isPlainObj from 'is-plain-obj';2+import {BINARY_ENCODINGS} from '../arguments/encoding.js';3+import {TRANSFORM_TYPES} from './type.js';4+import {getTransformObjectModes} from './object-mode.js';5+6+// Transforms generators/duplex/TransformStream can have multiple shapes.7+// This normalizes it and applies default values.8+export const normalizeTransforms = (stdioItems, optionName, direction, options) => [9+ ...stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type)),10+ ...getTransforms(stdioItems, optionName, direction, options),11+];12+13+const getTransforms = (stdioItems, optionName, direction, {encoding}) => {14+ const transforms = stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type));15+ const newTransforms = Array.from({length: transforms.length});16+17+ for (const [index, stdioItem] of Object.entries(transforms)) {18+ newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, optionName, direction, encoding});19+ }20+21+ return sortTransforms(newTransforms, direction);22+};23+24+const normalizeTransform = ({stdioItem, stdioItem: {type}, index, newTransforms, optionName, direction, encoding}) => {25+ if (type === 'duplex') {26+ return normalizeDuplex({stdioItem, optionName});27+ }28+29+ if (type === 'webTransform') {30+ return normalizeTransformStream({stdioItem, index, newTransforms, direction});31+ }32+33+ return normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});34+};35+36+const normalizeDuplex = ({37+ stdioItem,38+ stdioItem: {39+ value: {40+ transform,41+ transform: {writableObjectMode, readableObjectMode},42+ objectMode = readableObjectMode,43+ },44+ },45+ optionName,46+}) => {47+ if (objectMode && !readableObjectMode) {48+ throw new TypeError(`The \`${optionName}.objectMode\` option can only be \`true\` if \`new Duplex({objectMode: true})\` is used.`);49+ }50+51+ if (!objectMode && readableObjectMode) {52+ throw new TypeError(`The \`${optionName}.objectMode\` option cannot be \`false\` if \`new Duplex({objectMode: true})\` is used.`);53+ }54+55+ return {56+ ...stdioItem,57+ value: {transform, writableObjectMode, readableObjectMode},58+ };59+};60+61+const normalizeTransformStream = ({stdioItem, stdioItem: {value}, index, newTransforms, direction}) => {62+ const {transform, objectMode} = isPlainObj(value) ? value : {transform: value};63+ const {writableObjectMode, readableObjectMode} = getTransformObjectModes(objectMode, index, newTransforms, direction);64+ return ({65+ ...stdioItem,66+ value: {transform, writableObjectMode, readableObjectMode},67+ });68+};69+70+const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms, direction, encoding}) => {71+ const {72+ transform,73+ final,74+ binary: binaryOption = false,75+ preserveNewlines = false,76+ objectMode,77+ } = isPlainObj(value) ? value : {transform: value};78+ const binary = binaryOption || BINARY_ENCODINGS.has(encoding);79+ const {writableObjectMode, readableObjectMode} = getTransformObjectModes(objectMode, index, newTransforms, direction);80+ return {...stdioItem, value: {transform, final, binary, preserveNewlines, writableObjectMode, readableObjectMode}};81+};82+83+const sortTransforms = (newTransforms, direction) => direction === 'input' ? newTransforms.reverse() : newTransforms;added:lib/stdio/object-mode.js+41 added
1+import {TRANSFORM_TYPES} from './type.js';2+3+/*4+Retrieve the `objectMode`s of a single transform.5+`objectMode` determines the return value's type, i.e. the `readableObjectMode`.6+The chunk argument's type is based on the previous generator's return value, i.e. the `writableObjectMode` is based on the previous `readableObjectMode`.7+The last input's generator is read by `subprocess.stdin` which:8+- should not be in `objectMode` for performance reasons.9+- can only be strings, Buffers and Uint8Arrays.10+Therefore its `readableObjectMode` must be `false`.11+The same applies to the first output's generator's `writableObjectMode`.12+*/13+export const getTransformObjectModes = (objectMode, index, newTransforms, direction) => direction === 'output'14+ ? getOutputObjectModes(objectMode, index, newTransforms)15+ : getInputObjectModes(objectMode, index, newTransforms);16+17+const getOutputObjectModes = (objectMode, index, newTransforms) => {18+ const writableObjectMode = index !== 0 && newTransforms[index - 1].value.readableObjectMode;19+ const readableObjectMode = objectMode ?? writableObjectMode;20+ return {writableObjectMode, readableObjectMode};21+};22+23+const getInputObjectModes = (objectMode, index, newTransforms) => {24+ const writableObjectMode = index === 025+ ? objectMode === true26+ : newTransforms[index - 1].value.readableObjectMode;27+ const readableObjectMode = index !== newTransforms.length - 1 && (objectMode ?? writableObjectMode);28+ return {writableObjectMode, readableObjectMode};29+};30+31+// Retrieve the `objectMode` of a file descriptor, e.g. `stdout` or `stderr`32+export const getFdObjectMode = (stdioItems, direction) => {33+ const lastTransform = stdioItems.findLast(({type}) => TRANSFORM_TYPES.has(type));34+ if (lastTransform === undefined) {35+ return false;36+ }37+38+ return direction === 'input'39+ ? lastTransform.value.writableObjectMode40+ : lastTransform.value.readableObjectMode;41+};added:lib/stdio/output-async.js+71 added
1+import mergeStreams from '@sindresorhus/merge-streams';2+import {isStandardStream} from '../utils.js';3+import {incrementMaxListeners} from '../max-listener.js';4+import {pipeStreams} from './pipeline.js';5+import {TRANSFORM_TYPES} from './type.js';6+7+// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async mode8+// When multiple input streams are used, we merge them to ensure the output stream ends only once each input stream has ended9+export const pipeOutputAsync = (subprocess, fileDescriptors, controller) => {10+ const inputStreamsGroups = {};11+12+ for (const [fdNumber, {stdioItems, direction}] of Object.entries(fileDescriptors)) {13+ for (const {stream} of stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type))) {14+ pipeTransform(subprocess, stream, direction, fdNumber);15+ }16+17+ for (const {stream} of stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type))) {18+ pipeStdioItem({subprocess, stream, direction, fdNumber, inputStreamsGroups, controller});19+ }20+ }21+22+ for (const [fdNumber, inputStreams] of Object.entries(inputStreamsGroups)) {23+ const inputStream = inputStreams.length === 1 ? inputStreams[0] : mergeStreams(inputStreams);24+ pipeStreams(inputStream, subprocess.stdio[fdNumber]);25+ }26+};27+28+// `subprocess.stdin|stdout|stderr|stdio` is directly mutated.29+const pipeTransform = (subprocess, stream, direction, fdNumber) => {30+ if (direction === 'output') {31+ pipeStreams(subprocess.stdio[fdNumber], stream);32+ } else {33+ pipeStreams(stream, subprocess.stdio[fdNumber]);34+ }35+36+ const streamProperty = SUBPROCESS_STREAM_PROPERTIES[fdNumber];37+ if (streamProperty !== undefined) {38+ subprocess[streamProperty] = stream;39+ }40+41+ subprocess.stdio[fdNumber] = stream;42+};43+44+const SUBPROCESS_STREAM_PROPERTIES = ['stdin', 'stdout', 'stderr'];45+46+const pipeStdioItem = ({subprocess, stream, direction, fdNumber, inputStreamsGroups, controller}) => {47+ if (stream === undefined) {48+ return;49+ }50+51+ setStandardStreamMaxListeners(stream, controller);52+53+ if (direction === 'output') {54+ pipeStreams(subprocess.stdio[fdNumber], stream);55+ } else {56+ inputStreamsGroups[fdNumber] = [...(inputStreamsGroups[fdNumber] ?? []), stream];57+ }58+};59+60+// Multiple subprocesses might be piping from/to `process.std*` at the same time.61+// This is not necessarily an error and should not print a `maxListeners` warning.62+const setStandardStreamMaxListeners = (stream, {signal}) => {63+ if (isStandardStream(stream)) {64+ incrementMaxListeners(stream, MAX_LISTENERS_INCREMENT, signal);65+ }66+};67+68+// `source.pipe(destination)` adds at most 1 listener for each event.69+// If `stdin` option is an array, the values might be combined with `merge-streams`.70+// That library also listens for `source` end, which adds 1 more listener.71+const MAX_LISTENERS_INCREMENT = 2;modified:lib/stdio/output-sync.js+5 added-37 removed
1 import {writeFileSync} from 'node:fs';2 import {shouldLogOutput, logLinesSync} from '../verbose/output.js';3 import {getMaxBufferSync} from '../stream/max-buffer.js';4-import {stripNewline} from '../return/output.js';5-import {joinToString, joinToUint8Array, bufferToUint8Array, isUint8Array, concatUint8Arrays} from './uint-array.js';6-import {getGenerators, runGeneratorsSync} from './generator.js';4+import {joinToString, joinToUint8Array, bufferToUint8Array} from './uint-array.js';5+import {runGeneratorsSync} from './transform-run.js';6 import {splitLinesSync} from './split.js';7 import {FILE_TYPES} from './type.js';8 9 // Apply `stdout`/`stderr` options, after spawning, in sync mode15 unmodified lines25 26 const truncatedResult = truncateResult(result, isMaxBuffer, getMaxBufferSync(maxBuffer));27 const uint8ArrayResult = bufferToUint8Array(truncatedResult);28 const {stdioItems, objectMode} = fileDescriptors[fdNumber];30- const generators = getGenerators(stdioItems);31- const chunks = runOutputGeneratorsSync([uint8ArrayResult], generators, encoding, state);29+ const chunks = runOutputGeneratorsSync([uint8ArrayResult], stdioItems, encoding, state);30 const {31 serializedResult,32 finalResult = serializedResult,33 } = serializeChunks({chunks, objectMode, encoding, lines, stripFinalNewline, fdNumber});20 unmodified lines54 const truncateResult = (result, isMaxBuffer, maxBuffer) => isMaxBuffer && result.length > maxBuffer55 ? result.slice(0, maxBuffer)56 : result;57 60-const runOutputGeneratorsSync = (chunks, generators, encoding, state) => {58+const runOutputGeneratorsSync = (chunks, stdioItems, encoding, state) => {59 try {62- return runGeneratorsSync(chunks, generators, encoding);60+ return runGeneratorsSync(chunks, stdioItems, encoding, false);61 } catch (error) {62 state.error = error;63 return chunks;64 }22 unmodified lines87 writeFileSync(path, serializedResult);88 }89 }90 };93-94-export const getAllSync = ([, stdout, stderr], options) => {95- if (!options.all) {96- return;97- }98-99- if (stdout === undefined) {100- return stderr;101- }102-103- if (stderr === undefined) {104- return stdout;105- }106-107- if (Array.isArray(stdout)) {108- return Array.isArray(stderr)109- ? [...stdout, ...stderr]110- : [...stdout, stripNewline(stderr, options, 'all')];111- }112-113- if (Array.isArray(stderr)) {114- return [stripNewline(stdout, options, 'all'), ...stderr];115- }116-117- if (isUint8Array(stdout) && isUint8Array(stderr)) {118- return concatUint8Arrays([stdout, stderr]);119- }120-121- return `${stdout}${stderr}`;122-};added:lib/stdio/transform-async.js+59 added
1+import {callbackify} from 'node:util';2+3+export const pushChunks = callbackify(async (getChunks, state, args, transformStream) => {4+ state.currentIterable = getChunks(...args);5+6+ try {7+ for await (const chunk of state.currentIterable) {8+ transformStream.push(chunk);9+ }10+ } finally {11+ delete state.currentIterable;12+ }13+});14+15+// For each new chunk, apply each `transform()` method16+export const transformChunk = async function * (chunk, generators, index) {17+ if (index === generators.length) {18+ yield chunk;19+ return;20+ }21+22+ const {transform = identityGenerator} = generators[index];23+ for await (const transformedChunk of transform(chunk)) {24+ yield * transformChunk(transformedChunk, generators, index + 1);25+ }26+};27+28+// At the end, apply each `final()` method, followed by the `transform()` method of the next transforms29+export const finalChunks = async function * (generators) {30+ for (const [index, {final}] of Object.entries(generators)) {31+ yield * generatorFinalChunks(final, Number(index), generators);32+ }33+};34+35+const generatorFinalChunks = async function * (final, index, generators) {36+ if (final === undefined) {37+ return;38+ }39+40+ for await (const finalChunk of final()) {41+ yield * transformChunk(finalChunk, generators, index + 1);42+ }43+};44+45+// Cancel any ongoing async generator when the Transform is destroyed, e.g. when the subprocess errors46+export const destroyTransform = callbackify(async ({currentIterable}, error) => {47+ if (currentIterable !== undefined) {48+ await (error ? currentIterable.throw(error) : currentIterable.return());49+ return;50+ }51+52+ if (error) {53+ throw error;54+ }55+});56+57+const identityGenerator = function * (chunk) {58+ yield chunk;59+};added:lib/stdio/transform-run.js+90 added
1+import {Transform, getDefaultHighWaterMark} from 'node:stream';2+import {pushChunks, transformChunk, finalChunks, destroyTransform} from './transform-async.js';3+import {pushChunksSync, transformChunkSync, finalChunksSync, runTransformSync} from './transform-sync.js';4+import {getEncodingTransformGenerator} from './encoding-transform.js';5+import {getSplitLinesGenerator, getAppendNewlineGenerator} from './split.js';6+import {getValidateTransformInput, getValidateTransformReturn} from './validate.js';7+import {isAsyncGenerator} from './type.js';8+9+/*10+Generators can be used to transform/filter standard streams.11+12+Generators have a simple syntax, yet allows all of the following:13+- Sharing `state` between chunks14+- Flushing logic, by using a `final` function15+- Asynchronous logic16+- Emitting multiple chunks from a single source chunk, even if spaced in time, by using multiple `yield`17+- Filtering, by using no `yield`18+19+Therefore, there is no need to allow Node.js or web transform streams.20+21+The `highWaterMark` is kept as the default value, since this is what `subprocess.std*` uses.22+23+Chunks are currently processed serially. We could add a `concurrency` option to parallelize in the future.24+25+Transform an array of generator functions into a `Transform` stream.26+`Duplex.from(generator)` cannot be used because it does not allow setting the `objectMode` and `highWaterMark`.27+*/28+export const generatorToStream = ({29+ value,30+ value: {transform, final, writableObjectMode, readableObjectMode},31+ optionName,32+}, {encoding}) => {33+ const state = {};34+ const generators = addInternalGenerators(value, encoding, optionName);35+36+ const transformAsync = isAsyncGenerator(transform);37+ const finalAsync = isAsyncGenerator(final);38+ const transformMethod = transformAsync39+ ? pushChunks.bind(undefined, transformChunk, state)40+ : pushChunksSync.bind(undefined, transformChunkSync);41+ const finalMethod = transformAsync || finalAsync42+ ? pushChunks.bind(undefined, finalChunks, state)43+ : pushChunksSync.bind(undefined, finalChunksSync);44+ const destroyMethod = transformAsync || finalAsync45+ ? destroyTransform.bind(undefined, state)46+ : undefined;47+48+ const stream = new Transform({49+ writableObjectMode,50+ writableHighWaterMark: getDefaultHighWaterMark(writableObjectMode),51+ readableObjectMode,52+ readableHighWaterMark: getDefaultHighWaterMark(readableObjectMode),53+ transform(chunk, encoding, done) {54+ transformMethod([chunk, generators, 0], this, done);55+ },56+ flush(done) {57+ finalMethod([generators], this, done);58+ },59+ destroy: destroyMethod,60+ });61+ return {stream};62+};63+64+export const runGeneratorsSync = (chunks, stdioItems, encoding, isInput) => {65+ const generators = stdioItems.filter(({type}) => type === 'generator');66+ const reversedGenerators = isInput ? generators.reverse() : generators;67+68+ for (const {value, optionName} of reversedGenerators) {69+ const generators = addInternalGenerators(value, encoding, optionName);70+ chunks = runTransformSync(generators, chunks);71+ }72+73+ return chunks;74+};75+76+const addInternalGenerators = (77+ {transform, final, binary, writableObjectMode, readableObjectMode, preserveNewlines},78+ encoding,79+ optionName,80+) => {81+ const state = {};82+ return [83+ {transform: getValidateTransformInput(writableObjectMode, optionName)},84+ getEncodingTransformGenerator(binary, encoding, writableObjectMode),85+ getSplitLinesGenerator(binary, preserveNewlines, writableObjectMode, state),86+ {transform, final},87+ {transform: getValidateTransformReturn(readableObjectMode, optionName)},88+ getAppendNewlineGenerator({binary, preserveNewlines, readableObjectMode, state}),89+ ].filter(Boolean);90+};added:lib/stdio/transform-sync.js+50 added
1+// Duplicate the code from `transform-async.js` but as synchronous functions2+export const pushChunksSync = (getChunksSync, args, transformStream, done) => {3+ try {4+ for (const chunk of getChunksSync(...args)) {5+ transformStream.push(chunk);6+ }7+8+ done();9+ } catch (error) {10+ done(error);11+ }12+};13+14+// Run synchronous generators with `execaSync()`15+export const runTransformSync = (generators, chunks) => [16+ ...chunks.flatMap(chunk => [...transformChunkSync(chunk, generators, 0)]),17+ ...finalChunksSync(generators),18+];19+20+export const transformChunkSync = function * (chunk, generators, index) {21+ if (index === generators.length) {22+ yield chunk;23+ return;24+ }25+26+ const {transform = identityGenerator} = generators[index];27+ for (const transformedChunk of transform(chunk)) {28+ yield * transformChunkSync(transformedChunk, generators, index + 1);29+ }30+};31+32+export const finalChunksSync = function * (generators) {33+ for (const [index, {final}] of Object.entries(generators)) {34+ yield * generatorFinalChunksSync(final, Number(index), generators);35+ }36+};37+38+const generatorFinalChunksSync = function * (final, index, generators) {39+ if (final === undefined) {40+ return;41+ }42+43+ for (const finalChunk of final()) {44+ yield * transformChunkSync(finalChunk, generators, index + 1);45+ }46+};47+48+const identityGenerator = function * (chunk) {49+ yield chunk;50+};deleted:lib/stdio/transform.js-137 removed
1-import {Transform, getDefaultHighWaterMark} from 'node:stream';2-import {callbackify} from 'node:util';3-4-// Transform an array of generator functions into a `Transform` stream.5-// `Duplex.from(generator)` cannot be used because it does not allow setting the `objectMode` and `highWaterMark`.6-export const generatorsToTransform = (generators, {transformAsync, finalAsync, writableObjectMode, readableObjectMode}) => {7- const state = {};8- const transformMethod = transformAsync9- ? pushChunks.bind(undefined, transformChunk, state)10- : pushChunksSync.bind(undefined, transformChunkSync);11- const finalMethod = transformAsync || finalAsync12- ? pushChunks.bind(undefined, finalChunks, state)13- : pushChunksSync.bind(undefined, finalChunksSync);14- const destroyMethod = transformAsync || finalAsync15- ? destroyTransform.bind(undefined, state)16- : undefined;17-18- return new Transform({19- writableObjectMode,20- writableHighWaterMark: getDefaultHighWaterMark(writableObjectMode),21- readableObjectMode,22- readableHighWaterMark: getDefaultHighWaterMark(readableObjectMode),23- transform(chunk, encoding, done) {24- transformMethod([chunk, generators, 0], this, done);25- },26- flush(done) {27- finalMethod([generators], this, done);28- },29- destroy: destroyMethod,30- });31-};32-33-const pushChunks = callbackify(async (getChunks, state, args, transformStream) => {34- state.currentIterable = getChunks(...args);35-36- try {37- for await (const chunk of state.currentIterable) {38- transformStream.push(chunk);39- }40- } finally {41- delete state.currentIterable;42- }43-});44-45-// For each new chunk, apply each `transform()` method46-const transformChunk = async function * (chunk, generators, index) {47- if (index === generators.length) {48- yield chunk;49- return;50- }51-52- const {transform = identityGenerator} = generators[index];53- for await (const transformedChunk of transform(chunk)) {54- yield * transformChunk(transformedChunk, generators, index + 1);55- }56-};57-58-// At the end, apply each `final()` method, followed by the `transform()` method of the next transforms59-const finalChunks = async function * (generators) {60- for (const [index, {final}] of Object.entries(generators)) {61- yield * generatorFinalChunks(final, Number(index), generators);62- }63-};64-65-const generatorFinalChunks = async function * (final, index, generators) {66- if (final === undefined) {67- return;68- }69-70- for await (const finalChunk of final()) {71- yield * transformChunk(finalChunk, generators, index + 1);72- }73-};74-75-// Cancel any ongoing async generator when the Transform is destroyed, e.g. when the subprocess errors76-const destroyTransform = callbackify(async ({currentIterable}, error) => {77- if (currentIterable !== undefined) {78- await (error ? currentIterable.throw(error) : currentIterable.return());79- return;80- }81-82- if (error) {83- throw error;84- }85-});86-87-// Duplicate the code above but as synchronous functions.88-// This is a performance optimization when the `transform`/`flush` function is synchronous, which is the common case.89-const pushChunksSync = (getChunksSync, args, transformStream, done) => {90- try {91- for (const chunk of getChunksSync(...args)) {92- transformStream.push(chunk);93- }94-95- done();96- } catch (error) {97- done(error);98- }99-};100-101-// Run synchronous generators with `execaSync()`102-export const runTransformSync = (generators, chunks) => [103- ...chunks.flatMap(chunk => [...transformChunkSync(chunk, generators, 0)]),104- ...finalChunksSync(generators),105-];106-107-export const transformChunkSync = function * (chunk, generators, index) {108- if (index === generators.length) {109- yield chunk;110- return;111- }112-113- const {transform = identityGenerator} = generators[index];114- for (const transformedChunk of transform(chunk)) {115- yield * transformChunkSync(transformedChunk, generators, index + 1);116- }117-};118-119-export const finalChunksSync = function * (generators) {120- for (const [index, {final}] of Object.entries(generators)) {121- yield * generatorFinalChunksSync(final, Number(index), generators);122- }123-};124-125-const generatorFinalChunksSync = function * (final, index, generators) {126- if (final === undefined) {127- return;128- }129-130- for (const finalChunk of final()) {131- yield * transformChunkSync(finalChunk, generators, index + 1);132- }133-};134-135-const identityGenerator = function * (chunk) {136- yield chunk;137-};modified:lib/stdio/type.js+1 added
140 unmodified lines141 const isAsyncIterableObject = value => isObject(value) && typeof value[Symbol.asyncIterator] === 'function';142 const isIterableObject = value => isObject(value) && typeof value[Symbol.iterator] === 'function';143 const isObject = value => typeof value === 'object' && value !== null;144 145+export const TRANSFORM_TYPES = new Set(['generator', 'asyncGenerator', 'duplex', 'webTransform']);146 export const FILE_TYPES = new Set(['fileUrl', 'filePath', 'fileNumber']);147 148 // Convert types to human-friendly strings for error messages149 export const TYPE_TO_MESSAGE = {14 unmodified linesadded:lib/stream/contents.js+63 added
1+import {setImmediate} from 'node:timers/promises';2+import getStream, {getStreamAsArrayBuffer, getStreamAsArray} from 'get-stream';3+import {isArrayBuffer} from '../stdio/uint-array.js';4+import {iterateForResult} from '../convert/loop.js';5+import {shouldLogOutput, logLines} from '../verbose/output.js';6+import {getStripFinalNewline} from '../return/strip-newline.js';7+import {handleMaxBuffer} from './max-buffer.js';8+9+export const getStreamOutput = async ({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo: {fileDescriptors}}) => {10+ if (shouldLogOutput({stdioItems: fileDescriptors[fdNumber]?.stdioItems, encoding, verboseInfo, fdNumber})) {11+ const linesIterable = iterateForResult({stream, onStreamEnd, lines: true, encoding, stripFinalNewline: true, allMixed});12+ logLines(linesIterable, stream, verboseInfo);13+ }14+15+ if (!buffer) {16+ await resumeStream(stream);17+ return;18+ }19+20+ const stripFinalNewlineValue = getStripFinalNewline(stripFinalNewline, fdNumber);21+ const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline: stripFinalNewlineValue, allMixed});22+ return getStreamContents({stream, iterable, fdNumber, encoding, maxBuffer, lines});23+};24+25+// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away26+// See https://github.com/sindresorhus/execa/issues/730 and https://github.com/sindresorhus/execa/pull/729#discussion_r146549631027+const resumeStream = async stream => {28+ await setImmediate();29+ if (stream.readableFlowing === null) {30+ stream.resume();31+ }32+};33+34+const getStreamContents = async ({stream, stream: {readableObjectMode}, iterable, fdNumber, encoding, maxBuffer, lines}) => {35+ try {36+ if (readableObjectMode || lines) {37+ return await getStreamAsArray(iterable, {maxBuffer});38+ }39+40+ if (encoding === 'buffer') {41+ return new Uint8Array(await getStreamAsArrayBuffer(iterable, {maxBuffer}));42+ }43+44+ return await getStream(iterable, {maxBuffer});45+ } catch (error) {46+ return handleBufferedData(handleMaxBuffer({error, stream, readableObjectMode, lines, encoding, fdNumber}));47+ }48+};49+50+// On failure, `result.stdout|stderr|all` should contain the currently buffered stream51+// They are automatically closed and flushed by Node.js when the subprocess exits52+// When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve53+export const getBufferedData = async streamPromise => {54+ try {55+ return await streamPromise;56+ } catch (error) {57+ return handleBufferedData(error);58+ }59+};60+61+const handleBufferedData = ({bufferedData}) => isArrayBuffer(bufferedData)62+ ? new Uint8Array(bufferedData)63+ : bufferedData;added:lib/stream/exit-async.js+45 added
1+import {once} from 'node:events';2+import {DiscardedError} from '../return/cause.js';3+4+// If `error` is emitted before `spawn`, `exit` will never be emitted.5+// However, `error` might be emitted after `spawn`, e.g. with the `cancelSignal` option.6+// In that case, `exit` will still be emitted.7+// Since the `exit` event contains the signal name, we want to make sure we are listening for it.8+// This function also takes into account the following unlikely cases:9+// - `exit` being emitted in the same microtask as `spawn`10+// - `error` being emitted multiple times11+export const waitForExit = async subprocess => {12+ const [spawnPayload, exitPayload] = await Promise.allSettled([13+ once(subprocess, 'spawn'),14+ once(subprocess, 'exit'),15+ ]);16+17+ if (spawnPayload.status === 'rejected') {18+ return [];19+ }20+21+ return exitPayload.status === 'rejected'22+ ? waitForSubprocessExit(subprocess)23+ : exitPayload.value;24+};25+26+const waitForSubprocessExit = async subprocess => {27+ try {28+ return await once(subprocess, 'exit');29+ } catch {30+ return waitForSubprocessExit(subprocess);31+ }32+};33+34+export const waitForSuccessfulExit = async exitPromise => {35+ const [exitCode, signal] = await exitPromise;36+37+ if (!isSubprocessErrorExit(exitCode, signal) && isFailedExit(exitCode, signal)) {38+ throw new DiscardedError();39+ }40+41+ return [exitCode, signal];42+};43+44+const isSubprocessErrorExit = (exitCode, signal) => exitCode === undefined && signal === undefined;45+export const isFailedExit = (exitCode, signal) => exitCode !== 0 || signal !== null;added:lib/stream/exit-sync.js+18 added
1+import {DiscardedError} from '../return/cause.js';2+import {isMaxBufferSync} from './max-buffer.js';3+import {isFailedExit} from './exit-async.js';4+5+export const getExitResultSync = ({error, status: exitCode, signal, output}, {maxBuffer}) => {6+ const resultError = getResultError(error, exitCode, signal);7+ const timedOut = resultError?.code === 'ETIMEDOUT';8+ const isMaxBuffer = isMaxBufferSync(resultError, output, maxBuffer);9+ return {resultError, exitCode, signal, timedOut, isMaxBuffer};10+};11+12+const getResultError = (error, exitCode, signal) => {13+ if (error !== undefined) {14+ return error;15+ }16+17+ return isFailedExit(exitCode, signal) ? new DiscardedError() : undefined;18+};deleted:lib/stream/exit.js-31 removed
1-import {once} from 'node:events';2-3-// If `error` is emitted before `spawn`, `exit` will never be emitted.4-// However, `error` might be emitted after `spawn`, e.g. with the `cancelSignal` option.5-// In that case, `exit` will still be emitted.6-// Since the `exit` event contains the signal name, we want to make sure we are listening for it.7-// This function also takes into account the following unlikely cases:8-// - `exit` being emitted in the same microtask as `spawn`9-// - `error` being emitted multiple times10-export const waitForExit = async subprocess => {11- const [spawnPayload, exitPayload] = await Promise.allSettled([12- once(subprocess, 'spawn'),13- once(subprocess, 'exit'),14- ]);15-16- if (spawnPayload.status === 'rejected') {17- return [];18- }19-20- return exitPayload.status === 'rejected'21- ? waitForSubprocessExit(subprocess)22- : exitPayload.value;23-};24-25-const waitForSubprocessExit = async subprocess => {26- try {27- return await once(subprocess, 'exit');28- } catch {29- return waitForSubprocessExit(subprocess);30- }31-};modified:lib/stream/resolve.js+4 added-8 removed
1 import {once} from 'node:events';2 import {isStream as isNodeStream} from 'is-stream';3-import {waitForSuccessfulExit} from '../exit/code.js';3 import {errorSignal} from '../exit/kill.js';4 import {throwOnTimeout} from '../exit/timeout.js';5 import {isStandardStream} from '../utils.js';7-import {TRANSFORM_TYPES} from '../stdio/generator.js';6+import {TRANSFORM_TYPES} from '../stdio/type.js';7 import {waitForAllStream} from './all.js';9-import {waitForSubprocessStream, getBufferedData} from './subprocess.js';10-import {waitForExit} from './exit.js';8+import {waitForSubprocessStreams} from './subprocess.js';9+import {getBufferedData} from './contents.js';10+import {waitForExit, waitForSuccessfulExit} from './exit-async.js';11 import {waitForStream} from './wait.js';12 13 // Retrieve result of subprocess: exit code, signal, error, streams (stdout/stderr/all)14 export const getSubprocessResult = async ({38 unmodified lines53 ]);54 }55 };56 57-// Read the contents of `subprocess.std*` and|or wait for its completion58-const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo}) =>59- subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, fdNumber, encoding, buffer: buffer[fdNumber], maxBuffer: maxBuffer[fdNumber], lines: lines[fdNumber], allMixed: false, stripFinalNewline, verboseInfo, streamInfo}));60-57 // Transforms replace `subprocess.std*`, which means they are not exposed to users.58 // However, we still want to wait for their completion.59 const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>60 originalStreams.map((stream, fdNumber) => stream === subprocess.stdio[fdNumber]22 unmodified linesmodified:lib/stream/subprocess.js+21 added-69 removed
1-import {setImmediate} from 'node:timers/promises';2-import getStream, {getStreamAsArrayBuffer, getStreamAsArray} from 'get-stream';3-import {iterateForResult} from '../convert/loop.js';4-import {isArrayBuffer} from '../stdio/uint-array.js';5-import {shouldLogOutput, logLines} from '../verbose/output.js';6-import {getStripFinalNewline} from '../return/output.js';7-import {handleMaxBuffer} from './max-buffer.js';1 import {waitForStream, isInputFileDescriptor} from './wait.js';2+import {getStreamOutput} from './contents.js';3 4+// Read the contents of `subprocess.std*` and|or wait for its completion5+export const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo}) => subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({6+ stream,7+ fdNumber,8+ encoding,9+ buffer: buffer[fdNumber],10+ maxBuffer: maxBuffer[fdNumber],11+ lines: lines[fdNumber],12+ allMixed: false,13+ stripFinalNewline,14+ verboseInfo,15+ streamInfo,16+}));17+18 export const waitForSubprocessStream = async ({stream, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}) => {19 if (!stream) {20 return;21 }22 23 const onStreamEnd = waitForStream(stream, fdNumber, streamInfo);24+ if (isInputFileDescriptor(streamInfo, fdNumber)) {25+ await onStreamEnd;26+ return;27+ }28+29 const [output] = await Promise.all([17- waitForDefinedStream({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}),30+ getStreamOutput({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}),31 onStreamEnd,32 ]);33 return output;34 };22-23-const waitForDefinedStream = async ({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo, streamInfo: {fileDescriptors}}) => {24- if (isInputFileDescriptor(streamInfo, fdNumber)) {25- return;26- }27-28- if (shouldLogOutput({stdioItems: fileDescriptors[fdNumber]?.stdioItems, encoding, verboseInfo, fdNumber})) {29- const linesIterable = iterateForResult({stream, onStreamEnd, lines: true, encoding, stripFinalNewline: true, allMixed});30- logLines(linesIterable, stream, verboseInfo);31- }32-33- if (!buffer) {34- await resumeStream(stream);35- return;36- }37-38- const stripFinalNewlineValue = getStripFinalNewline(stripFinalNewline, fdNumber);39- const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline: stripFinalNewlineValue, allMixed});40- return getStreamContents({stream, iterable, fdNumber, encoding, maxBuffer, lines});41-};42-43-// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away44-// See https://github.com/sindresorhus/execa/issues/730 and https://github.com/sindresorhus/execa/pull/729#discussion_r146549631045-const resumeStream = async stream => {46- await setImmediate();47- if (stream.readableFlowing === null) {48- stream.resume();49- }50-};51-52-const getStreamContents = async ({stream, stream: {readableObjectMode}, iterable, fdNumber, encoding, maxBuffer, lines}) => {53- try {54- if (readableObjectMode || lines) {55- return await getStreamAsArray(iterable, {maxBuffer});56- }57-58- if (encoding === 'buffer') {59- return new Uint8Array(await getStreamAsArrayBuffer(iterable, {maxBuffer}));60- }61-62- return await getStream(iterable, {maxBuffer});63- } catch (error) {64- return handleBufferedData(handleMaxBuffer({error, stream, readableObjectMode, lines, encoding, fdNumber}));65- }66-};67-68-// On failure, `result.stdout|stderr|all` should contain the currently buffered stream69-// They are automatically closed and flushed by Node.js when the subprocess exits70-// When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve71-export const getBufferedData = async streamPromise => {72- try {73- return await streamPromise;74- } catch (error) {75- return handleBufferedData(error);76- }77-};78-79-const handleBufferedData = ({bufferedData}) => isArrayBuffer(bufferedData)80- ? new Uint8Array(bufferedData)81- : bufferedData;82-modified:lib/verbose/output.js+1 added-1 removed
1 import {inspect} from 'node:util';2 import {escapeLines} from '../arguments/escape.js';3 import {BINARY_ENCODINGS} from '../arguments/encoding.js';4-import {TRANSFORM_TYPES} from '../stdio/generator.js';4+import {TRANSFORM_TYPES} from '../stdio/type.js';5 import {verboseLog} from './log.js';6 7 // `ignore` opts-out of `verbose` for a specific stream.8 // `ipc` cannot use piping.51 unmodified linesmodified:lib/async.js+7 added-4 removed
1 import {setMaxListeners} from 'node:events';2 import {spawn} from 'node:child_process';3 import {MaxBufferError} from 'get-stream';4-import {handleCommand, handleOptions} from './arguments/options.js';4+import {handleCommand} from './arguments/command.js';5+import {handleOptions} from './arguments/options.js';6 import {makeError, makeSuccessResult} from './return/error.js';6-import {stripNewline, handleResult} from './return/output.js';7+import {stripNewline} from './return/strip-newline.js';8+import {handleResult} from './return/reject.js';9 import {handleEarlyError} from './return/early-error.js';8-import {handleInputAsync, pipeOutputAsync} from './stdio/async.js';10+import {handleInputAsync} from './stdio/async.js';11+import {pipeOutputAsync} from './stdio/output-async.js';12 import {subprocessKill} from './exit/kill.js';13 import {cleanupOnExit} from './exit/cleanup.js';14 import {pipeToSubprocess} from './pipe/setup.js';12-import {SUBPROCESS_OPTIONS} from './pipe/validate.js';15+import {SUBPROCESS_OPTIONS} from './convert/fd-options.js';16 import {logEarlyResult} from './verbose/complete.js';17 import {makeAllStream} from './stream/all.js';18 import {addConvertedStreams} from './convert/add.js';19 import {getSubprocessResult} from './stream/resolve.js';91 unmodified linesadded:lib/max-listener.js+13 added
1+import {addAbortListener} from 'node:events';2+3+export const incrementMaxListeners = (eventEmitter, maxListenersIncrement, signal) => {4+ const maxListeners = eventEmitter.getMaxListeners();5+ if (maxListeners === 0 || maxListeners === Number.POSITIVE_INFINITY) {6+ return;7+ }8+9+ eventEmitter.setMaxListeners(maxListeners + maxListenersIncrement);10+ addAbortListener(signal, () => {11+ eventEmitter.setMaxListeners(eventEmitter.getMaxListeners() - maxListenersIncrement);12+ });13+};modified:lib/sync.js+8 added-5 removed
1 import {spawnSync} from 'node:child_process';2-import {handleCommand, handleOptions} from './arguments/options.js';2+import {handleCommand} from './arguments/command.js';3+import {handleOptions} from './arguments/options.js';4 import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';4-import {stripNewline, handleResult} from './return/output.js';5+import {stripNewline} from './return/strip-newline.js';6+import {handleResult} from './return/reject.js';7 import {handleInputSync} from './stdio/sync.js';8 import {addInputOptionsSync} from './stdio/input-sync.js';7-import {transformOutputSync, getAllSync} from './stdio/output-sync.js';9+import {transformOutputSync} from './stdio/output-sync.js';10+import {getAllSync} from './stdio/all-sync.js';11 import {logEarlyResult} from './verbose/complete.js';9-import {getSyncExitResult} from './exit/code.js';12+import {getExitResultSync} from './stream/exit-sync.js';13 import {getMaxBufferSync} from './stream/max-buffer.js';14 15 export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {16 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArgs, rawOptions);41 unmodified lines58 if (syncResult.failed) {59 return syncResult;60 }61 59- const {resultError, exitCode, signal, timedOut, isMaxBuffer} = getSyncExitResult(syncResult, options);62+ const {resultError, exitCode, signal, timedOut, isMaxBuffer} = getExitResultSync(syncResult, options);63 const {output, error = resultError} = transformOutputSync({fileDescriptors, syncResult, options, isMaxBuffer, verboseInfo});64 const stdio = output.map((stdioOutput, fdNumber) => stripNewline(stdioOutput, options, fdNumber));65 const all = stripNewline(getAllSync(output, options), options, 'all');66 return getSyncResult({error, exitCode, signal, timedOut, isMaxBuffer, stdio, all, options, command, escapedCommand, startTime});31 unmodified linesmodified:lib/utils.js-16 removed
1-import {ChildProcess} from 'node:child_process';2-import {addAbortListener} from 'node:events';1 import process from 'node:process';2 3 export const isStandardStream = stream => STANDARD_STREAMS.includes(stream);4 export const STANDARD_STREAMS = [process.stdin, process.stdout, process.stderr];5 export const STANDARD_STREAMS_ALIASES = ['stdin', 'stdout', 'stderr'];6 export const getStreamName = fdNumber => STANDARD_STREAMS_ALIASES[fdNumber] ?? `stdio[${fdNumber}]`;9-10-export const incrementMaxListeners = (eventEmitter, maxListenersIncrement, signal) => {11- const maxListeners = eventEmitter.getMaxListeners();12- if (maxListeners === 0 || maxListeners === Number.POSITIVE_INFINITY) {13- return;14- }15-16- eventEmitter.setMaxListeners(maxListeners + maxListenersIncrement);17- addAbortListener(signal, () => {18- eventEmitter.setMaxListeners(eventEmitter.getMaxListeners() - maxListenersIncrement);19- });20-};21-22-export const isSubprocess = value => value instanceof ChildProcess;added:test/arguments/create-bind.js+104 added
1+import {join} from 'node:path';2+import test from 'ava';3+import {execa, execaSync, execaNode, $} from '../../index.js';4+import {foobarString, foobarUppercase} from '../helpers/input.js';5+import {uppercaseGenerator} from '../helpers/generator.js';6+import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';7+8+setFixtureDir();9+10+const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');11+const PRINT_ENV_PATH = join(FIXTURES_DIR, 'environment.js');12+13+const testBindOptions = async (t, execaMethod) => {14+ const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);15+ t.is(stdout, `${foobarString}\n`);16+};17+18+test('execa() can bind options', testBindOptions, execa);19+test('execaNode() can bind options', testBindOptions, execaNode);20+test('$ can bind options', testBindOptions, $);21+22+const testBindOptionsSync = (t, execaMethod) => {23+ const {stdout} = execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);24+ t.is(stdout, `${foobarString}\n`);25+};26+27+test('execaSync() can bind options', testBindOptionsSync, execaSync);28+test('$.sync can bind options', testBindOptionsSync, $.sync);29+30+const testBindPriority = async (t, execaMethod) => {31+ const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: true});32+ t.is(stdout, foobarString);33+};34+35+test('execa() bound options have lower priority', testBindPriority, execa);36+test('execaSync() bound options have lower priority', testBindPriority, execaSync);37+test('execaNode() bound options have lower priority', testBindPriority, execaNode);38+test('$ bound options have lower priority', testBindPriority, $);39+test('$.sync bound options have lower priority', testBindPriority, $.sync);40+41+const testBindUndefined = async (t, execaMethod) => {42+ const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: undefined});43+ t.is(stdout, foobarString);44+};45+46+test('execa() undefined options use default value', testBindUndefined, execa);47+test('execaSync() undefined options use default value', testBindUndefined, execaSync);48+test('execaNode() undefined options use default value', testBindUndefined, execaNode);49+test('$ undefined options use default value', testBindUndefined, $);50+test('$.sync undefined options use default value', testBindUndefined, $.sync);51+52+const testMergeEnv = async (t, execaMethod) => {53+ const {stdout} = await execaMethod({env: {FOO: 'foo'}})(PRINT_ENV_PATH, {env: {BAR: 'bar'}});54+ t.is(stdout, 'foo\nbar');55+};56+57+test('execa() bound options are merged', testMergeEnv, execa);58+test('execaSync() bound options are merged', testMergeEnv, execaSync);59+test('execaNode() bound options are merged', testMergeEnv, execaNode);60+test('$ bound options are merged', testMergeEnv, $);61+test('$.sync bound options are merged', testMergeEnv, $.sync);62+63+const testMergeMultiple = async (t, execaMethod) => {64+ const {stdout} = await execaMethod({env: {FOO: 'baz'}})({env: {BAR: 'bar'}})(PRINT_ENV_PATH, {env: {FOO: 'foo'}});65+ t.is(stdout, 'foo\nbar');66+};67+68+test('execa() bound options are merged multiple times', testMergeMultiple, execa);69+test('execaSync() bound options are merged multiple times', testMergeMultiple, execaSync);70+test('execaNode() bound options are merged multiple times', testMergeMultiple, execaNode);71+test('$ bound options are merged multiple times', testMergeMultiple, $);72+test('$.sync bound options are merged multiple times', testMergeMultiple, $.sync);73+74+const testMergeFdSpecific = async (t, execaMethod) => {75+ const {isMaxBuffer, shortMessage} = await t.throwsAsync(execaMethod({maxBuffer: {stdout: 1}})(NOOP_PATH, [foobarString], {maxBuffer: {stderr: 100}}));76+ t.true(isMaxBuffer);77+ t.true(shortMessage.includes('Command\'s stdout was larger than 1'));78+};79+80+test('execa() bound options merge fd-specific ones', testMergeFdSpecific, execa);81+test('execaNode() bound options merge fd-specific ones', testMergeFdSpecific, execaNode);82+test('$ bound options merge fd-specific ones', testMergeFdSpecific, $);83+84+const testMergeEnvUndefined = async (t, execaMethod) => {85+ const {stdout} = await execaMethod({env: {FOO: 'foo'}})(PRINT_ENV_PATH, {env: {BAR: undefined}});86+ t.is(stdout, 'foo\nundefined');87+};88+89+test('execa() bound options are merged even if undefined', testMergeEnvUndefined, execa);90+test('execaSync() bound options are merged even if undefined', testMergeEnvUndefined, execaSync);91+test('execaNode() bound options are merged even if undefined', testMergeEnvUndefined, execaNode);92+test('$ bound options are merged even if undefined', testMergeEnvUndefined, $);93+test('$.sync bound options are merged even if undefined', testMergeEnvUndefined, $.sync);94+95+const testMergeSpecific = async (t, execaMethod) => {96+ const {stdout} = await execaMethod({stdout: {transform: uppercaseGenerator().transform, objectMode: true}})(NOOP_PATH, {stdout: {transform: uppercaseGenerator().transform}});97+ t.is(stdout, foobarUppercase);98+};99+100+test('execa() bound options only merge specific ones', testMergeSpecific, execa);101+test('execaSync() bound options only merge specific ones', testMergeSpecific, execaSync);102+test('execaNode() bound options only merge specific ones', testMergeSpecific, execaNode);103+test('$ bound options only merge specific ones', testMergeSpecific, $);104+test('$.sync bound options only merge specific ones', testMergeSpecific, $.sync);added:test/arguments/create-main.js+58 added
1+import {join} from 'node:path';2+import test from 'ava';3+import {execa, execaSync, execaNode, $} from '../../index.js';4+import {foobarString, foobarArray} from '../helpers/input.js';5+import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';6+7+setFixtureDir();8+9+const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');10+11+const testTemplate = async (t, execaMethod) => {12+ const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;13+ t.is(stdout, foobarString);14+};15+16+test('execa() can use template strings', testTemplate, execa);17+test('execaNode() can use template strings', testTemplate, execaNode);18+test('$ can use template strings', testTemplate, $);19+20+const testTemplateSync = (t, execaMethod) => {21+ const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`;22+ t.is(stdout, foobarString);23+};24+25+test('execaSync() can use template strings', testTemplateSync, execaSync);26+test('$.sync can use template strings', testTemplateSync, $.sync);27+28+const testTemplateOptions = async (t, execaMethod) => {29+ const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;30+ t.is(stdout, `${foobarString}\n`);31+};32+33+test('execa() can use template strings with options', testTemplateOptions, execa);34+test('execaNode() can use template strings with options', testTemplateOptions, execaNode);35+test('$ can use template strings with options', testTemplateOptions, $);36+37+const testTemplateOptionsSync = (t, execaMethod) => {38+ const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;39+ t.is(stdout, `${foobarString}\n`);40+};41+42+test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);43+test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);44+45+const testSpacedCommand = async (t, args, execaMethod) => {46+ const {stdout} = await execaMethod('command with space.js', args);47+ const expectedStdout = args === undefined ? '' : args.join('\n');48+ t.is(stdout, expectedStdout);49+};50+51+test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);52+test('allow commands with spaces and array arguments', testSpacedCommand, foobarArray, execa);53+test('allow commands with spaces and no array arguments, execaSync', testSpacedCommand, undefined, execaSync);54+test('allow commands with spaces and array arguments, execaSync', testSpacedCommand, foobarArray, execaSync);55+test('allow commands with spaces and no array arguments, $', testSpacedCommand, undefined, $);56+test('allow commands with spaces and array arguments, $', testSpacedCommand, foobarArray, $);57+test('allow commands with spaces and no array arguments, $.sync', testSpacedCommand, undefined, $.sync);58+test('allow commands with spaces and array arguments, $.sync', testSpacedCommand, foobarArray, $.sync);deleted:test/arguments/create.js-152 removed
1-import {join} from 'node:path';2-import test from 'ava';3-import {execa, execaSync, execaNode, $} from '../../index.js';4-import {foobarString, foobarArray, foobarUppercase} from '../helpers/input.js';5-import {uppercaseGenerator} from '../helpers/generator.js';6-import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';7-8-setFixtureDir();9-const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');10-const PRINT_ENV_PATH = join(FIXTURES_DIR, 'environment.js');11-12-const testTemplate = async (t, execaMethod) => {13- const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;14- t.is(stdout, foobarString);15-};16-17-test('execa() can use template strings', testTemplate, execa);18-test('execaNode() can use template strings', testTemplate, execaNode);19-test('$ can use template strings', testTemplate, $);20-21-const testTemplateSync = (t, execaMethod) => {22- const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`;23- t.is(stdout, foobarString);24-};25-26-test('execaSync() can use template strings', testTemplateSync, execaSync);27-test('$.sync can use template strings', testTemplateSync, $.sync);28-29-const testTemplateOptions = async (t, execaMethod) => {30- const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;31- t.is(stdout, `${foobarString}\n`);32-};33-34-test('execa() can use template strings with options', testTemplateOptions, execa);35-test('execaNode() can use template strings with options', testTemplateOptions, execaNode);36-test('$ can use template strings with options', testTemplateOptions, $);37-38-const testTemplateOptionsSync = (t, execaMethod) => {39- const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;40- t.is(stdout, `${foobarString}\n`);41-};42-43-test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);44-test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);45-46-const testBindOptions = async (t, execaMethod) => {47- const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);48- t.is(stdout, `${foobarString}\n`);49-};50-51-test('execa() can bind options', testBindOptions, execa);52-test('execaNode() can bind options', testBindOptions, execaNode);53-test('$ can bind options', testBindOptions, $);54-55-const testBindOptionsSync = (t, execaMethod) => {56- const {stdout} = execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);57- t.is(stdout, `${foobarString}\n`);58-};59-60-test('execaSync() can bind options', testBindOptionsSync, execaSync);61-test('$.sync can bind options', testBindOptionsSync, $.sync);62-63-const testBindPriority = async (t, execaMethod) => {64- const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: true});65- t.is(stdout, foobarString);66-};67-68-test('execa() bound options have lower priority', testBindPriority, execa);69-test('execaSync() bound options have lower priority', testBindPriority, execaSync);70-test('execaNode() bound options have lower priority', testBindPriority, execaNode);71-test('$ bound options have lower priority', testBindPriority, $);72-test('$.sync bound options have lower priority', testBindPriority, $.sync);73-74-const testBindUndefined = async (t, execaMethod) => {75- const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: undefined});76- t.is(stdout, foobarString);77-};78-79-test('execa() undefined options use default value', testBindUndefined, execa);80-test('execaSync() undefined options use default value', testBindUndefined, execaSync);81-test('execaNode() undefined options use default value', testBindUndefined, execaNode);82-test('$ undefined options use default value', testBindUndefined, $);83-test('$.sync undefined options use default value', testBindUndefined, $.sync);84-85-const testMergeEnv = async (t, execaMethod) => {86- const {stdout} = await execaMethod({env: {FOO: 'foo'}})(PRINT_ENV_PATH, {env: {BAR: 'bar'}});87- t.is(stdout, 'foo\nbar');88-};89-90-test('execa() bound options are merged', testMergeEnv, execa);91-test('execaSync() bound options are merged', testMergeEnv, execaSync);92-test('execaNode() bound options are merged', testMergeEnv, execaNode);93-test('$ bound options are merged', testMergeEnv, $);94-test('$.sync bound options are merged', testMergeEnv, $.sync);95-96-const testMergeMultiple = async (t, execaMethod) => {97- const {stdout} = await execaMethod({env: {FOO: 'baz'}})({env: {BAR: 'bar'}})(PRINT_ENV_PATH, {env: {FOO: 'foo'}});98- t.is(stdout, 'foo\nbar');99-};100-101-test('execa() bound options are merged multiple times', testMergeMultiple, execa);102-test('execaSync() bound options are merged multiple times', testMergeMultiple, execaSync);103-test('execaNode() bound options are merged multiple times', testMergeMultiple, execaNode);104-test('$ bound options are merged multiple times', testMergeMultiple, $);105-test('$.sync bound options are merged multiple times', testMergeMultiple, $.sync);106-107-const testMergeFdSpecific = async (t, execaMethod) => {108- const {isMaxBuffer, shortMessage} = await t.throwsAsync(execaMethod({maxBuffer: {stdout: 1}})(NOOP_PATH, [foobarString], {maxBuffer: {stderr: 100}}));109- t.true(isMaxBuffer);110- t.true(shortMessage.includes('Command\'s stdout was larger than 1'));111-};112-113-test('execa() bound options merge fd-specific ones', testMergeFdSpecific, execa);114-test('execaNode() bound options merge fd-specific ones', testMergeFdSpecific, execaNode);115-test('$ bound options merge fd-specific ones', testMergeFdSpecific, $);116-117-const testMergeEnvUndefined = async (t, execaMethod) => {118- const {stdout} = await execaMethod({env: {FOO: 'foo'}})(PRINT_ENV_PATH, {env: {BAR: undefined}});119- t.is(stdout, 'foo\nundefined');120-};121-122-test('execa() bound options are merged even if undefined', testMergeEnvUndefined, execa);123-test('execaSync() bound options are merged even if undefined', testMergeEnvUndefined, execaSync);124-test('execaNode() bound options are merged even if undefined', testMergeEnvUndefined, execaNode);125-test('$ bound options are merged even if undefined', testMergeEnvUndefined, $);126-test('$.sync bound options are merged even if undefined', testMergeEnvUndefined, $.sync);127-128-const testMergeSpecific = async (t, execaMethod) => {129- const {stdout} = await execaMethod({stdout: {transform: uppercaseGenerator().transform, objectMode: true}})(NOOP_PATH, {stdout: {transform: uppercaseGenerator().transform}});130- t.is(stdout, foobarUppercase);131-};132-133-test('execa() bound options only merge specific ones', testMergeSpecific, execa);134-test('execaSync() bound options only merge specific ones', testMergeSpecific, execaSync);135-test('execaNode() bound options only merge specific ones', testMergeSpecific, execaNode);136-test('$ bound options only merge specific ones', testMergeSpecific, $);137-test('$.sync bound options only merge specific ones', testMergeSpecific, $.sync);138-139-const testSpacedCommand = async (t, args, execaMethod) => {140- const {stdout} = await execaMethod('command with space.js', args);141- const expectedStdout = args === undefined ? '' : args.join('\n');142- t.is(stdout, expectedStdout);143-};144-145-test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);146-test('allow commands with spaces and array arguments', testSpacedCommand, foobarArray, execa);147-test('allow commands with spaces and no array arguments, execaSync', testSpacedCommand, undefined, execaSync);148-test('allow commands with spaces and array arguments, execaSync', testSpacedCommand, foobarArray, execaSync);149-test('allow commands with spaces and no array arguments, $', testSpacedCommand, undefined, $);150-test('allow commands with spaces and array arguments, $', testSpacedCommand, foobarArray, $);151-test('allow commands with spaces and no array arguments, $.sync', testSpacedCommand, undefined, $.sync);152-test('allow commands with spaces and array arguments, $.sync', testSpacedCommand, foobarArray, $.sync);added:test/arguments/env.js+32 added
1+import process from 'node:process';2+import test from 'ava';3+import {execa} from '../../index.js';4+import {setFixtureDir, PATH_KEY} from '../helpers/fixtures-dir.js';5+6+setFixtureDir();7+process.env.FOO = 'foo';8+9+const isWindows = process.platform === 'win32';10+11+test('use environment variables by default', async t => {12+ const {stdout} = await execa('environment.js');13+ t.deepEqual(stdout.split('\n'), ['foo', 'undefined']);14+});15+16+test('extend environment variables by default', async t => {17+ const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}});18+ t.deepEqual(stdout.split('\n'), ['foo', 'bar']);19+});20+21+test('do not extend environment with `extendEnv: false`', async t => {22+ const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}, extendEnv: false});23+ t.deepEqual(stdout.split('\n'), ['undefined', 'bar']);24+});25+26+test('use extend environment with `extendEnv: true` and `shell: true`', async t => {27+ process.env.TEST = 'test';28+ const command = isWindows ? 'echo %TEST%' : 'echo $TEST';29+ const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true});30+ t.is(stdout, 'test');31+ delete process.env.TEST;32+});added:test/arguments/local.js+71 added
1+import {delimiter} from 'node:path';2+import process from 'node:process';3+import {pathToFileURL} from 'node:url';4+import test from 'ava';5+import {execa, $} from '../../index.js';6+import {setFixtureDir, PATH_KEY} from '../helpers/fixtures-dir.js';7+8+setFixtureDir();9+process.env.FOO = 'foo';10+11+const isWindows = process.platform === 'win32';12+const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;13+14+const getPathWithoutLocalDir = () => {15+ const newPath = process.env[PATH_KEY].split(delimiter).filter(pathDir => !BIN_DIR_REGEXP.test(pathDir)).join(delimiter);16+ return {[PATH_KEY]: newPath};17+};18+19+const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;20+21+const pathWitoutLocalDir = getPathWithoutLocalDir();22+23+test('preferLocal: true', async t => {24+ await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWitoutLocalDir}));25+});26+27+test('preferLocal: false', async t => {28+ await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});29+});30+31+test('preferLocal: undefined', async t => {32+ await t.throwsAsync(execa('ava', ['--version'], {env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});33+});34+35+test('preferLocal: undefined with $', async t => {36+ await t.notThrowsAsync($('ava', ['--version'], {env: pathWitoutLocalDir}));37+});38+39+test('preferLocal: undefined with $.sync', t => {40+ t.notThrows(() => $.sync('ava', ['--version'], {env: pathWitoutLocalDir}));41+});42+43+test('preferLocal: undefined with execa.pipe`...`', async t => {44+ await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);45+});46+47+test('preferLocal: undefined with $.pipe`...`', async t => {48+ await t.notThrows(() => $('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);49+});50+51+test('preferLocal: undefined with execa.pipe()', async t => {52+ await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));53+});54+55+test('preferLocal: undefined with $.pipe()', async t => {56+ await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));57+});58+59+test('localDir option', async t => {60+ const command = isWindows ? 'echo %PATH%' : 'echo $PATH';61+ const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});62+ const envPaths = stdout.split(delimiter);63+ t.true(envPaths.some(envPath => envPath.endsWith('.bin')));64+});65+66+test('localDir option can be a URL', async t => {67+ const command = isWindows ? 'echo %PATH%' : 'echo $PATH';68+ const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')});69+ const envPaths = stdout.split(delimiter);70+ t.true(envPaths.some(envPath => envPath.endsWith('.bin')));71+});added:test/arguments/normalize-args.js+47 added
1+import test from 'ava';2+import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+5+setFixtureDir();6+7+const testInvalidArgs = async (t, execaMethod) => {8+ t.throws(() => {9+ execaMethod('echo', true);10+ }, {message: /Second argument must be either/});11+};12+13+test('execa()\'s second argument must be valid', testInvalidArgs, execa);14+test('execaSync()\'s second argument must be valid', testInvalidArgs, execaSync);15+test('execaCommand()\'s second argument must be valid', testInvalidArgs, execaCommand);16+test('execaCommandSync()\'s second argument must be valid', testInvalidArgs, execaCommandSync);17+test('execaNode()\'s second argument must be valid', testInvalidArgs, execaNode);18+test('$\'s second argument must be valid', testInvalidArgs, $);19+test('$.sync\'s second argument must be valid', testInvalidArgs, $.sync);20+21+const testInvalidArgsItems = async (t, execaMethod) => {22+ t.throws(() => {23+ execaMethod('echo', [{}]);24+ }, {message: 'Second argument must be an array of strings: [object Object]'});25+};26+27+test('execa()\'s second argument must not be objects', testInvalidArgsItems, execa);28+test('execaSync()\'s second argument must not be objects', testInvalidArgsItems, execaSync);29+test('execaCommand()\'s second argument must not be objects', testInvalidArgsItems, execaCommand);30+test('execaCommandSync()\'s second argument must not be objects', testInvalidArgsItems, execaCommandSync);31+test('execaNode()\'s second argument must not be objects', testInvalidArgsItems, execaNode);32+test('$\'s second argument must not be objects', testInvalidArgsItems, $);33+test('$.sync\'s second argument must not be objects', testInvalidArgsItems, $.sync);34+35+const testNullByteArg = async (t, execaMethod) => {36+ t.throws(() => {37+ execaMethod('echo', ['a\0b']);38+ }, {message: /null bytes/});39+};40+41+test('execa()\'s second argument must not include \\0', testNullByteArg, execa);42+test('execaSync()\'s second argument must not include \\0', testNullByteArg, execaSync);43+test('execaCommand()\'s second argument must not include \\0', testNullByteArg, execaCommand);44+test('execaCommandSync()\'s second argument must not include \\0', testNullByteArg, execaCommandSync);45+test('execaNode()\'s second argument must not include \\0', testNullByteArg, execaNode);46+test('$\'s second argument must not include \\0', testNullByteArg, $);47+test('$.sync\'s second argument must not include \\0', testNullByteArg, $.sync);added:test/arguments/normalize-command.js+80 added
1+import {join, basename} from 'node:path';2+import {fileURLToPath} from 'node:url';3+import test from 'ava';4+import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';5+import {setFixtureDir, FIXTURES_DIR_URL} from '../helpers/fixtures-dir.js';6+import {foobarString} from '../helpers/input.js';7+8+setFixtureDir();9+10+const testFileUrl = async (t, execaMethod) => {11+ const command = new URL('noop.js', FIXTURES_DIR_URL);12+ const {stdout} = await execaMethod(command);13+ t.is(stdout, foobarString);14+};15+16+test('execa()\'s command argument can be a file URL', testFileUrl, execa);17+test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync);18+test('execaCommand()\'s command argument can be a file URL', testFileUrl, execaCommand);19+test('execaCommandSync()\'s command argument can be a file URL', testFileUrl, execaCommandSync);20+test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode);21+test('$\'s command argument can be a file URL', testFileUrl, $);22+test('$.sync\'s command argument can be a file URL', testFileUrl, $.sync);23+24+const testInvalidFileUrl = async (t, execaMethod) => {25+ const invalidUrl = new URL('https://invalid.com');26+ t.throws(() => {27+ execaMethod(invalidUrl);28+ }, {code: 'ERR_INVALID_URL_SCHEME'});29+};30+31+test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa);32+test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync);33+test('execaCommand()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommand);34+test('execaCommandSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommandSync);35+test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);36+test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $);37+test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync);38+39+const testInvalidCommand = async (t, arg, execaMethod) => {40+ t.throws(() => {41+ execaMethod(arg);42+ }, {message: /First argument must be a string or a file URL/});43+};44+45+test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa);46+test('execaSync()\'s first argument must be defined', testInvalidCommand, undefined, execaSync);47+test('execaCommand()\'s first argument must be defined', testInvalidCommand, undefined, execaCommand);48+test('execaCommandSync()\'s first argument must be defined', testInvalidCommand, undefined, execaCommandSync);49+test('execaNode()\'s first argument must be defined', testInvalidCommand, undefined, execaNode);50+test('$\'s first argument must be defined', testInvalidCommand, undefined, $);51+test('$.sync\'s first argument must be defined', testInvalidCommand, undefined, $.sync);52+test('execa()\'s first argument must be valid', testInvalidCommand, true, execa);53+test('execaSync()\'s first argument must be valid', testInvalidCommand, true, execaSync);54+test('execaCommand()\'s first argument must be valid', testInvalidCommand, true, execaCommand);55+test('execaCommandSync()\'s first argument must be valid', testInvalidCommand, true, execaCommandSync);56+test('execaNode()\'s first argument must be valid', testInvalidCommand, true, execaNode);57+test('$\'s first argument must be valid', testInvalidCommand, true, $);58+test('$.sync\'s first argument must be valid', testInvalidCommand, true, $.sync);59+test('execa()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execa);60+test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaSync);61+test('execaCommand()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommand);62+test('execaCommandSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommandSync);63+test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaNode);64+test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $);65+test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync);66+67+const testRelativePath = async (t, execaMethod) => {68+ const rootDir = basename(fileURLToPath(new URL('../..', import.meta.url)));69+ const pathViaParentDir = join('..', rootDir, 'test', 'fixtures', 'noop.js');70+ const {stdout} = await execaMethod(pathViaParentDir);71+ t.is(stdout, foobarString);72+};73+74+test('execa() use relative path with \'..\' chars', testRelativePath, execa);75+test('execaSync() use relative path with \'..\' chars', testRelativePath, execaSync);76+test('execaCommand() use relative path with \'..\' chars', testRelativePath, execaCommand);77+test('execaCommandSync() use relative path with \'..\' chars', testRelativePath, execaCommandSync);78+test('execaNode() use relative path with \'..\' chars', testRelativePath, execaNode);79+test('$ use relative path with \'..\' chars', testRelativePath, $);80+test('$.sync use relative path with \'..\' chars', testRelativePath, $.sync);added:test/arguments/normalize-options.js+68 added
1+import {join} from 'node:path';2+import test from 'ava';3+import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';4+import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';5+6+setFixtureDir();7+8+const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');9+10+const testSerializeArg = async (t, arg, execaMethod) => {11+ const {stdout} = await execaMethod(NOOP_PATH, [arg]);12+ t.is(stdout, String(arg));13+};14+15+test('execa()\'s arguments can be numbers', testSerializeArg, 1, execa);16+test('execa()\'s arguments can be booleans', testSerializeArg, true, execa);17+test('execa()\'s arguments can be NaN', testSerializeArg, Number.NaN, execa);18+test('execa()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execa);19+test('execa()\'s arguments can be null', testSerializeArg, null, execa);20+test('execa()\'s arguments can be undefined', testSerializeArg, undefined, execa);21+test('execa()\'s arguments can be bigints', testSerializeArg, 1n, execa);22+test('execa()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execa);23+test('execaSync()\'s arguments can be numbers', testSerializeArg, 1, execaSync);24+test('execaSync()\'s arguments can be booleans', testSerializeArg, true, execaSync);25+test('execaSync()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaSync);26+test('execaSync()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaSync);27+test('execaSync()\'s arguments can be null', testSerializeArg, null, execaSync);28+test('execaSync()\'s arguments can be undefined', testSerializeArg, undefined, execaSync);29+test('execaSync()\'s arguments can be bigints', testSerializeArg, 1n, execaSync);30+test('execaSync()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaSync);31+test('execaNode()\'s arguments can be numbers', testSerializeArg, 1, execaNode);32+test('execaNode()\'s arguments can be booleans', testSerializeArg, true, execaNode);33+test('execaNode()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaNode);34+test('execaNode()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaNode);35+test('execaNode()\'s arguments can be null', testSerializeArg, null, execaNode);36+test('execaNode()\'s arguments can be undefined', testSerializeArg, undefined, execaNode);37+test('execaNode()\'s arguments can be bigints', testSerializeArg, 1n, execaNode);38+test('execaNode()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaNode);39+test('$\'s arguments can be numbers', testSerializeArg, 1, $);40+test('$\'s arguments can be booleans', testSerializeArg, true, $);41+test('$\'s arguments can be NaN', testSerializeArg, Number.NaN, $);42+test('$\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $);43+test('$\'s arguments can be null', testSerializeArg, null, $);44+test('$\'s arguments can be undefined', testSerializeArg, undefined, $);45+test('$\'s arguments can be bigints', testSerializeArg, 1n, $);46+test('$\'s arguments can be symbols', testSerializeArg, Symbol('test'), $);47+test('$.sync\'s arguments can be numbers', testSerializeArg, 1, $.sync);48+test('$.sync\'s arguments can be booleans', testSerializeArg, true, $.sync);49+test('$.sync\'s arguments can be NaN', testSerializeArg, Number.NaN, $.sync);50+test('$.sync\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $.sync);51+test('$.sync\'s arguments can be null', testSerializeArg, null, $.sync);52+test('$.sync\'s arguments can be undefined', testSerializeArg, undefined, $.sync);53+test('$.sync\'s arguments can be bigints', testSerializeArg, 1n, $.sync);54+test('$.sync\'s arguments can be symbols', testSerializeArg, Symbol('test'), $.sync);55+56+const testInvalidOptions = async (t, execaMethod) => {57+ t.throws(() => {58+ execaMethod('echo', [], new Map());59+ }, {message: /Last argument must be an options object/});60+};61+62+test('execa()\'s third argument must be a plain object', testInvalidOptions, execa);63+test('execaSync()\'s third argument must be a plain object', testInvalidOptions, execaSync);64+test('execaCommand()\'s third argument must be a plain object', testInvalidOptions, execaCommand);65+test('execaCommandSync()\'s third argument must be a plain object', testInvalidOptions, execaCommandSync);66+test('execaNode()\'s third argument must be a plain object', testInvalidOptions, execaNode);67+test('$\'s third argument must be a plain object', testInvalidOptions, $);68+test('$.sync\'s third argument must be a plain object', testInvalidOptions, $.sync);deleted:test/arguments/normalize.js-183 removed
1-import {join, basename} from 'node:path';2-import {fileURLToPath} from 'node:url';3-import test from 'ava';4-import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';5-import {setFixtureDir, FIXTURES_DIR, FIXTURES_DIR_URL} from '../helpers/fixtures-dir.js';6-import {foobarString} from '../helpers/input.js';7-8-setFixtureDir();9-const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');10-11-const testFileUrl = async (t, execaMethod) => {12- const command = new URL('noop.js', FIXTURES_DIR_URL);13- const {stdout} = await execaMethod(command);14- t.is(stdout, foobarString);15-};16-17-test('execa()\'s command argument can be a file URL', testFileUrl, execa);18-test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync);19-test('execaCommand()\'s command argument can be a file URL', testFileUrl, execaCommand);20-test('execaCommandSync()\'s command argument can be a file URL', testFileUrl, execaCommandSync);21-test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode);22-test('$\'s command argument can be a file URL', testFileUrl, $);23-test('$.sync\'s command argument can be a file URL', testFileUrl, $.sync);24-25-const testInvalidFileUrl = async (t, execaMethod) => {26- const invalidUrl = new URL('https://invalid.com');27- t.throws(() => {28- execaMethod(invalidUrl);29- }, {code: 'ERR_INVALID_URL_SCHEME'});30-};31-32-test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa);33-test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync);34-test('execaCommand()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommand);35-test('execaCommandSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommandSync);36-test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);37-test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $);38-test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync);39-40-const testInvalidCommand = async (t, arg, execaMethod) => {41- t.throws(() => {42- execaMethod(arg);43- }, {message: /First argument must be a string or a file URL/});44-};45-46-test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa);47-test('execaSync()\'s first argument must be defined', testInvalidCommand, undefined, execaSync);48-test('execaCommand()\'s first argument must be defined', testInvalidCommand, undefined, execaCommand);49-test('execaCommandSync()\'s first argument must be defined', testInvalidCommand, undefined, execaCommandSync);50-test('execaNode()\'s first argument must be defined', testInvalidCommand, undefined, execaNode);51-test('$\'s first argument must be defined', testInvalidCommand, undefined, $);52-test('$.sync\'s first argument must be defined', testInvalidCommand, undefined, $.sync);53-test('execa()\'s first argument must be valid', testInvalidCommand, true, execa);54-test('execaSync()\'s first argument must be valid', testInvalidCommand, true, execaSync);55-test('execaCommand()\'s first argument must be valid', testInvalidCommand, true, execaCommand);56-test('execaCommandSync()\'s first argument must be valid', testInvalidCommand, true, execaCommandSync);57-test('execaNode()\'s first argument must be valid', testInvalidCommand, true, execaNode);58-test('$\'s first argument must be valid', testInvalidCommand, true, $);59-test('$.sync\'s first argument must be valid', testInvalidCommand, true, $.sync);60-test('execa()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execa);61-test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaSync);62-test('execaCommand()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommand);63-test('execaCommandSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommandSync);64-test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaNode);65-test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $);66-test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync);67-68-const testInvalidArgs = async (t, execaMethod) => {69- t.throws(() => {70- execaMethod('echo', true);71- }, {message: /Second argument must be either/});72-};73-74-test('execa()\'s second argument must be valid', testInvalidArgs, execa);75-test('execaSync()\'s second argument must be valid', testInvalidArgs, execaSync);76-test('execaCommand()\'s second argument must be valid', testInvalidArgs, execaCommand);77-test('execaCommandSync()\'s second argument must be valid', testInvalidArgs, execaCommandSync);78-test('execaNode()\'s second argument must be valid', testInvalidArgs, execaNode);79-test('$\'s second argument must be valid', testInvalidArgs, $);80-test('$.sync\'s second argument must be valid', testInvalidArgs, $.sync);81-82-const testInvalidArgsItems = async (t, execaMethod) => {83- t.throws(() => {84- execaMethod('echo', [{}]);85- }, {message: 'Second argument must be an array of strings: [object Object]'});86-};87-88-test('execa()\'s second argument must not be objects', testInvalidArgsItems, execa);89-test('execaSync()\'s second argument must not be objects', testInvalidArgsItems, execaSync);90-test('execaCommand()\'s second argument must not be objects', testInvalidArgsItems, execaCommand);91-test('execaCommandSync()\'s second argument must not be objects', testInvalidArgsItems, execaCommandSync);92-test('execaNode()\'s second argument must not be objects', testInvalidArgsItems, execaNode);93-test('$\'s second argument must not be objects', testInvalidArgsItems, $);94-test('$.sync\'s second argument must not be objects', testInvalidArgsItems, $.sync);95-96-const testNullByteArg = async (t, execaMethod) => {97- t.throws(() => {98- execaMethod('echo', ['a\0b']);99- }, {message: /null bytes/});100-};101-102-test('execa()\'s second argument must not include \\0', testNullByteArg, execa);103-test('execaSync()\'s second argument must not include \\0', testNullByteArg, execaSync);104-test('execaCommand()\'s second argument must not include \\0', testNullByteArg, execaCommand);105-test('execaCommandSync()\'s second argument must not include \\0', testNullByteArg, execaCommandSync);106-test('execaNode()\'s second argument must not include \\0', testNullByteArg, execaNode);107-test('$\'s second argument must not include \\0', testNullByteArg, $);108-test('$.sync\'s second argument must not include \\0', testNullByteArg, $.sync);109-110-const testSerializeArg = async (t, arg, execaMethod) => {111- const {stdout} = await execaMethod(NOOP_PATH, [arg]);112- t.is(stdout, String(arg));113-};114-115-test('execa()\'s arguments can be numbers', testSerializeArg, 1, execa);116-test('execa()\'s arguments can be booleans', testSerializeArg, true, execa);117-test('execa()\'s arguments can be NaN', testSerializeArg, Number.NaN, execa);118-test('execa()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execa);119-test('execa()\'s arguments can be null', testSerializeArg, null, execa);120-test('execa()\'s arguments can be undefined', testSerializeArg, undefined, execa);121-test('execa()\'s arguments can be bigints', testSerializeArg, 1n, execa);122-test('execa()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execa);123-test('execaSync()\'s arguments can be numbers', testSerializeArg, 1, execaSync);124-test('execaSync()\'s arguments can be booleans', testSerializeArg, true, execaSync);125-test('execaSync()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaSync);126-test('execaSync()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaSync);127-test('execaSync()\'s arguments can be null', testSerializeArg, null, execaSync);128-test('execaSync()\'s arguments can be undefined', testSerializeArg, undefined, execaSync);129-test('execaSync()\'s arguments can be bigints', testSerializeArg, 1n, execaSync);130-test('execaSync()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaSync);131-test('execaNode()\'s arguments can be numbers', testSerializeArg, 1, execaNode);132-test('execaNode()\'s arguments can be booleans', testSerializeArg, true, execaNode);133-test('execaNode()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaNode);134-test('execaNode()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaNode);135-test('execaNode()\'s arguments can be null', testSerializeArg, null, execaNode);136-test('execaNode()\'s arguments can be undefined', testSerializeArg, undefined, execaNode);137-test('execaNode()\'s arguments can be bigints', testSerializeArg, 1n, execaNode);138-test('execaNode()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaNode);139-test('$\'s arguments can be numbers', testSerializeArg, 1, $);140-test('$\'s arguments can be booleans', testSerializeArg, true, $);141-test('$\'s arguments can be NaN', testSerializeArg, Number.NaN, $);142-test('$\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $);143-test('$\'s arguments can be null', testSerializeArg, null, $);144-test('$\'s arguments can be undefined', testSerializeArg, undefined, $);145-test('$\'s arguments can be bigints', testSerializeArg, 1n, $);146-test('$\'s arguments can be symbols', testSerializeArg, Symbol('test'), $);147-test('$.sync\'s arguments can be numbers', testSerializeArg, 1, $.sync);148-test('$.sync\'s arguments can be booleans', testSerializeArg, true, $.sync);149-test('$.sync\'s arguments can be NaN', testSerializeArg, Number.NaN, $.sync);150-test('$.sync\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $.sync);151-test('$.sync\'s arguments can be null', testSerializeArg, null, $.sync);152-test('$.sync\'s arguments can be undefined', testSerializeArg, undefined, $.sync);153-test('$.sync\'s arguments can be bigints', testSerializeArg, 1n, $.sync);154-test('$.sync\'s arguments can be symbols', testSerializeArg, Symbol('test'), $.sync);155-156-const testInvalidOptions = async (t, execaMethod) => {157- t.throws(() => {158- execaMethod('echo', [], new Map());159- }, {message: /Last argument must be an options object/});160-};161-162-test('execa()\'s third argument must be a plain object', testInvalidOptions, execa);163-test('execaSync()\'s third argument must be a plain object', testInvalidOptions, execaSync);164-test('execaCommand()\'s third argument must be a plain object', testInvalidOptions, execaCommand);165-test('execaCommandSync()\'s third argument must be a plain object', testInvalidOptions, execaCommandSync);166-test('execaNode()\'s third argument must be a plain object', testInvalidOptions, execaNode);167-test('$\'s third argument must be a plain object', testInvalidOptions, $);168-test('$.sync\'s third argument must be a plain object', testInvalidOptions, $.sync);169-170-const testRelativePath = async (t, execaMethod) => {171- const rootDir = basename(fileURLToPath(new URL('../..', import.meta.url)));172- const pathViaParentDir = join('..', rootDir, 'test', 'fixtures', 'noop.js');173- const {stdout} = await execaMethod(pathViaParentDir);174- t.is(stdout, foobarString);175-};176-177-test('execa() use relative path with \'..\' chars', testRelativePath, execa);178-test('execaSync() use relative path with \'..\' chars', testRelativePath, execaSync);179-test('execaCommand() use relative path with \'..\' chars', testRelativePath, execaCommand);180-test('execaCommandSync() use relative path with \'..\' chars', testRelativePath, execaCommandSync);181-test('execaNode() use relative path with \'..\' chars', testRelativePath, execaNode);182-test('$ use relative path with \'..\' chars', testRelativePath, $);183-test('$.sync use relative path with \'..\' chars', testRelativePath, $.sync);deleted:test/arguments/options.js-111 removed
1-import {delimiter} from 'node:path';2-import process from 'node:process';3-import {pathToFileURL} from 'node:url';4-import test from 'ava';5-import which from 'which';6-import {execa, $} from '../../index.js';7-import {setFixtureDir, PATH_KEY} from '../helpers/fixtures-dir.js';8-import {identity} from '../helpers/stdio.js';9-10-setFixtureDir();11-process.env.FOO = 'foo';12-13-const isWindows = process.platform === 'win32';14-const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;15-16-const getPathWithoutLocalDir = () => {17- const newPath = process.env[PATH_KEY].split(delimiter).filter(pathDir => !BIN_DIR_REGEXP.test(pathDir)).join(delimiter);18- return {[PATH_KEY]: newPath};19-};20-21-const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;22-23-const pathWitoutLocalDir = getPathWithoutLocalDir();24-25-test('preferLocal: true', async t => {26- await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWitoutLocalDir}));27-});28-29-test('preferLocal: false', async t => {30- await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});31-});32-33-test('preferLocal: undefined', async t => {34- await t.throwsAsync(execa('ava', ['--version'], {env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});35-});36-37-test('preferLocal: undefined with $', async t => {38- await t.notThrowsAsync($('ava', ['--version'], {env: pathWitoutLocalDir}));39-});40-41-test('preferLocal: undefined with $.sync', t => {42- t.notThrows(() => $.sync('ava', ['--version'], {env: pathWitoutLocalDir}));43-});44-45-test('preferLocal: undefined with execa.pipe`...`', async t => {46- await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);47-});48-49-test('preferLocal: undefined with $.pipe`...`', async t => {50- await t.notThrows(() => $('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);51-});52-53-test('preferLocal: undefined with execa.pipe()', async t => {54- await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));55-});56-57-test('preferLocal: undefined with $.pipe()', async t => {58- await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));59-});60-61-test('localDir option', async t => {62- const command = isWindows ? 'echo %PATH%' : 'echo $PATH';63- const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});64- const envPaths = stdout.split(delimiter);65- t.true(envPaths.some(envPath => envPath.endsWith('.bin')));66-});67-68-test('localDir option can be a URL', async t => {69- const command = isWindows ? 'echo %PATH%' : 'echo $PATH';70- const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: pathToFileURL('/test')});71- const envPaths = stdout.split(delimiter);72- t.true(envPaths.some(envPath => envPath.endsWith('.bin')));73-});74-75-test('use environment variables by default', async t => {76- const {stdout} = await execa('environment.js');77- t.deepEqual(stdout.split('\n'), ['foo', 'undefined']);78-});79-80-test('extend environment variables by default', async t => {81- const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}});82- t.deepEqual(stdout.split('\n'), ['foo', 'bar']);83-});84-85-test('do not extend environment with `extendEnv: false`', async t => {86- const {stdout} = await execa('environment.js', [], {env: {BAR: 'bar', [PATH_KEY]: process.env[PATH_KEY]}, extendEnv: false});87- t.deepEqual(stdout.split('\n'), ['undefined', 'bar']);88-});89-90-test('use extend environment with `extendEnv: true` and `shell: true`', async t => {91- process.env.TEST = 'test';92- const command = isWindows ? 'echo %TEST%' : 'echo $TEST';93- const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true});94- t.is(stdout, 'test');95- delete process.env.TEST;96-});97-98-test('can use `options.shell: true`', async t => {99- const {stdout} = await execa('node test/fixtures/noop.js foo', {shell: true});100- t.is(stdout, 'foo');101-});102-103-const testShellPath = async (t, mapPath) => {104- const shellPath = isWindows ? 'cmd.exe' : 'bash';105- const shell = mapPath(await which(shellPath));106- const {stdout} = await execa('node test/fixtures/noop.js foo', {shell});107- t.is(stdout, 'foo');108-};109-110-test('can use `options.shell: string`', testShellPath, identity);111-test('can use `options.shell: file URL`', testShellPath, pathToFileURL);added:test/arguments/shell.js+27 added
1+import process from 'node:process';2+import {pathToFileURL} from 'node:url';3+import test from 'ava';4+import which from 'which';5+import {execa} from '../../index.js';6+import {setFixtureDir} from '../helpers/fixtures-dir.js';7+import {identity} from '../helpers/stdio.js';8+9+setFixtureDir();10+process.env.FOO = 'foo';11+12+const isWindows = process.platform === 'win32';13+14+test('can use `options.shell: true`', async t => {15+ const {stdout} = await execa('node test/fixtures/noop.js foo', {shell: true});16+ t.is(stdout, 'foo');17+});18+19+const testShellPath = async (t, mapPath) => {20+ const shellPath = isWindows ? 'cmd.exe' : 'bash';21+ const shell = mapPath(await which(shellPath));22+ const {stdout} = await execa('node test/fixtures/noop.js foo', {shell});23+ t.is(stdout, 'foo');24+};25+26+test('can use `options.shell: string`', testShellPath, identity);27+test('can use `options.shell: file URL`', testShellPath, pathToFileURL);added:test/arguments/specific.js+38 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString} from '../helpers/input.js';5+6+setFixtureDir();7+8+// eslint-disable-next-line max-params9+const testPriorityOrder = async (t, buffer, bufferStdout, bufferStderr, execaMethod) => {10+ const {stdout, stderr} = await execaMethod('noop-both.js', {buffer});11+ t.is(stdout, bufferStdout ? foobarString : undefined);12+ t.is(stderr, bufferStderr ? foobarString : undefined);13+};14+15+test('buffer: {stdout, fd1}', testPriorityOrder, {stdout: true, fd1: false}, true, true, execa);16+test('buffer: {stdout, all}', testPriorityOrder, {stdout: true, all: false}, true, false, execa);17+test('buffer: {fd1, all}', testPriorityOrder, {fd1: true, all: false}, true, false, execa);18+test('buffer: {stderr, fd2}', testPriorityOrder, {stderr: true, fd2: false}, true, true, execa);19+test('buffer: {stderr, all}', testPriorityOrder, {stderr: true, all: false}, false, true, execa);20+test('buffer: {fd2, all}', testPriorityOrder, {fd2: true, all: false}, false, true, execa);21+test('buffer: {fd1, stdout}', testPriorityOrder, {fd1: false, stdout: true}, true, true, execa);22+test('buffer: {all, stdout}', testPriorityOrder, {all: false, stdout: true}, true, false, execa);23+test('buffer: {all, fd1}', testPriorityOrder, {all: false, fd1: true}, true, false, execa);24+test('buffer: {fd2, stderr}', testPriorityOrder, {fd2: false, stderr: true}, true, true, execa);25+test('buffer: {all, stderr}', testPriorityOrder, {all: false, stderr: true}, false, true, execa);26+test('buffer: {all, fd2}', testPriorityOrder, {all: false, fd2: true}, false, true, execa);27+test('buffer: {stdout, fd1}, sync', testPriorityOrder, {stdout: true, fd1: false}, true, true, execaSync);28+test('buffer: {stdout, all}, sync', testPriorityOrder, {stdout: true, all: false}, true, false, execaSync);29+test('buffer: {fd1, all}, sync', testPriorityOrder, {fd1: true, all: false}, true, false, execaSync);30+test('buffer: {stderr, fd2}, sync', testPriorityOrder, {stderr: true, fd2: false}, true, true, execaSync);31+test('buffer: {stderr, all}, sync', testPriorityOrder, {stderr: true, all: false}, false, true, execaSync);32+test('buffer: {fd2, all}, sync', testPriorityOrder, {fd2: true, all: false}, false, true, execaSync);33+test('buffer: {fd1, stdout}, sync', testPriorityOrder, {fd1: false, stdout: true}, true, true, execaSync);34+test('buffer: {all, stdout}, sync', testPriorityOrder, {all: false, stdout: true}, true, false, execaSync);35+test('buffer: {all, fd1}, sync', testPriorityOrder, {all: false, fd1: true}, true, false, execaSync);36+test('buffer: {fd2, stderr}, sync', testPriorityOrder, {fd2: false, stderr: true}, true, true, execaSync);37+test('buffer: {all, stderr}, sync', testPriorityOrder, {all: false, stderr: true}, false, true, execaSync);38+test('buffer: {all, fd2}, sync', testPriorityOrder, {all: false, fd2: true}, false, true, execaSync);added:test/convert/fd-options.js+725 added
1+import {PassThrough} from 'node:stream';2+import {spawn} from 'node:child_process';3+import process from 'node:process';4+import test from 'ava';5+import {execa} from '../../index.js';6+import {setFixtureDir} from '../helpers/fixtures-dir.js';7+import {fullStdio, getStdio} from '../helpers/stdio.js';8+import {getEarlyErrorSubprocess} from '../helpers/early-error.js';9+import {assertPipeError} from '../helpers/pipe.js';10+11+setFixtureDir();12+13+const getMessage = message => Array.isArray(message)14+ ? `"${message[0]}: ${message[1]}" option is incompatible`15+ : message;16+17+const testPipeError = async (t, {18+ message,19+ sourceOptions = {},20+ destinationOptions = {},21+ getSource = () => execa('empty.js', sourceOptions),22+ getDestination = () => execa('empty.js', destinationOptions),23+ isScript = false,24+ from,25+ to,26+}) => {27+ const source = getSource();28+ const pipePromise = isScript ? source.pipe({from, to})`empty.js` : source.pipe(getDestination(), {from, to});29+ await assertPipeError(t, pipePromise, getMessage(message));30+};31+32+const testNodeStream = async (t, {33+ message,34+ sourceOptions = {},35+ getSource = () => execa('empty.js', sourceOptions),36+ from,37+ to,38+ writable = to !== undefined,39+}) => {40+ assertNodeStream({t, message, getSource, from, to, methodName: writable ? 'writable' : 'readable'});41+ assertNodeStream({t, message, getSource, from, to, methodName: 'duplex'});42+};43+44+const assertNodeStream = ({t, message, getSource, from, to, methodName}) => {45+ const error = t.throws(() => {46+ getSource()[methodName]({from, to});47+ });48+ t.true(error.message.includes(getMessage(message)));49+};50+51+const testIterable = async (t, {52+ message,53+ sourceOptions = {},54+ getSource = () => execa('empty.js', sourceOptions),55+ from,56+}) => {57+ const error = t.throws(() => {58+ getSource().iterable({from});59+ });60+ t.true(error.message.includes(getMessage(message)));61+};62+63+test('Must set "all" option to "true" to use .pipe("all")', testPipeError, {64+ from: 'all',65+ message: '"all" option must be true',66+});67+test('Must set "all" option to "true" to use .duplex("all")', testNodeStream, {68+ from: 'all',69+ message: '"all" option must be true',70+});71+test('Must set "all" option to "true" to use .iterable("all")', testIterable, {72+ from: 'all',73+ message: '"all" option must be true',74+});75+test('.pipe() cannot pipe to non-subprocesses', testPipeError, {76+ getDestination: () => new PassThrough(),77+ message: 'an Execa subprocess',78+});79+test('.pipe() cannot pipe to non-Execa subprocesses', testPipeError, {80+ getDestination: () => spawn('node', ['--version']),81+ message: 'an Execa subprocess',82+});83+test('.pipe() "from" option cannot be "stdin"', testPipeError, {84+ from: 'stdin',85+ message: '"from" must not be',86+});87+test('.duplex() "from" option cannot be "stdin"', testNodeStream, {88+ from: 'stdin',89+ message: '"from" must not be',90+});91+test('.iterable() "from" option cannot be "stdin"', testIterable, {92+ from: 'stdin',93+ message: '"from" must not be',94+});95+test('$.pipe() "from" option cannot be "stdin"', testPipeError, {96+ from: 'stdin',97+ isScript: true,98+ message: '"from" must not be',99+});100+test('.pipe() "to" option cannot be "stdout"', testPipeError, {101+ to: 'stdout',102+ message: '"to" must not be',103+});104+test('.duplex() "to" option cannot be "stdout"', testNodeStream, {105+ to: 'stdout',106+ message: '"to" must not be',107+});108+test('$.pipe() "to" option cannot be "stdout"', testPipeError, {109+ to: 'stdout',110+ isScript: true,111+ message: '"to" must not be',112+});113+test('.pipe() "from" option cannot be any string', testPipeError, {114+ from: 'other',115+ message: 'must be "stdout", "stderr", "all"',116+});117+test('.duplex() "from" option cannot be any string', testNodeStream, {118+ from: 'other',119+ message: 'must be "stdout", "stderr", "all"',120+});121+test('.iterable() "from" option cannot be any string', testIterable, {122+ from: 'other',123+ message: 'must be "stdout", "stderr", "all"',124+});125+test('.pipe() "to" option cannot be any string', testPipeError, {126+ to: 'other',127+ message: 'must be "stdin"',128+});129+test('.duplex() "to" option cannot be any string', testNodeStream, {130+ to: 'other',131+ message: 'must be "stdin"',132+});133+test('.pipe() "from" option cannot be a number without "fd"', testPipeError, {134+ from: '1',135+ message: 'must be "stdout", "stderr", "all"',136+});137+test('.duplex() "from" option cannot be a number without "fd"', testNodeStream, {138+ from: '1',139+ message: 'must be "stdout", "stderr", "all"',140+});141+test('.iterable() "from" option cannot be a number without "fd"', testIterable, {142+ from: '1',143+ message: 'must be "stdout", "stderr", "all"',144+});145+test('.pipe() "to" option cannot be a number without "fd"', testPipeError, {146+ to: '0',147+ message: 'must be "stdin"',148+});149+test('.duplex() "to" option cannot be a number without "fd"', testNodeStream, {150+ to: '0',151+ message: 'must be "stdin"',152+});153+test('.pipe() "from" option cannot be just "fd"', testPipeError, {154+ from: 'fd',155+ message: 'must be "stdout", "stderr", "all"',156+});157+test('.duplex() "from" option cannot be just "fd"', testNodeStream, {158+ from: 'fd',159+ message: 'must be "stdout", "stderr", "all"',160+});161+test('.iterable() "from" option cannot be just "fd"', testIterable, {162+ from: 'fd',163+ message: 'must be "stdout", "stderr", "all"',164+});165+test('.pipe() "to" option cannot be just "fd"', testPipeError, {166+ to: 'fd',167+ message: 'must be "stdin"',168+});169+test('.duplex() "to" option cannot be just "fd"', testNodeStream, {170+ to: 'fd',171+ message: 'must be "stdin"',172+});173+test('.pipe() "from" option cannot be a float', testPipeError, {174+ from: 'fd1.5',175+ message: 'must be "stdout", "stderr", "all"',176+});177+test('.duplex() "from" option cannot be a float', testNodeStream, {178+ from: 'fd1.5',179+ message: 'must be "stdout", "stderr", "all"',180+});181+test('.iterable() "from" option cannot be a float', testIterable, {182+ from: 'fd1.5',183+ message: 'must be "stdout", "stderr", "all"',184+});185+test('.pipe() "to" option cannot be a float', testPipeError, {186+ to: 'fd1.5',187+ message: 'must be "stdin"',188+});189+test('.duplex() "to" option cannot be a float', testNodeStream, {190+ to: 'fd1.5',191+ message: 'must be "stdin"',192+});193+test('.pipe() "from" option cannot be a negative number', testPipeError, {194+ from: 'fd-1',195+ message: 'must be "stdout", "stderr", "all"',196+});197+test('.duplex() "from" option cannot be a negative number', testNodeStream, {198+ from: 'fd-1',199+ message: 'must be "stdout", "stderr", "all"',200+});201+test('.iterable() "from" option cannot be a negative number', testIterable, {202+ from: 'fd-1',203+ message: 'must be "stdout", "stderr", "all"',204+});205+test('.pipe() "to" option cannot be a negative number', testPipeError, {206+ to: 'fd-1',207+ message: 'must be "stdin"',208+});209+test('.duplex() "to" option cannot be a negative number', testNodeStream, {210+ to: 'fd-1',211+ message: 'must be "stdin"',212+});213+test('.pipe() "from" option cannot be a non-existing file descriptor', testPipeError, {214+ from: 'fd3',215+ message: 'file descriptor does not exist',216+});217+test('.duplex() "from" cannot be a non-existing file descriptor', testNodeStream, {218+ from: 'fd3',219+ message: 'file descriptor does not exist',220+});221+test('.iterable() "from" cannot be a non-existing file descriptor', testIterable, {222+ from: 'fd3',223+ message: 'file descriptor does not exist',224+});225+test('.pipe() "to" option cannot be a non-existing file descriptor', testPipeError, {226+ to: 'fd3',227+ message: 'file descriptor does not exist',228+});229+test('.duplex() "to" cannot be a non-existing file descriptor', testNodeStream, {230+ to: 'fd3',231+ message: 'file descriptor does not exist',232+});233+test('.pipe() "from" option cannot be an input file descriptor', testPipeError, {234+ sourceOptions: getStdio(3, new Uint8Array()),235+ from: 'fd3',236+ message: 'must be a readable stream',237+});238+test('.duplex() "from" option cannot be an input file descriptor', testNodeStream, {239+ sourceOptions: getStdio(3, new Uint8Array()),240+ from: 'fd3',241+ message: 'must be a readable stream',242+});243+test('.iterable() "from" option cannot be an input file descriptor', testIterable, {244+ sourceOptions: getStdio(3, new Uint8Array()),245+ from: 'fd3',246+ message: 'must be a readable stream',247+});248+test('.pipe() "to" option cannot be an output file descriptor', testPipeError, {249+ destinationOptions: fullStdio,250+ to: 'fd3',251+ message: 'must be a writable stream',252+});253+test('.duplex() "to" option cannot be an output file descriptor', testNodeStream, {254+ sourceOptions: fullStdio,255+ to: 'fd3',256+ message: 'must be a writable stream',257+});258+test('.pipe() "to" option cannot be "all"', testPipeError, {259+ destinationOptions: fullStdio,260+ to: 'all',261+ message: 'must be a writable stream',262+});263+test('.duplex() "to" option cannot be "all"', testNodeStream, {264+ sourceOptions: fullStdio,265+ to: 'all',266+ message: 'must be a writable stream',267+});268+test('Cannot set "stdout" option to "ignore" to use .pipe()', testPipeError, {269+ sourceOptions: {stdout: 'ignore'},270+ message: ['stdout', '\'ignore\''],271+});272+test('Cannot set "stdout" option to "ignore" to use .duplex()', testNodeStream, {273+ sourceOptions: {stdout: 'ignore'},274+ message: ['stdout', '\'ignore\''],275+});276+test('Cannot set "stdout" option to "ignore" to use .iterable()', testIterable, {277+ sourceOptions: {stdout: 'ignore'},278+ message: ['stdout', '\'ignore\''],279+});280+test('Cannot set "stdin" option to "ignore" to use .pipe()', testPipeError, {281+ destinationOptions: {stdin: 'ignore'},282+ message: ['stdin', '\'ignore\''],283+});284+test('Cannot set "stdin" option to "ignore" to use .duplex()', testNodeStream, {285+ sourceOptions: {stdin: 'ignore'},286+ message: ['stdin', '\'ignore\''],287+ writable: true,288+});289+test('Cannot set "stdout" option to "ignore" to use .pipe(1)', testPipeError, {290+ sourceOptions: {stdout: 'ignore'},291+ from: 'fd1',292+ message: ['stdout', '\'ignore\''],293+});294+test('Cannot set "stdout" option to "ignore" to use .duplex(1)', testNodeStream, {295+ sourceOptions: {stdout: 'ignore'},296+ from: 'fd1',297+ message: ['stdout', '\'ignore\''],298+});299+test('Cannot set "stdout" option to "ignore" to use .iterable(1)', testIterable, {300+ sourceOptions: {stdout: 'ignore'},301+ from: 'fd1',302+ message: ['stdout', '\'ignore\''],303+});304+test('Cannot set "stdin" option to "ignore" to use .pipe(0)', testPipeError, {305+ destinationOptions: {stdin: 'ignore'},306+ message: ['stdin', '\'ignore\''],307+ to: 'fd0',308+});309+test('Cannot set "stdin" option to "ignore" to use .duplex(0)', testNodeStream, {310+ sourceOptions: {stdin: 'ignore'},311+ message: ['stdin', '\'ignore\''],312+ to: 'fd0',313+});314+test('Cannot set "stdout" option to "ignore" to use .pipe("stdout")', testPipeError, {315+ sourceOptions: {stdout: 'ignore'},316+ from: 'stdout',317+ message: ['stdout', '\'ignore\''],318+});319+test('Cannot set "stdout" option to "ignore" to use .duplex("stdout")', testNodeStream, {320+ sourceOptions: {stdout: 'ignore'},321+ from: 'stdout',322+ message: ['stdout', '\'ignore\''],323+});324+test('Cannot set "stdout" option to "ignore" to use .iterable("stdout")', testIterable, {325+ sourceOptions: {stdout: 'ignore'},326+ from: 'stdout',327+ message: ['stdout', '\'ignore\''],328+});329+test('Cannot set "stdin" option to "ignore" to use .pipe("stdin")', testPipeError, {330+ destinationOptions: {stdin: 'ignore'},331+ message: ['stdin', '\'ignore\''],332+ to: 'stdin',333+});334+test('Cannot set "stdin" option to "ignore" to use .duplex("stdin")', testNodeStream, {335+ sourceOptions: {stdin: 'ignore'},336+ message: ['stdin', '\'ignore\''],337+ to: 'stdin',338+});339+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe()', testPipeError, {340+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},341+ message: ['stdout', '\'ignore\''],342+});343+test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex()', testNodeStream, {344+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},345+ message: ['stdout', '\'ignore\''],346+});347+test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable()', testIterable, {348+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},349+ message: ['stdout', '\'ignore\''],350+});351+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(1)', testPipeError, {352+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},353+ from: 'fd1',354+ message: ['stdout', '\'ignore\''],355+});356+test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex(1)', testNodeStream, {357+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},358+ from: 'fd1',359+ message: ['stdout', '\'ignore\''],360+});361+test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable(1)', testIterable, {362+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},363+ from: 'fd1',364+ message: ['stdout', '\'ignore\''],365+});366+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stdout")', testPipeError, {367+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},368+ from: 'stdout',369+ message: ['stdout', '\'ignore\''],370+});371+test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex("stdout")', testNodeStream, {372+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},373+ from: 'stdout',374+ message: ['stdout', '\'ignore\''],375+});376+test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable("stdout")', testIterable, {377+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},378+ from: 'stdout',379+ message: ['stdout', '\'ignore\''],380+});381+test('Cannot set "stdio[1]" option to "ignore" to use .pipe()', testPipeError, {382+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},383+ message: ['stdio[1]', '\'ignore\''],384+});385+test('Cannot set "stdio[1]" option to "ignore" to use .duplex()', testNodeStream, {386+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},387+ message: ['stdio[1]', '\'ignore\''],388+});389+test('Cannot set "stdio[1]" option to "ignore" to use .iterable()', testIterable, {390+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},391+ message: ['stdio[1]', '\'ignore\''],392+});393+test('Cannot set "stdio[0]" option to "ignore" to use .pipe()', testPipeError, {394+ destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},395+ message: ['stdio[0]', '\'ignore\''],396+});397+test('Cannot set "stdio[0]" option to "ignore" to use .duplex()', testNodeStream, {398+ sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},399+ message: ['stdio[0]', '\'ignore\''],400+ writable: true,401+});402+test('Cannot set "stdio[1]" option to "ignore" to use .pipe(1)', testPipeError, {403+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},404+ from: 'fd1',405+ message: ['stdio[1]', '\'ignore\''],406+});407+test('Cannot set "stdio[1]" option to "ignore" to use .duplex(1)', testNodeStream, {408+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},409+ from: 'fd1',410+ message: ['stdio[1]', '\'ignore\''],411+});412+test('Cannot set "stdio[1]" option to "ignore" to use .iterable(1)', testIterable, {413+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},414+ from: 'fd1',415+ message: ['stdio[1]', '\'ignore\''],416+});417+test('Cannot set "stdio[0]" option to "ignore" to use .pipe(0)', testPipeError, {418+ destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},419+ message: ['stdio[0]', '\'ignore\''],420+ to: 'fd0',421+});422+test('Cannot set "stdio[0]" option to "ignore" to use .duplex(0)', testNodeStream, {423+ sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},424+ message: ['stdio[0]', '\'ignore\''],425+ to: 'fd0',426+});427+test('Cannot set "stdio[1]" option to "ignore" to use .pipe("stdout")', testPipeError, {428+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},429+ from: 'stdout',430+ message: ['stdio[1]', '\'ignore\''],431+});432+test('Cannot set "stdio[1]" option to "ignore" to use .duplex("stdout")', testNodeStream, {433+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},434+ from: 'stdout',435+ message: ['stdio[1]', '\'ignore\''],436+});437+test('Cannot set "stdio[1]" option to "ignore" to use .iterable("stdout")', testIterable, {438+ sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},439+ from: 'stdout',440+ message: ['stdio[1]', '\'ignore\''],441+});442+test('Cannot set "stdio[0]" option to "ignore" to use .pipe("stdin")', testPipeError, {443+ destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},444+ message: ['stdio[0]', '\'ignore\''],445+ to: 'stdin',446+});447+test('Cannot set "stdio[0]" option to "ignore" to use .duplex("stdin")', testNodeStream, {448+ sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},449+ message: ['stdio[0]', '\'ignore\''],450+ to: 'stdin',451+});452+test('Cannot set "stderr" option to "ignore" to use .pipe(2)', testPipeError, {453+ sourceOptions: {stderr: 'ignore'},454+ from: 'fd2',455+ message: ['stderr', '\'ignore\''],456+});457+test('Cannot set "stderr" option to "ignore" to use .duplex(2)', testNodeStream, {458+ sourceOptions: {stderr: 'ignore'},459+ from: 'fd2',460+ message: ['stderr', '\'ignore\''],461+});462+test('Cannot set "stderr" option to "ignore" to use .iterable(2)', testIterable, {463+ sourceOptions: {stderr: 'ignore'},464+ from: 'fd2',465+ message: ['stderr', '\'ignore\''],466+});467+test('Cannot set "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {468+ sourceOptions: {stderr: 'ignore'},469+ from: 'stderr',470+ message: ['stderr', '\'ignore\''],471+});472+test('Cannot set "stderr" option to "ignore" to use .duplex("stderr")', testNodeStream, {473+ sourceOptions: {stderr: 'ignore'},474+ from: 'stderr',475+ message: ['stderr', '\'ignore\''],476+});477+test('Cannot set "stderr" option to "ignore" to use .iterable("stderr")', testIterable, {478+ sourceOptions: {stderr: 'ignore'},479+ from: 'stderr',480+ message: ['stderr', '\'ignore\''],481+});482+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(2)', testPipeError, {483+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},484+ from: 'fd2',485+ message: ['stderr', '\'ignore\''],486+});487+test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex(2)', testNodeStream, {488+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},489+ from: 'fd2',490+ message: ['stderr', '\'ignore\''],491+});492+test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable(2)', testIterable, {493+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},494+ from: 'fd2',495+ message: ['stderr', '\'ignore\''],496+});497+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {498+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},499+ from: 'stderr',500+ message: ['stderr', '\'ignore\''],501+});502+test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex("stderr")', testNodeStream, {503+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},504+ from: 'stderr',505+ message: ['stderr', '\'ignore\''],506+});507+test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable("stderr")', testIterable, {508+ sourceOptions: {stdout: 'ignore', stderr: 'ignore'},509+ from: 'stderr',510+ message: ['stderr', '\'ignore\''],511+});512+test('Cannot set "stdio[2]" option to "ignore" to use .pipe(2)', testPipeError, {513+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},514+ from: 'fd2',515+ message: ['stdio[2]', '\'ignore\''],516+});517+test('Cannot set "stdio[2]" option to "ignore" to use .duplex(2)', testNodeStream, {518+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},519+ from: 'fd2',520+ message: ['stdio[2]', '\'ignore\''],521+});522+test('Cannot set "stdio[2]" option to "ignore" to use .iterable(2)', testIterable, {523+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},524+ from: 'fd2',525+ message: ['stdio[2]', '\'ignore\''],526+});527+test('Cannot set "stdio[2]" option to "ignore" to use .pipe("stderr")', testPipeError, {528+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},529+ from: 'stderr',530+ message: ['stdio[2]', '\'ignore\''],531+});532+test('Cannot set "stdio[2]" option to "ignore" to use .duplex("stderr")', testNodeStream, {533+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},534+ from: 'stderr',535+ message: ['stdio[2]', '\'ignore\''],536+});537+test('Cannot set "stdio[2]" option to "ignore" to use .iterable("stderr")', testIterable, {538+ sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},539+ from: 'stderr',540+ message: ['stdio[2]', '\'ignore\''],541+});542+test('Cannot set "stdio[3]" option to "ignore" to use .pipe(3)', testPipeError, {543+ sourceOptions: getStdio(3, 'ignore'),544+ from: 'fd3',545+ message: ['stdio[3]', '\'ignore\''],546+});547+test('Cannot set "stdio[3]" option to "ignore" to use .duplex(3)', testNodeStream, {548+ sourceOptions: getStdio(3, 'ignore'),549+ from: 'fd3',550+ message: ['stdio[3]', '\'ignore\''],551+});552+test('Cannot set "stdio[3]" option to "ignore" to use .iterable(3)', testIterable, {553+ sourceOptions: getStdio(3, 'ignore'),554+ from: 'fd3',555+ message: ['stdio[3]', '\'ignore\''],556+});557+test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("all")', testPipeError, {558+ sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},559+ from: 'all',560+ message: ['stdout', '\'ignore\''],561+});562+test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex("all")', testNodeStream, {563+ sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},564+ from: 'all',565+ message: ['stdout', '\'ignore\''],566+});567+test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable("all")', testIterable, {568+ sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},569+ from: 'all',570+ message: ['stdout', '\'ignore\''],571+});572+test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .pipe("all")', testPipeError, {573+ sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},574+ from: 'all',575+ message: ['stdio[1]', '\'ignore\''],576+});577+test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .duplex("all")', testNodeStream, {578+ sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},579+ from: 'all',580+ message: ['stdio[1]', '\'ignore\''],581+});582+test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .iterable("all")', testIterable, {583+ sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},584+ from: 'all',585+ message: ['stdio[1]', '\'ignore\''],586+});587+test('Cannot set "stdout" option to "inherit" to use .pipe()', testPipeError, {588+ sourceOptions: {stdout: 'inherit'},589+ message: ['stdout', '\'inherit\''],590+});591+test('Cannot set "stdout" option to "inherit" to use .duplex()', testNodeStream, {592+ sourceOptions: {stdout: 'inherit'},593+ message: ['stdout', '\'inherit\''],594+});595+test('Cannot set "stdout" option to "inherit" to use .iterable()', testIterable, {596+ sourceOptions: {stdout: 'inherit'},597+ message: ['stdout', '\'inherit\''],598+});599+test('Cannot set "stdin" option to "inherit" to use .pipe()', testPipeError, {600+ destinationOptions: {stdin: 'inherit'},601+ message: ['stdin', '\'inherit\''],602+});603+test('Cannot set "stdin" option to "inherit" to use .duplex()', testNodeStream, {604+ sourceOptions: {stdin: 'inherit'},605+ message: ['stdin', '\'inherit\''],606+ writable: true,607+});608+test('Cannot set "stdout" option to "ipc" to use .pipe()', testPipeError, {609+ sourceOptions: {stdout: 'ipc'},610+ message: ['stdout', '\'ipc\''],611+});612+test('Cannot set "stdout" option to "ipc" to use .duplex()', testNodeStream, {613+ sourceOptions: {stdout: 'ipc'},614+ message: ['stdout', '\'ipc\''],615+});616+test('Cannot set "stdout" option to "ipc" to use .iterable()', testIterable, {617+ sourceOptions: {stdout: 'ipc'},618+ message: ['stdout', '\'ipc\''],619+});620+test('Cannot set "stdin" option to "ipc" to use .pipe()', testPipeError, {621+ destinationOptions: {stdin: 'ipc'},622+ message: ['stdin', '\'ipc\''],623+});624+test('Cannot set "stdin" option to "ipc" to use .duplex()', testNodeStream, {625+ sourceOptions: {stdin: 'ipc'},626+ message: ['stdin', '\'ipc\''],627+ writable: true,628+});629+test('Cannot set "stdout" option to file descriptors to use .pipe()', testPipeError, {630+ sourceOptions: {stdout: 1},631+ message: ['stdout', '1'],632+});633+test('Cannot set "stdout" option to file descriptors to use .duplex()', testNodeStream, {634+ sourceOptions: {stdout: 1},635+ message: ['stdout', '1'],636+});637+test('Cannot set "stdout" option to file descriptors to use .iterable()', testIterable, {638+ sourceOptions: {stdout: 1},639+ message: ['stdout', '1'],640+});641+test('Cannot set "stdin" option to file descriptors to use .pipe()', testPipeError, {642+ destinationOptions: {stdin: 0},643+ message: ['stdin', '0'],644+});645+test('Cannot set "stdin" option to file descriptors to use .duplex()', testNodeStream, {646+ sourceOptions: {stdin: 0},647+ message: ['stdin', '0'],648+ writable: true,649+});650+test('Cannot set "stdout" option to Node.js streams to use .pipe()', testPipeError, {651+ sourceOptions: {stdout: process.stdout},652+ message: ['stdout', 'Stream'],653+});654+test('Cannot set "stdout" option to Node.js streams to use .duplex()', testNodeStream, {655+ sourceOptions: {stdout: process.stdout},656+ message: ['stdout', 'Stream'],657+});658+test('Cannot set "stdout" option to Node.js streams to use .iterable()', testIterable, {659+ sourceOptions: {stdout: process.stdout},660+ message: ['stdout', 'Stream'],661+});662+test('Cannot set "stdin" option to Node.js streams to use .pipe()', testPipeError, {663+ destinationOptions: {stdin: process.stdin},664+ message: ['stdin', 'Stream'],665+});666+test('Cannot set "stdin" option to Node.js streams to use .duplex()', testNodeStream, {667+ sourceOptions: {stdin: process.stdin},668+ message: ['stdin', 'Stream'],669+ writable: true,670+});671+test('Cannot set "stdio[3]" option to Node.js Writable streams to use .pipe()', testPipeError, {672+ sourceOptions: getStdio(3, process.stdout),673+ message: ['stdio[3]', 'Stream'],674+ from: 'fd3',675+});676+test('Cannot set "stdio[3]" option to Node.js Writable streams to use .duplex()', testNodeStream, {677+ sourceOptions: getStdio(3, process.stdout),678+ message: ['stdio[3]', 'Stream'],679+ from: 'fd3',680+});681+test('Cannot set "stdio[3]" option to Node.js Writable streams to use .iterable()', testIterable, {682+ sourceOptions: getStdio(3, process.stdout),683+ message: ['stdio[3]', 'Stream'],684+ from: 'fd3',685+});686+test('Cannot set "stdio[3]" option to Node.js Readable streams to use .pipe()', testPipeError, {687+ destinationOptions: getStdio(3, process.stdin),688+ message: ['stdio[3]', 'Stream'],689+ to: 'fd3',690+});691+test('Cannot set "stdio[3]" option to Node.js Readable streams to use .duplex()', testNodeStream, {692+ sourceOptions: getStdio(3, process.stdin),693+ message: ['stdio[3]', 'Stream'],694+ to: 'fd3',695+});696+697+test('Sets the right error message when the "all" option is incompatible - execa.$', async t => {698+ await assertPipeError(699+ t,700+ execa('empty.js')701+ .pipe({all: false})`stdin.js`702+ .pipe(execa('empty.js'), {from: 'all'}),703+ '"all" option must be true',704+ );705+});706+707+test('Sets the right error message when the "all" option is incompatible - execa.execa', async t => {708+ await assertPipeError(709+ t,710+ execa('empty.js')711+ .pipe(execa('stdin.js', {all: false}))712+ .pipe(execa('empty.js'), {from: 'all'}),713+ '"all" option must be true',714+ );715+});716+717+test('Sets the right error message when the "all" option is incompatible - early error', async t => {718+ await assertPipeError(719+ t,720+ getEarlyErrorSubprocess()721+ .pipe(execa('stdin.js', {all: false}))722+ .pipe(execa('empty.js'), {from: 'all'}),723+ '"all" option must be true',724+ );725+});deleted:test/exit/code.js-85 removed
1-import process from 'node:process';2-import test from 'ava';3-import {execa} from '../../index.js';4-import {setFixtureDir} from '../helpers/fixtures-dir.js';5-6-const isWindows = process.platform === 'win32';7-8-setFixtureDir();9-10-test('exitCode is 0 on success', async t => {11- const {exitCode} = await execa('noop.js', ['foo']);12- t.is(exitCode, 0);13-});14-15-const testExitCode = async (t, expectedExitCode) => {16- const {exitCode, originalMessage, shortMessage, message} = await t.throwsAsync(17- execa('exit.js', [`${expectedExitCode}`]),18- );19- t.is(exitCode, expectedExitCode);20- t.is(originalMessage, '');21- t.is(shortMessage, `Command failed with exit code ${expectedExitCode}: exit.js ${expectedExitCode}`);22- t.is(message, shortMessage);23-};24-25-test('exitCode is 2', testExitCode, 2);26-test('exitCode is 3', testExitCode, 3);27-test('exitCode is 4', testExitCode, 4);28-29-if (!isWindows) {30- test('error.signal is SIGINT', async t => {31- const subprocess = execa('forever.js');32-33- process.kill(subprocess.pid, 'SIGINT');34-35- const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});36- t.is(signal, 'SIGINT');37- });38-39- test('error.signalDescription is defined', async t => {40- const subprocess = execa('forever.js');41-42- process.kill(subprocess.pid, 'SIGINT');43-44- const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});45- t.is(signalDescription, 'User interruption with CTRL-C');46- });47-48- test('error.signal is SIGTERM', async t => {49- const subprocess = execa('forever.js');50-51- process.kill(subprocess.pid, 'SIGTERM');52-53- const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});54- t.is(signal, 'SIGTERM');55- });56-57- test('error.signal uses killSignal', async t => {58- const {signal} = await t.throwsAsync(execa('forever.js', {killSignal: 'SIGINT', timeout: 1, message: /timed out after/}));59- t.is(signal, 'SIGINT');60- });61-62- test('exitCode is undefined on signal termination', async t => {63- const subprocess = execa('forever.js');64-65- process.kill(subprocess.pid);66-67- const {exitCode} = await t.throwsAsync(subprocess);68- t.is(exitCode, undefined);69- });70-}71-72-test('result.signal is undefined for successful execution', async t => {73- const {signal} = await execa('noop.js');74- t.is(signal, undefined);75-});76-77-test('result.signal is undefined if subprocess failed, but was not killed', async t => {78- const {signal} = await t.throwsAsync(execa('fail.js'));79- t.is(signal, undefined);80-});81-82-test('result.signalDescription is undefined for successful execution', async t => {83- const {signalDescription} = await execa('noop.js');84- t.is(signalDescription, undefined);85-});added:test/exit/kill-error.js+83 added
1+import {once} from 'node:events';2+import {setImmediate} from 'node:timers/promises';3+import test from 'ava';4+import isRunning from 'is-running';5+import {execa} from '../../index.js';6+import {setFixtureDir} from '../helpers/fixtures-dir.js';7+8+setFixtureDir();9+10+test('.kill(error) propagates error', async t => {11+ const subprocess = execa('forever.js');12+ const originalMessage = 'test';13+ const cause = new Error(originalMessage);14+ t.true(subprocess.kill(cause));15+ const error = await t.throwsAsync(subprocess);16+ t.is(error.cause, cause);17+ t.true(cause.stack.includes(import.meta.url));18+ t.is(error.exitCode, undefined);19+ t.is(error.signal, 'SIGTERM');20+ t.true(error.isTerminated);21+ t.is(error.originalMessage, originalMessage);22+ t.true(error.message.includes(originalMessage));23+ t.true(error.message.includes('was killed with SIGTERM'));24+});25+26+test('.kill(error) uses killSignal', async t => {27+ const subprocess = execa('forever.js', {killSignal: 'SIGINT'});28+ const cause = new Error('test');29+ subprocess.kill(cause);30+ const error = await t.throwsAsync(subprocess);31+ t.is(error.cause, cause);32+ t.is(error.signal, 'SIGINT');33+});34+35+test('.kill(signal, error) uses signal', async t => {36+ const subprocess = execa('forever.js');37+ const cause = new Error('test');38+ subprocess.kill('SIGINT', cause);39+ const error = await t.throwsAsync(subprocess);40+ t.is(error.cause, cause);41+ t.is(error.signal, 'SIGINT');42+});43+44+test('.kill(error) is a noop if subprocess already exited', async t => {45+ const subprocess = execa('empty.js');46+ await subprocess;47+ t.false(isRunning(subprocess.pid));48+ t.false(subprocess.kill(new Error('test')));49+});50+51+test('.kill(error) terminates but does not change the error if the subprocess already errored but did not exit yet', async t => {52+ const subprocess = execa('forever.js');53+ const cause = new Error('first');54+ subprocess.stdout.destroy(cause);55+ await setImmediate();56+ const secondError = new Error('second');57+ t.true(subprocess.kill(secondError));58+ const error = await t.throwsAsync(subprocess);59+ t.is(error.cause, cause);60+ t.is(error.exitCode, undefined);61+ t.is(error.signal, 'SIGTERM');62+ t.true(error.isTerminated);63+ t.false(error.message.includes(secondError.message));64+});65+66+test('.kill(error) twice in a row', async t => {67+ const subprocess = execa('forever.js');68+ const cause = new Error('first');69+ subprocess.kill(cause);70+ const secondCause = new Error('second');71+ subprocess.kill(secondCause);72+ const error = await t.throwsAsync(subprocess);73+ t.is(error.cause, cause);74+ t.false(error.message.includes(secondCause.message));75+});76+77+test('.kill(error) does not emit the "error" event', async t => {78+ const subprocess = execa('forever.js');79+ const cause = new Error('test');80+ subprocess.kill(cause);81+ const error = await Promise.race([t.throwsAsync(subprocess), once(subprocess, 'error')]);82+ t.is(error.cause, cause);83+});added:test/exit/kill-force.js+140 added
1+import process from 'node:process';2+import {once, defaultMaxListeners} from 'node:events';3+import {constants} from 'node:os';4+import {setTimeout} from 'node:timers/promises';5+import test from 'ava';6+import {pEvent} from 'p-event';7+import isRunning from 'is-running';8+import {execa} from '../../index.js';9+import {setFixtureDir} from '../helpers/fixtures-dir.js';10+import {assertMaxListeners} from '../helpers/listeners.js';11+12+setFixtureDir();13+14+const isWindows = process.platform === 'win32';15+16+const spawnNoKillable = async (forceKillAfterDelay, options) => {17+ const subprocess = execa('no-killable.js', {18+ ipc: true,19+ forceKillAfterDelay,20+ ...options,21+ });22+ await pEvent(subprocess, 'message');23+ return {subprocess};24+};25+26+const spawnNoKillableSimple = options => execa('forever.js', {killSignal: 'SIGWINCH', forceKillAfterDelay: 1, ...options});27+28+test('kill("SIGKILL") should terminate cleanly', async t => {29+ const {subprocess} = await spawnNoKillable();30+31+ subprocess.kill('SIGKILL');32+33+ const {isTerminated, signal} = await t.throwsAsync(subprocess);34+ t.true(isTerminated);35+ t.is(signal, 'SIGKILL');36+});37+38+const testInvalidForceKill = async (t, forceKillAfterDelay) => {39+ t.throws(() => {40+ execa('empty.js', {forceKillAfterDelay});41+ }, {instanceOf: TypeError, message: /non-negative integer/});42+};43+44+test('`forceKillAfterDelay` should not be NaN', testInvalidForceKill, Number.NaN);45+test('`forceKillAfterDelay` should not be negative', testInvalidForceKill, -1);46+47+// `SIGTERM` cannot be caught on Windows, and it always aborts the subprocess (like `SIGKILL` on Unix).48+// Therefore, this feature and those tests must be different on Windows.49+if (isWindows) {50+ test('Can call `.kill()` with `forceKillAfterDelay` on Windows', async t => {51+ const {subprocess} = await spawnNoKillable(1);52+ subprocess.kill();53+54+ const {isTerminated, signal} = await t.throwsAsync(subprocess);55+ t.true(isTerminated);56+ t.is(signal, 'SIGTERM');57+ });58+} else {59+ const testNoForceKill = async (t, forceKillAfterDelay, killArgument, options) => {60+ const {subprocess} = await spawnNoKillable(forceKillAfterDelay, options);61+62+ subprocess.kill(killArgument);63+64+ await setTimeout(6e3);65+ t.true(isRunning(subprocess.pid));66+ subprocess.kill('SIGKILL');67+68+ const {isTerminated, signal} = await t.throwsAsync(subprocess);69+ t.true(isTerminated);70+ t.is(signal, 'SIGKILL');71+ };72+73+ test('`forceKillAfterDelay: false` should not kill after a timeout', testNoForceKill, false);74+ test('`forceKillAfterDelay` should not kill after a timeout with other signals', testNoForceKill, true, 'SIGINT');75+ test('`forceKillAfterDelay` should not kill after a timeout with wrong killSignal string', testNoForceKill, true, 'SIGTERM', {killSignal: 'SIGINT'});76+ test('`forceKillAfterDelay` should not kill after a timeout with wrong killSignal number', testNoForceKill, true, constants.signals.SIGTERM, {killSignal: constants.signals.SIGINT});77+78+ const testForceKill = async (t, forceKillAfterDelay, killArgument, options) => {79+ const {subprocess} = await spawnNoKillable(forceKillAfterDelay, options);80+81+ subprocess.kill(killArgument);82+83+ const {isTerminated, signal} = await t.throwsAsync(subprocess);84+ t.true(isTerminated);85+ t.is(signal, 'SIGKILL');86+ };87+88+ test('`forceKillAfterDelay: number` should kill after a timeout', testForceKill, 50);89+ test('`forceKillAfterDelay: true` should kill after a timeout', testForceKill, true);90+ test('`forceKillAfterDelay: undefined` should kill after a timeout', testForceKill, undefined);91+ test('`forceKillAfterDelay` should kill after a timeout with SIGTERM', testForceKill, 50, 'SIGTERM');92+ test('`forceKillAfterDelay` should kill after a timeout with the killSignal string', testForceKill, 50, 'SIGINT', {killSignal: 'SIGINT'});93+ test('`forceKillAfterDelay` should kill after a timeout with the killSignal number', testForceKill, 50, constants.signals.SIGINT, {killSignal: constants.signals.SIGINT});94+ test('`forceKillAfterDelay` should kill after a timeout with an error', testForceKill, 50, new Error('test'));95+ test('`forceKillAfterDelay` should kill after a timeout with an error and a killSignal', testForceKill, 50, new Error('test'), {killSignal: 'SIGINT'});96+97+ test('`forceKillAfterDelay` works with the "signal" option', async t => {98+ const abortController = new AbortController();99+ const subprocess = spawnNoKillableSimple({cancelSignal: abortController.signal});100+ await once(subprocess, 'spawn');101+ abortController.abort();102+ const {isTerminated, signal, isCanceled} = await t.throwsAsync(subprocess);103+ t.true(isTerminated);104+ t.is(signal, 'SIGKILL');105+ t.true(isCanceled);106+ });107+108+ test('`forceKillAfterDelay` works with the "timeout" option', async t => {109+ const subprocess = spawnNoKillableSimple({timeout: 1});110+ const {isTerminated, signal, timedOut} = await t.throwsAsync(subprocess);111+ t.true(isTerminated);112+ t.is(signal, 'SIGKILL');113+ t.true(timedOut);114+ });115+116+ test.serial('Can call `.kill()` with `forceKillAfterDelay` many times without triggering the maxListeners warning', async t => {117+ const checkMaxListeners = assertMaxListeners(t);118+119+ const subprocess = spawnNoKillableSimple();120+ for (let index = 0; index < defaultMaxListeners + 1; index += 1) {121+ subprocess.kill();122+ }123+124+ const {isTerminated, signal} = await t.throwsAsync(subprocess);125+ t.true(isTerminated);126+ t.is(signal, 'SIGKILL');127+128+ checkMaxListeners();129+ });130+131+ test('Can call `.kill()` with `forceKillAfterDelay` multiple times', async t => {132+ const subprocess = spawnNoKillableSimple();133+ subprocess.kill();134+ subprocess.kill();135+136+ const {isTerminated, signal} = await t.throwsAsync(subprocess);137+ t.true(isTerminated);138+ t.is(signal, 'SIGKILL');139+ });140+}added:test/exit/kill-signal.js+95 added
1+import {once} from 'node:events';2+import {setImmediate} from 'node:timers/promises';3+import test from 'ava';4+import {execa} from '../../index.js';5+import {setFixtureDir} from '../helpers/fixtures-dir.js';6+7+setFixtureDir();8+9+test('Can call `.kill()` multiple times', async t => {10+ const subprocess = execa('forever.js');11+ subprocess.kill();12+ subprocess.kill();13+14+ const {isTerminated, signal} = await t.throwsAsync(subprocess);15+ t.true(isTerminated);16+ t.is(signal, 'SIGTERM');17+});18+19+test('execa() returns a promise with kill()', async t => {20+ const subprocess = execa('noop.js', ['foo']);21+ t.is(typeof subprocess.kill, 'function');22+ await subprocess;23+});24+25+const testInvalidKillArgument = async (t, killArgument, secondKillArgument) => {26+ const subprocess = execa('empty.js');27+ const message = secondKillArgument instanceof Error || secondKillArgument === undefined28+ ? /error instance or a signal name/29+ : /second argument is optional/;30+ t.throws(() => {31+ subprocess.kill(killArgument, secondKillArgument);32+ }, {message});33+ await subprocess;34+};35+36+test('Cannot call .kill(null)', testInvalidKillArgument, null);37+test('Cannot call .kill(0n)', testInvalidKillArgument, 0n);38+test('Cannot call .kill(true)', testInvalidKillArgument, true);39+test('Cannot call .kill(errorObject)', testInvalidKillArgument, {name: '', message: '', stack: ''});40+test('Cannot call .kill(errorArray)', testInvalidKillArgument, [new Error('test')]);41+test('Cannot call .kill(undefined, true)', testInvalidKillArgument, undefined, true);42+test('Cannot call .kill("SIGTERM", true)', testInvalidKillArgument, 'SIGTERM', true);43+test('Cannot call .kill(true, error)', testInvalidKillArgument, true, new Error('test'));44+45+test('subprocess errors are handled before spawn', async t => {46+ const subprocess = execa('forever.js');47+ const cause = new Error('test');48+ subprocess.emit('error', cause);49+ subprocess.kill();50+ const error = await t.throwsAsync(subprocess);51+ t.is(error.cause, cause);52+ t.is(error.exitCode, undefined);53+ t.is(error.signal, undefined);54+ t.false(error.isTerminated);55+});56+57+test('subprocess errors are handled after spawn', async t => {58+ const subprocess = execa('forever.js');59+ await once(subprocess, 'spawn');60+ const cause = new Error('test');61+ subprocess.emit('error', cause);62+ subprocess.kill();63+ const error = await t.throwsAsync(subprocess);64+ t.is(error.cause, cause);65+ t.is(error.exitCode, undefined);66+ t.is(error.signal, 'SIGTERM');67+ t.true(error.isTerminated);68+});69+70+test('subprocess double errors are handled after spawn', async t => {71+ const abortController = new AbortController();72+ const subprocess = execa('forever.js', {cancelSignal: abortController.signal});73+ await once(subprocess, 'spawn');74+ const cause = new Error('test');75+ subprocess.emit('error', cause);76+ await setImmediate();77+ abortController.abort();78+ const error = await t.throwsAsync(subprocess);79+ t.is(error.cause, cause);80+ t.is(error.exitCode, undefined);81+ t.is(error.signal, 'SIGTERM');82+ t.true(error.isTerminated);83+});84+85+test('subprocess errors use killSignal', async t => {86+ const subprocess = execa('forever.js', {killSignal: 'SIGINT'});87+ await once(subprocess, 'spawn');88+ const cause = new Error('test');89+ subprocess.emit('error', cause);90+ subprocess.kill();91+ const error = await t.throwsAsync(subprocess);92+ t.is(error.cause, cause);93+ t.true(error.isTerminated);94+ t.is(error.signal, 'SIGINT');95+});deleted:test/exit/kill.js-303 removed
1-import process from 'node:process';2-import {once, defaultMaxListeners} from 'node:events';3-import {constants} from 'node:os';4-import {setTimeout, setImmediate} from 'node:timers/promises';5-import test from 'ava';6-import {pEvent} from 'p-event';7-import isRunning from 'is-running';8-import {execa} from '../../index.js';9-import {setFixtureDir} from '../helpers/fixtures-dir.js';10-import {assertMaxListeners} from '../helpers/listeners.js';11-12-setFixtureDir();13-14-const isWindows = process.platform === 'win32';15-16-const spawnNoKillable = async (forceKillAfterDelay, options) => {17- const subprocess = execa('no-killable.js', {18- ipc: true,19- forceKillAfterDelay,20- ...options,21- });22- await pEvent(subprocess, 'message');23- return {subprocess};24-};25-26-const spawnNoKillableSimple = options => execa('forever.js', {killSignal: 'SIGWINCH', forceKillAfterDelay: 1, ...options});27-28-test('kill("SIGKILL") should terminate cleanly', async t => {29- const {subprocess} = await spawnNoKillable();30-31- subprocess.kill('SIGKILL');32-33- const {isTerminated, signal} = await t.throwsAsync(subprocess);34- t.true(isTerminated);35- t.is(signal, 'SIGKILL');36-});37-38-const testInvalidForceKill = async (t, forceKillAfterDelay) => {39- t.throws(() => {40- execa('empty.js', {forceKillAfterDelay});41- }, {instanceOf: TypeError, message: /non-negative integer/});42-};43-44-test('`forceKillAfterDelay` should not be NaN', testInvalidForceKill, Number.NaN);45-test('`forceKillAfterDelay` should not be negative', testInvalidForceKill, -1);46-47-// `SIGTERM` cannot be caught on Windows, and it always aborts the subprocess (like `SIGKILL` on Unix).48-// Therefore, this feature and those tests must be different on Windows.49-if (isWindows) {50- test('Can call `.kill()` with `forceKillAfterDelay` on Windows', async t => {51- const {subprocess} = await spawnNoKillable(1);52- subprocess.kill();53-54- const {isTerminated, signal} = await t.throwsAsync(subprocess);55- t.true(isTerminated);56- t.is(signal, 'SIGTERM');57- });58-} else {59- const testNoForceKill = async (t, forceKillAfterDelay, killArgument, options) => {60- const {subprocess} = await spawnNoKillable(forceKillAfterDelay, options);61-62- subprocess.kill(killArgument);63-64- await setTimeout(6e3);65- t.true(isRunning(subprocess.pid));66- subprocess.kill('SIGKILL');67-68- const {isTerminated, signal} = await t.throwsAsync(subprocess);69- t.true(isTerminated);70- t.is(signal, 'SIGKILL');71- };72-73- test('`forceKillAfterDelay: false` should not kill after a timeout', testNoForceKill, false);74- test('`forceKillAfterDelay` should not kill after a timeout with other signals', testNoForceKill, true, 'SIGINT');75- test('`forceKillAfterDelay` should not kill after a timeout with wrong killSignal string', testNoForceKill, true, 'SIGTERM', {killSignal: 'SIGINT'});76- test('`forceKillAfterDelay` should not kill after a timeout with wrong killSignal number', testNoForceKill, true, constants.signals.SIGTERM, {killSignal: constants.signals.SIGINT});77-78- const testForceKill = async (t, forceKillAfterDelay, killArgument, options) => {79- const {subprocess} = await spawnNoKillable(forceKillAfterDelay, options);80-81- subprocess.kill(killArgument);82-83- const {isTerminated, signal} = await t.throwsAsync(subprocess);84- t.true(isTerminated);85- t.is(signal, 'SIGKILL');86- };87-88- test('`forceKillAfterDelay: number` should kill after a timeout', testForceKill, 50);89- test('`forceKillAfterDelay: true` should kill after a timeout', testForceKill, true);90- test('`forceKillAfterDelay: undefined` should kill after a timeout', testForceKill, undefined);91- test('`forceKillAfterDelay` should kill after a timeout with SIGTERM', testForceKill, 50, 'SIGTERM');92- test('`forceKillAfterDelay` should kill after a timeout with the killSignal string', testForceKill, 50, 'SIGINT', {killSignal: 'SIGINT'});93- test('`forceKillAfterDelay` should kill after a timeout with the killSignal number', testForceKill, 50, constants.signals.SIGINT, {killSignal: constants.signals.SIGINT});94- test('`forceKillAfterDelay` should kill after a timeout with an error', testForceKill, 50, new Error('test'));95- test('`forceKillAfterDelay` should kill after a timeout with an error and a killSignal', testForceKill, 50, new Error('test'), {killSignal: 'SIGINT'});96-97- test('`forceKillAfterDelay` works with the "signal" option', async t => {98- const abortController = new AbortController();99- const subprocess = spawnNoKillableSimple({cancelSignal: abortController.signal});100- await once(subprocess, 'spawn');101- abortController.abort();102- const {isTerminated, signal, isCanceled} = await t.throwsAsync(subprocess);103- t.true(isTerminated);104- t.is(signal, 'SIGKILL');105- t.true(isCanceled);106- });107-108- test('`forceKillAfterDelay` works with the "timeout" option', async t => {109- const subprocess = spawnNoKillableSimple({timeout: 1});110- const {isTerminated, signal, timedOut} = await t.throwsAsync(subprocess);111- t.true(isTerminated);112- t.is(signal, 'SIGKILL');113- t.true(timedOut);114- });115-116- test.serial('Can call `.kill()` with `forceKillAfterDelay` many times without triggering the maxListeners warning', async t => {117- const checkMaxListeners = assertMaxListeners(t);118-119- const subprocess = spawnNoKillableSimple();120- for (let index = 0; index < defaultMaxListeners + 1; index += 1) {121- subprocess.kill();122- }123-124- const {isTerminated, signal} = await t.throwsAsync(subprocess);125- t.true(isTerminated);126- t.is(signal, 'SIGKILL');127-128- checkMaxListeners();129- });130-131- test('Can call `.kill()` with `forceKillAfterDelay` multiple times', async t => {132- const subprocess = spawnNoKillableSimple();133- subprocess.kill();134- subprocess.kill();135-136- const {isTerminated, signal} = await t.throwsAsync(subprocess);137- t.true(isTerminated);138- t.is(signal, 'SIGKILL');139- });140-}141-142-test('Can call `.kill()` multiple times', async t => {143- const subprocess = execa('forever.js');144- subprocess.kill();145- subprocess.kill();146-147- const {isTerminated, signal} = await t.throwsAsync(subprocess);148- t.true(isTerminated);149- t.is(signal, 'SIGTERM');150-});151-152-test('execa() returns a promise with kill()', async t => {153- const subprocess = execa('noop.js', ['foo']);154- t.is(typeof subprocess.kill, 'function');155- await subprocess;156-});157-158-const testInvalidKillArgument = async (t, killArgument, secondKillArgument) => {159- const subprocess = execa('empty.js');160- const message = secondKillArgument instanceof Error || secondKillArgument === undefined161- ? /error instance or a signal name/162- : /second argument is optional/;163- t.throws(() => {164- subprocess.kill(killArgument, secondKillArgument);165- }, {message});166- await subprocess;167-};168-169-test('Cannot call .kill(null)', testInvalidKillArgument, null);170-test('Cannot call .kill(0n)', testInvalidKillArgument, 0n);171-test('Cannot call .kill(true)', testInvalidKillArgument, true);172-test('Cannot call .kill(errorObject)', testInvalidKillArgument, {name: '', message: '', stack: ''});173-test('Cannot call .kill(errorArray)', testInvalidKillArgument, [new Error('test')]);174-test('Cannot call .kill(undefined, true)', testInvalidKillArgument, undefined, true);175-test('Cannot call .kill("SIGTERM", true)', testInvalidKillArgument, 'SIGTERM', true);176-test('Cannot call .kill(true, error)', testInvalidKillArgument, true, new Error('test'));177-178-test('.kill(error) propagates error', async t => {179- const subprocess = execa('forever.js');180- const originalMessage = 'test';181- const cause = new Error(originalMessage);182- t.true(subprocess.kill(cause));183- const error = await t.throwsAsync(subprocess);184- t.is(error.cause, cause);185- t.true(cause.stack.includes(import.meta.url));186- t.is(error.exitCode, undefined);187- t.is(error.signal, 'SIGTERM');188- t.true(error.isTerminated);189- t.is(error.originalMessage, originalMessage);190- t.true(error.message.includes(originalMessage));191- t.true(error.message.includes('was killed with SIGTERM'));192-});193-194-test('.kill(error) uses killSignal', async t => {195- const subprocess = execa('forever.js', {killSignal: 'SIGINT'});196- const cause = new Error('test');197- subprocess.kill(cause);198- const error = await t.throwsAsync(subprocess);199- t.is(error.cause, cause);200- t.is(error.signal, 'SIGINT');201-});202-203-test('.kill(signal, error) uses signal', async t => {204- const subprocess = execa('forever.js');205- const cause = new Error('test');206- subprocess.kill('SIGINT', cause);207- const error = await t.throwsAsync(subprocess);208- t.is(error.cause, cause);209- t.is(error.signal, 'SIGINT');210-});211-212-test('.kill(error) is a noop if subprocess already exited', async t => {213- const subprocess = execa('empty.js');214- await subprocess;215- t.false(isRunning(subprocess.pid));216- t.false(subprocess.kill(new Error('test')));217-});218-219-test('.kill(error) terminates but does not change the error if the subprocess already errored but did not exit yet', async t => {220- const subprocess = execa('forever.js');221- const cause = new Error('first');222- subprocess.stdout.destroy(cause);223- await setImmediate();224- const secondError = new Error('second');225- t.true(subprocess.kill(secondError));226- const error = await t.throwsAsync(subprocess);227- t.is(error.cause, cause);228- t.is(error.exitCode, undefined);229- t.is(error.signal, 'SIGTERM');230- t.true(error.isTerminated);231- t.false(error.message.includes(secondError.message));232-});233-234-test('.kill(error) twice in a row', async t => {235- const subprocess = execa('forever.js');236- const cause = new Error('first');237- subprocess.kill(cause);238- const secondCause = new Error('second');239- subprocess.kill(secondCause);240- const error = await t.throwsAsync(subprocess);241- t.is(error.cause, cause);242- t.false(error.message.includes(secondCause.message));243-});244-245-test('.kill(error) does not emit the "error" event', async t => {246- const subprocess = execa('forever.js');247- const cause = new Error('test');248- subprocess.kill(cause);249- const error = await Promise.race([t.throwsAsync(subprocess), once(subprocess, 'error')]);250- t.is(error.cause, cause);251-});252-253-test('subprocess errors are handled before spawn', async t => {254- const subprocess = execa('forever.js');255- const cause = new Error('test');256- subprocess.emit('error', cause);257- subprocess.kill();258- const error = await t.throwsAsync(subprocess);259- t.is(error.cause, cause);260- t.is(error.exitCode, undefined);261- t.is(error.signal, undefined);262- t.false(error.isTerminated);263-});264-265-test('subprocess errors are handled after spawn', async t => {266- const subprocess = execa('forever.js');267- await once(subprocess, 'spawn');268- const cause = new Error('test');269- subprocess.emit('error', cause);270- subprocess.kill();271- const error = await t.throwsAsync(subprocess);272- t.is(error.cause, cause);273- t.is(error.exitCode, undefined);274- t.is(error.signal, 'SIGTERM');275- t.true(error.isTerminated);276-});277-278-test('subprocess double errors are handled after spawn', async t => {279- const abortController = new AbortController();280- const subprocess = execa('forever.js', {cancelSignal: abortController.signal});281- await once(subprocess, 'spawn');282- const cause = new Error('test');283- subprocess.emit('error', cause);284- await setImmediate();285- abortController.abort();286- const error = await t.throwsAsync(subprocess);287- t.is(error.cause, cause);288- t.is(error.exitCode, undefined);289- t.is(error.signal, 'SIGTERM');290- t.true(error.isTerminated);291-});292-293-test('subprocess errors use killSignal', async t => {294- const subprocess = execa('forever.js', {killSignal: 'SIGINT'});295- await once(subprocess, 'spawn');296- const cause = new Error('test');297- subprocess.emit('error', cause);298- subprocess.kill();299- const error = await t.throwsAsync(subprocess);300- t.is(error.cause, cause);301- t.true(error.isTerminated);302- t.is(error.signal, 'SIGINT');303-});added:test/helpers/file-path.js+4 added
1+import {relative} from 'node:path';2+3+export const getAbsolutePath = file => ({file});4+export const getRelativePath = filePath => ({file: relative('.', filePath)});modified:test/helpers/lines.js+6 added
1 import {Buffer} from 'node:buffer';2+import {execa} from '../../index.js';3 4 const textEncoder = new TextEncoder();5 6 export const stringsToUint8Arrays = strings => strings.map(string => stringToUint8Arrays(string, true));30 unmodified lines37 export const singleComplexUint8Array = textEncoder.encode(complexFull);38 export const singleComplexHex = complexFullBuffer.toString('hex');39 export const complexChunksEnd = ['\n', 'aaa\r\n', 'bbb\n', '\n', 'ccc'];40 export const complexChunks = ['', 'aaa', 'bbb', '', 'ccc'];41+export const singleFull = 'aaa';42+export const singleFullEnd = `${singleFull}\n`;43+44+export const getSimpleChunkSubprocessAsync = options => getSimpleChunkSubprocess(execa, options);45+export const getSimpleChunkSubprocess = (execaMethod, options) => execaMethod('noop-fd.js', ['1', simpleFull], {lines: true, ...options});added:test/helpers/pipe.js+26 added
1+export const assertPipeError = async (t, pipePromise, message) => {2+ const error = await t.throwsAsync(pipePromise);3+4+ t.is(error.command, 'source.pipe(destination)');5+ t.is(error.escapedCommand, error.command);6+7+ t.is(typeof error.cwd, 'string');8+ t.true(error.failed);9+ t.false(error.timedOut);10+ t.false(error.isCanceled);11+ t.false(error.isTerminated);12+ t.is(error.exitCode, undefined);13+ t.is(error.signal, undefined);14+ t.is(error.signalDescription, undefined);15+ t.is(error.stdout, undefined);16+ t.is(error.stderr, undefined);17+ t.is(error.all, undefined);18+ t.deepEqual(error.stdio, Array.from({length: error.stdio.length}));19+ t.deepEqual(error.pipedFrom, []);20+21+ t.true(error.shortMessage.includes(`Command failed: ${error.command}`));22+ t.true(error.shortMessage.includes(error.originalMessage));23+ t.true(error.message.includes(error.shortMessage));24+25+ t.true(error.originalMessage.includes(message));26+};added:test/helpers/wait.js+17 added
1+import {getStdio} from '../helpers/stdio.js';2+import {noopGenerator} from '../helpers/generator.js';3+4+export const endOptionStream = ({stream}) => {5+ stream.end();6+};7+8+export const destroyOptionStream = ({stream, error}) => {9+ stream.destroy(error);10+};11+12+export const destroySubprocessStream = ({subprocess, fdNumber, error}) => {13+ subprocess.stdio[fdNumber].destroy(error);14+};15+16+export const getStreamStdio = (fdNumber, stream, useTransform) =>17+ getStdio(fdNumber, [stream, useTransform ? noopGenerator(false) : 'pipe']);deleted:test/pipe/template.js-272 removed
1-import {spawn} from 'node:child_process';2-import {pathToFileURL} from 'node:url';3-import test from 'ava';4-import {$, execa} from '../../index.js';5-import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';6-import {foobarString} from '../helpers/input.js';7-8-setFixtureDir();9-10-test('$.pipe(subprocess)', async t => {11- const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);12- t.is(stdout, foobarString);13-});14-15-test('execa.$.pipe(subprocess)', async t => {16- const {stdout} = await execa('noop.js', [foobarString]).pipe($({stdin: 'pipe'})`stdin.js`);17- t.is(stdout, foobarString);18-});19-20-test('$.pipe.pipe(subprocess)', async t => {21- const {stdout} = await $`noop.js ${foobarString}`22- .pipe($({stdin: 'pipe'})`stdin.js`)23- .pipe($({stdin: 'pipe'})`stdin.js`);24- t.is(stdout, foobarString);25-});26-27-test('$.pipe`command`', async t => {28- const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;29- t.is(stdout, foobarString);30-});31-32-test('execa.$.pipe`command`', async t => {33- const {stdout} = await execa('noop.js', [foobarString]).pipe`stdin.js`;34- t.is(stdout, foobarString);35-});36-37-test('$.pipe.pipe`command`', async t => {38- const {stdout} = await $`noop.js ${foobarString}`39- .pipe`stdin.js`40- .pipe`stdin.js`;41- t.is(stdout, foobarString);42-});43-44-test('$.pipe("file")', async t => {45- const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js');46- t.is(stdout, foobarString);47-});48-49-test('execa.$.pipe("file")`', async t => {50- const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js');51- t.is(stdout, foobarString);52-});53-54-test('$.pipe.pipe("file")', async t => {55- const {stdout} = await $`noop.js ${foobarString}`56- .pipe`stdin.js`57- .pipe('stdin.js');58- t.is(stdout, foobarString);59-});60-61-test('execa.$.pipe(fileUrl)`', async t => {62- const {stdout} = await execa('noop.js', [foobarString]).pipe(pathToFileURL(`${FIXTURES_DIR}/stdin.js`));63- t.is(stdout, foobarString);64-});65-66-test('$.pipe("file", args, options)', async t => {67- const {stdout} = await $`noop.js ${foobarString}`.pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});68- t.is(stdout, foobarString);69-});70-71-test('execa.$.pipe("file", args, options)`', async t => {72- const {stdout} = await execa('noop.js', [foobarString]).pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});73- t.is(stdout, foobarString);74-});75-76-test('$.pipe.pipe("file", args, options)', async t => {77- const {stdout} = await $`noop.js ${foobarString}`78- .pipe`stdin.js`79- .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});80- t.is(stdout, foobarString);81-});82-83-test('$.pipe(subprocess, pipeOptions)', async t => {84- const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});85- t.is(stdout, foobarString);86-});87-88-test('execa.$.pipe(subprocess, pipeOptions)', async t => {89- const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});90- t.is(stdout, foobarString);91-});92-93-test('$.pipe.pipe(subprocess, pipeOptions)', async t => {94- const {stdout} = await $`noop-fd.js 2 ${foobarString}`95- .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})96- .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});97- t.is(stdout, foobarString);98-});99-100-test('$.pipe(pipeOptions)`command`', async t => {101- const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;102- t.is(stdout, foobarString);103-});104-105-test('execa.$.pipe(pipeOptions)`command`', async t => {106- const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe({from: 'stderr'})`stdin.js`;107- t.is(stdout, foobarString);108-});109-110-test('$.pipe.pipe(pipeOptions)`command`', async t => {111- const {stdout} = await $`noop-fd.js 2 ${foobarString}`112- .pipe({from: 'stderr'})`noop-stdin-fd.js 2`113- .pipe({from: 'stderr'})`stdin.js`;114- t.is(stdout, foobarString);115-});116-117-test('$.pipe("file", pipeOptions)', async t => {118- const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe('stdin.js', {from: 'stderr'});119- t.is(stdout, foobarString);120-});121-122-test('execa.$.pipe("file", pipeOptions)', async t => {123- const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe('stdin.js', {from: 'stderr'});124- t.is(stdout, foobarString);125-});126-127-test('$.pipe.pipe("file", pipeOptions)', async t => {128- const {stdout} = await $`noop-fd.js 2 ${foobarString}`129- .pipe({from: 'stderr'})`noop-stdin-fd.js 2`130- .pipe('stdin.js', {from: 'stderr'});131- t.is(stdout, foobarString);132-});133-134-test('$.pipe(options)`command`', async t => {135- const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;136- t.is(stdout, `${foobarString}\n`);137-});138-139-test('execa.$.pipe(options)`command`', async t => {140- const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})`stdin.js`;141- t.is(stdout, `${foobarString}\n`);142-});143-144-test('$.pipe.pipe(options)`command`', async t => {145- const {stdout} = await $`noop.js ${foobarString}`146- .pipe({})`stdin.js`147- .pipe({stripFinalNewline: false})`stdin.js`;148- t.is(stdout, `${foobarString}\n`);149-});150-151-test('$.pipe("file", options)', async t => {152- const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js', {stripFinalNewline: false});153- t.is(stdout, `${foobarString}\n`);154-});155-156-test('execa.$.pipe("file", options)', async t => {157- const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stripFinalNewline: false});158- t.is(stdout, `${foobarString}\n`);159-});160-161-test('$.pipe.pipe("file", options)', async t => {162- const {stdout} = await $`noop.js ${foobarString}`163- .pipe({})`stdin.js`164- .pipe('stdin.js', {stripFinalNewline: false});165- t.is(stdout, `${foobarString}\n`);166-});167-168-test('$.pipe(pipeAndSubprocessOptions)`command`', async t => {169- const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;170- t.is(stdout, `${foobarString}\n`);171-});172-173-test('execa.$.pipe(pipeAndSubprocessOptions)`command`', async t => {174- const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;175- t.is(stdout, `${foobarString}\n`);176-});177-178-test('$.pipe.pipe(pipeAndSubprocessOptions)`command`', async t => {179- const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`180- .pipe({from: 'stderr'})`noop-stdin-fd.js 2`181- .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;182- t.is(stdout, `${foobarString}\n`);183-});184-185-test('$.pipe("file", pipeAndSubprocessOptions)', async t => {186- const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});187- t.is(stdout, `${foobarString}\n`);188-});189-190-test('execa.$.pipe("file", pipeAndSubprocessOptions)', async t => {191- const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});192- t.is(stdout, `${foobarString}\n`);193-});194-195-test('$.pipe.pipe("file", pipeAndSubprocessOptions)', async t => {196- const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`197- .pipe({from: 'stderr'})`noop-stdin-fd.js 2`198- .pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});199- t.is(stdout, `${foobarString}\n`);200-});201-202-test('$.pipe(options)(secondOptions)`command`', async t => {203- const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;204- t.is(stdout, foobarString);205-});206-207-test('execa.$.pipe(options)(secondOptions)`command`', async t => {208- const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;209- t.is(stdout, foobarString);210-});211-212-test('$.pipe.pipe(options)(secondOptions)`command`', async t => {213- const {stdout} = await $`noop.js ${foobarString}`214- .pipe({})({})`stdin.js`215- .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;216- t.is(stdout, foobarString);217-});218-219-test('$.pipe`command` forces "stdin: pipe"', async t => {220- const {stdout} = await $`noop.js ${foobarString}`.pipe({stdin: 'ignore'})`stdin.js`;221- t.is(stdout, foobarString);222-});223-224-test('execa.pipe("file") forces "stdin: "pipe"', async t => {225- const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stdin: 'ignore'});226- t.is(stdout, foobarString);227-});228-229-test('execa.pipe(subprocess) does not force "stdin: pipe"', async t => {230- await t.throwsAsync(231- execa('noop.js', [foobarString]).pipe(execa('stdin.js', {stdin: 'ignore'})),232- {message: /"stdin: 'ignore'" option is incompatible/},233- );234-});235-236-test('$.pipe(options)(subprocess) fails', async t => {237- await t.throwsAsync(238- $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`),239- {message: /Please use \.pipe/},240- );241-});242-243-test('execa.$.pipe(options)(subprocess) fails', async t => {244- await t.throwsAsync(245- execa('empty.js').pipe({stdout: 'pipe'})($`empty.js`),246- {message: /Please use \.pipe/},247- );248-});249-250-test('$.pipe(options)("file") fails', async t => {251- await t.throwsAsync(252- $`empty.js`.pipe({stdout: 'pipe'})('empty.js'),253- {message: /Please use \.pipe/},254- );255-});256-257-test('execa.$.pipe(options)("file") fails', async t => {258- await t.throwsAsync(259- execa('empty.js').pipe({stdout: 'pipe'})('empty.js'),260- {message: /Please use \.pipe/},261- );262-});263-264-const testInvalidPipe = async (t, ...args) => {265- await t.throwsAsync(266- $`empty.js`.pipe(...args),267- {message: /must be a template string/},268- );269-};270-271-test('$.pipe(nonExecaSubprocess) fails', testInvalidPipe, spawn('node', ['--version']));272-test('$.pipe(false) fails', testInvalidPipe, false);added:test/pipe/throw.js+38 added
1+import test from 'ava';2+import {execa} from '../../index.js';3+import {foobarString} from '../helpers/input.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {assertPipeError} from '../helpers/pipe.js';6+7+setFixtureDir();8+9+test('Destination stream is ended when first argument is invalid', async t => {10+ const source = execa('empty.js', {stdout: 'ignore'});11+ const destination = execa('stdin.js');12+ const pipePromise = source.pipe(destination);13+14+ await assertPipeError(t, pipePromise, 'option is incompatible');15+ await source;16+ t.like(await destination, {stdout: ''});17+});18+19+test('Destination stream is ended when first argument is invalid - $', async t => {20+ const pipePromise = execa('empty.js', {stdout: 'ignore'}).pipe`stdin.js`;21+ await assertPipeError(t, pipePromise, 'option is incompatible');22+});23+24+test('Source stream is aborted when second argument is invalid', async t => {25+ const source = execa('noop.js', [foobarString]);26+ const pipePromise = source.pipe(false);27+28+ await assertPipeError(t, pipePromise, 'an Execa subprocess');29+ t.like(await source, {stdout: ''});30+});31+32+test('Both arguments might be invalid', async t => {33+ const source = execa('empty.js', {stdout: 'ignore'});34+ const pipePromise = source.pipe(false);35+36+ await assertPipeError(t, pipePromise, 'an Execa subprocess');37+ t.like(await source, {stdout: undefined});38+});modified:test/pipe/validate.js+212 added-723 removed
1-import {PassThrough} from 'node:stream';1 import {spawn} from 'node:child_process';3-import process from 'node:process';2+import {pathToFileURL} from 'node:url';3 import test from 'ava';5-import {execa} from '../../index.js';6-import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {$, execa} from '../../index.js';5+import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';6 import {foobarString} from '../helpers/input.js';8-import {fullStdio, getStdio} from '../helpers/stdio.js';9-import {getEarlyErrorSubprocess} from '../helpers/early-error.js';7 8 setFixtureDir();9 13-const assertPipeError = async (t, pipePromise, message) => {14- const error = await t.throwsAsync(pipePromise);10+test('$.pipe(subprocess)', async t => {11+ const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);12+ t.is(stdout, foobarString);13+});14 16- t.is(error.command, 'source.pipe(destination)');17- t.is(error.escapedCommand, error.command);15+test('execa.$.pipe(subprocess)', async t => {16+ const {stdout} = await execa('noop.js', [foobarString]).pipe($({stdin: 'pipe'})`stdin.js`);17+ t.is(stdout, foobarString);18+});19 19- t.is(typeof error.cwd, 'string');20- t.true(error.failed);21- t.false(error.timedOut);22- t.false(error.isCanceled);23- t.false(error.isTerminated);24- t.is(error.exitCode, undefined);25- t.is(error.signal, undefined);26- t.is(error.signalDescription, undefined);27- t.is(error.stdout, undefined);28- t.is(error.stderr, undefined);29- t.is(error.all, undefined);30- t.deepEqual(error.stdio, Array.from({length: error.stdio.length}));31- t.deepEqual(error.pipedFrom, []);20+test('$.pipe.pipe(subprocess)', async t => {21+ const {stdout} = await $`noop.js ${foobarString}`22+ .pipe($({stdin: 'pipe'})`stdin.js`)23+ .pipe($({stdin: 'pipe'})`stdin.js`);24+ t.is(stdout, foobarString);25+});26 33- t.true(error.shortMessage.includes(`Command failed: ${error.command}`));34- t.true(error.shortMessage.includes(error.originalMessage));35- t.true(error.message.includes(error.shortMessage));27+test('$.pipe`command`', async t => {28+ const {stdout} = await $`noop.js ${foobarString}`.pipe`stdin.js`;29+ t.is(stdout, foobarString);30+});31 37- t.true(error.originalMessage.includes(message));38-};32+test('execa.$.pipe`command`', async t => {33+ const {stdout} = await execa('noop.js', [foobarString]).pipe`stdin.js`;34+ t.is(stdout, foobarString);35+});36 40-const getMessage = message => Array.isArray(message)41- ? `"${message[0]}: ${message[1]}" option is incompatible`42- : message;37+test('$.pipe.pipe`command`', async t => {38+ const {stdout} = await $`noop.js ${foobarString}`39+ .pipe`stdin.js`40+ .pipe`stdin.js`;41+ t.is(stdout, foobarString);42+});43 44-const testPipeError = async (t, {45- message,46- sourceOptions = {},47- destinationOptions = {},48- getSource = () => execa('empty.js', sourceOptions),49- getDestination = () => execa('empty.js', destinationOptions),50- isScript = false,51- from,52- to,53-}) => {54- const source = getSource();55- const pipePromise = isScript ? source.pipe({from, to})`empty.js` : source.pipe(getDestination(), {from, to});56- await assertPipeError(t, pipePromise, getMessage(message));57-};44+test('$.pipe("file")', async t => {45+ const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js');46+ t.is(stdout, foobarString);47+});48 59-const testNodeStream = async (t, {60- message,61- sourceOptions = {},62- getSource = () => execa('empty.js', sourceOptions),63- from,64- to,65- writable = to !== undefined,66-}) => {67- assertNodeStream({t, message, getSource, from, to, methodName: writable ? 'writable' : 'readable'});68- assertNodeStream({t, message, getSource, from, to, methodName: 'duplex'});69-};49+test('execa.$.pipe("file")`', async t => {50+ const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js');51+ t.is(stdout, foobarString);52+});53 71-const assertNodeStream = ({t, message, getSource, from, to, methodName}) => {72- const error = t.throws(() => {73- getSource()[methodName]({from, to});74- });75- t.true(error.message.includes(getMessage(message)));76-};54+test('$.pipe.pipe("file")', async t => {55+ const {stdout} = await $`noop.js ${foobarString}`56+ .pipe`stdin.js`57+ .pipe('stdin.js');58+ t.is(stdout, foobarString);59+});60 78-const testIterable = async (t, {79- message,80- sourceOptions = {},81- getSource = () => execa('empty.js', sourceOptions),82- from,83-}) => {84- const error = t.throws(() => {85- getSource().iterable({from});86- });87- t.true(error.message.includes(getMessage(message)));88-};61+test('execa.$.pipe(fileUrl)`', async t => {62+ const {stdout} = await execa('noop.js', [foobarString]).pipe(pathToFileURL(`${FIXTURES_DIR}/stdin.js`));63+ t.is(stdout, foobarString);64+});65 90-test('Must set "all" option to "true" to use .pipe("all")', testPipeError, {91- from: 'all',92- message: '"all" option must be true',66+test('$.pipe("file", args, options)', async t => {67+ const {stdout} = await $`noop.js ${foobarString}`.pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});68+ t.is(stdout, foobarString);69 });94-test('Must set "all" option to "true" to use .duplex("all")', testNodeStream, {95- from: 'all',96- message: '"all" option must be true',70+71+test('execa.$.pipe("file", args, options)`', async t => {72+ const {stdout} = await execa('noop.js', [foobarString]).pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});73+ t.is(stdout, foobarString);74 });98-test('Must set "all" option to "true" to use .iterable("all")', testIterable, {99- from: 'all',100- message: '"all" option must be true',75+76+test('$.pipe.pipe("file", args, options)', async t => {77+ const {stdout} = await $`noop.js ${foobarString}`78+ .pipe`stdin.js`79+ .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});80+ t.is(stdout, foobarString);81 });102-test('.pipe() cannot pipe to non-subprocesses', testPipeError, {103- getDestination: () => new PassThrough(),104- message: 'an Execa subprocess',82+83+test('$.pipe(subprocess, pipeOptions)', async t => {84+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});85+ t.is(stdout, foobarString);86 });106-test('.pipe() cannot pipe to non-Execa subprocesses', testPipeError, {107- getDestination: () => spawn('node', ['--version']),108- message: 'an Execa subprocess',87+88+test('execa.$.pipe(subprocess, pipeOptions)', async t => {89+ const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});90+ t.is(stdout, foobarString);91 });110-test('.pipe() "from" option cannot be "stdin"', testPipeError, {111- from: 'stdin',112- message: '"from" must not be',92+93+test('$.pipe.pipe(subprocess, pipeOptions)', async t => {94+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`95+ .pipe($({stdin: 'pipe'})`noop-stdin-fd.js 2`, {from: 'stderr'})96+ .pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});97+ t.is(stdout, foobarString);98 });114-test('.duplex() "from" option cannot be "stdin"', testNodeStream, {115- from: 'stdin',116- message: '"from" must not be',99+100+test('$.pipe(pipeOptions)`command`', async t => {101+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe({from: 'stderr'})`stdin.js`;102+ t.is(stdout, foobarString);103 });118-test('.iterable() "from" option cannot be "stdin"', testIterable, {119- from: 'stdin',120- message: '"from" must not be',104+105+test('execa.$.pipe(pipeOptions)`command`', async t => {106+ const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe({from: 'stderr'})`stdin.js`;107+ t.is(stdout, foobarString);108 });122-test('$.pipe() "from" option cannot be "stdin"', testPipeError, {123- from: 'stdin',124- isScript: true,125- message: '"from" must not be',109+110+test('$.pipe.pipe(pipeOptions)`command`', async t => {111+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`112+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`113+ .pipe({from: 'stderr'})`stdin.js`;114+ t.is(stdout, foobarString);115 });127-test('.pipe() "to" option cannot be "stdout"', testPipeError, {128- to: 'stdout',129- message: '"to" must not be',116+117+test('$.pipe("file", pipeOptions)', async t => {118+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe('stdin.js', {from: 'stderr'});119+ t.is(stdout, foobarString);120 });131-test('.duplex() "to" option cannot be "stdout"', testNodeStream, {132- to: 'stdout',133- message: '"to" must not be',121+122+test('execa.$.pipe("file", pipeOptions)', async t => {123+ const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe('stdin.js', {from: 'stderr'});124+ t.is(stdout, foobarString);125 });135-test('$.pipe() "to" option cannot be "stdout"', testPipeError, {136- to: 'stdout',137- isScript: true,138- message: '"to" must not be',126+127+test('$.pipe.pipe("file", pipeOptions)', async t => {128+ const {stdout} = await $`noop-fd.js 2 ${foobarString}`129+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`130+ .pipe('stdin.js', {from: 'stderr'});131+ t.is(stdout, foobarString);132 });140-test('.pipe() "from" option cannot be any string', testPipeError, {141- from: 'other',142- message: 'must be "stdout", "stderr", "all"',133+134+test('$.pipe(options)`command`', async t => {135+ const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;136+ t.is(stdout, `${foobarString}\n`);137 });144-test('.duplex() "from" option cannot be any string', testNodeStream, {145- from: 'other',146- message: 'must be "stdout", "stderr", "all"',138+139+test('execa.$.pipe(options)`command`', async t => {140+ const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})`stdin.js`;141+ t.is(stdout, `${foobarString}\n`);142 });148-test('.iterable() "from" option cannot be any string', testIterable, {149- from: 'other',150- message: 'must be "stdout", "stderr", "all"',143+144+test('$.pipe.pipe(options)`command`', async t => {145+ const {stdout} = await $`noop.js ${foobarString}`146+ .pipe({})`stdin.js`147+ .pipe({stripFinalNewline: false})`stdin.js`;148+ t.is(stdout, `${foobarString}\n`);149 });152-test('.pipe() "to" option cannot be any string', testPipeError, {153- to: 'other',154- message: 'must be "stdin"',150+151+test('$.pipe("file", options)', async t => {152+ const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js', {stripFinalNewline: false});153+ t.is(stdout, `${foobarString}\n`);154 });156-test('.duplex() "to" option cannot be any string', testNodeStream, {157- to: 'other',158- message: 'must be "stdin"',155+156+test('execa.$.pipe("file", options)', async t => {157+ const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stripFinalNewline: false});158+ t.is(stdout, `${foobarString}\n`);159 });160-test('.pipe() "from" option cannot be a number without "fd"', testPipeError, {161- from: '1',162- message: 'must be "stdout", "stderr", "all"',160+161+test('$.pipe.pipe("file", options)', async t => {162+ const {stdout} = await $`noop.js ${foobarString}`163+ .pipe({})`stdin.js`164+ .pipe('stdin.js', {stripFinalNewline: false});165+ t.is(stdout, `${foobarString}\n`);166 });164-test('.duplex() "from" option cannot be a number without "fd"', testNodeStream, {165- from: '1',166- message: 'must be "stdout", "stderr", "all"',167+168+test('$.pipe(pipeAndSubprocessOptions)`command`', async t => {169+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;170+ t.is(stdout, `${foobarString}\n`);171 });168-test('.iterable() "from" option cannot be a number without "fd"', testIterable, {169- from: '1',170- message: 'must be "stdout", "stderr", "all"',172+173+test('execa.$.pipe(pipeAndSubprocessOptions)`command`', async t => {174+ const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;175+ t.is(stdout, `${foobarString}\n`);176 });172-test('.pipe() "to" option cannot be a number without "fd"', testPipeError, {173- to: '0',174- message: 'must be "stdin"',177+178+test('$.pipe.pipe(pipeAndSubprocessOptions)`command`', async t => {179+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`180+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`181+ .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;182+ t.is(stdout, `${foobarString}\n`);183 });176-test('.duplex() "to" option cannot be a number without "fd"', testNodeStream, {177- to: '0',178- message: 'must be "stdin"',184+185+test('$.pipe("file", pipeAndSubprocessOptions)', async t => {186+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});187+ t.is(stdout, `${foobarString}\n`);188 });180-test('.pipe() "from" option cannot be just "fd"', testPipeError, {181- from: 'fd',182- message: 'must be "stdout", "stderr", "all"',189+190+test('execa.$.pipe("file", pipeAndSubprocessOptions)', async t => {191+ const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});192+ t.is(stdout, `${foobarString}\n`);193 });184-test('.duplex() "from" option cannot be just "fd"', testNodeStream, {185- from: 'fd',186- message: 'must be "stdout", "stderr", "all"',194+195+test('$.pipe.pipe("file", pipeAndSubprocessOptions)', async t => {196+ const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`197+ .pipe({from: 'stderr'})`noop-stdin-fd.js 2`198+ .pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});199+ t.is(stdout, `${foobarString}\n`);200 });188-test('.iterable() "from" option cannot be just "fd"', testIterable, {189- from: 'fd',190- message: 'must be "stdout", "stderr", "all"',201+202+test('$.pipe(options)(secondOptions)`command`', async t => {203+ const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;204+ t.is(stdout, foobarString);205 });192-test('.pipe() "to" option cannot be just "fd"', testPipeError, {193- to: 'fd',194- message: 'must be "stdin"',206+207+test('execa.$.pipe(options)(secondOptions)`command`', async t => {208+ const {stdout} = await execa('noop.js', [foobarString]).pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;209+ t.is(stdout, foobarString);210 });196-test('.duplex() "to" option cannot be just "fd"', testNodeStream, {197- to: 'fd',198- message: 'must be "stdin"',211+212+test('$.pipe.pipe(options)(secondOptions)`command`', async t => {213+ const {stdout} = await $`noop.js ${foobarString}`214+ .pipe({})({})`stdin.js`215+ .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;216+ t.is(stdout, foobarString);217 });200-test('.pipe() "from" option cannot be a float', testPipeError, {201- from: 'fd1.5',202- message: 'must be "stdout", "stderr", "all"',203-});204-test('.duplex() "from" option cannot be a float', testNodeStream, {205- from: 'fd1.5',206- message: 'must be "stdout", "stderr", "all"',207-});208-test('.iterable() "from" option cannot be a float', testIterable, {209- from: 'fd1.5',210- message: 'must be "stdout", "stderr", "all"',211-});212-test('.pipe() "to" option cannot be a float', testPipeError, {213- to: 'fd1.5',214- message: 'must be "stdin"',215-});216-test('.duplex() "to" option cannot be a float', testNodeStream, {217- to: 'fd1.5',218- message: 'must be "stdin"',219-});220-test('.pipe() "from" option cannot be a negative number', testPipeError, {221- from: 'fd-1',222- message: 'must be "stdout", "stderr", "all"',223-});224-test('.duplex() "from" option cannot be a negative number', testNodeStream, {225- from: 'fd-1',226- message: 'must be "stdout", "stderr", "all"',227-});228-test('.iterable() "from" option cannot be a negative number', testIterable, {229- from: 'fd-1',230- message: 'must be "stdout", "stderr", "all"',231-});232-test('.pipe() "to" option cannot be a negative number', testPipeError, {233- to: 'fd-1',234- message: 'must be "stdin"',235-});236-test('.duplex() "to" option cannot be a negative number', testNodeStream, {237- to: 'fd-1',238- message: 'must be "stdin"',239-});240-test('.pipe() "from" option cannot be a non-existing file descriptor', testPipeError, {241- from: 'fd3',242- message: 'file descriptor does not exist',243-});244-test('.duplex() "from" cannot be a non-existing file descriptor', testNodeStream, {245- from: 'fd3',246- message: 'file descriptor does not exist',247-});248-test('.iterable() "from" cannot be a non-existing file descriptor', testIterable, {249- from: 'fd3',250- message: 'file descriptor does not exist',251-});252-test('.pipe() "to" option cannot be a non-existing file descriptor', testPipeError, {253- to: 'fd3',254- message: 'file descriptor does not exist',255-});256-test('.duplex() "to" cannot be a non-existing file descriptor', testNodeStream, {257- to: 'fd3',258- message: 'file descriptor does not exist',259-});260-test('.pipe() "from" option cannot be an input file descriptor', testPipeError, {261- sourceOptions: getStdio(3, new Uint8Array()),262- from: 'fd3',263- message: 'must be a readable stream',264-});265-test('.duplex() "from" option cannot be an input file descriptor', testNodeStream, {266- sourceOptions: getStdio(3, new Uint8Array()),267- from: 'fd3',268- message: 'must be a readable stream',269-});270-test('.iterable() "from" option cannot be an input file descriptor', testIterable, {271- sourceOptions: getStdio(3, new Uint8Array()),272- from: 'fd3',273- message: 'must be a readable stream',274-});275-test('.pipe() "to" option cannot be an output file descriptor', testPipeError, {276- destinationOptions: fullStdio,277- to: 'fd3',278- message: 'must be a writable stream',279-});280-test('.duplex() "to" option cannot be an output file descriptor', testNodeStream, {281- sourceOptions: fullStdio,282- to: 'fd3',283- message: 'must be a writable stream',284-});285-test('.pipe() "to" option cannot be "all"', testPipeError, {286- destinationOptions: fullStdio,287- to: 'all',288- message: 'must be a writable stream',289-});290-test('.duplex() "to" option cannot be "all"', testNodeStream, {291- sourceOptions: fullStdio,292- to: 'all',293- message: 'must be a writable stream',294-});295-test('Cannot set "stdout" option to "ignore" to use .pipe()', testPipeError, {296- sourceOptions: {stdout: 'ignore'},297- message: ['stdout', '\'ignore\''],298-});299-test('Cannot set "stdout" option to "ignore" to use .duplex()', testNodeStream, {300- sourceOptions: {stdout: 'ignore'},301- message: ['stdout', '\'ignore\''],302-});303-test('Cannot set "stdout" option to "ignore" to use .iterable()', testIterable, {304- sourceOptions: {stdout: 'ignore'},305- message: ['stdout', '\'ignore\''],306-});307-test('Cannot set "stdin" option to "ignore" to use .pipe()', testPipeError, {308- destinationOptions: {stdin: 'ignore'},309- message: ['stdin', '\'ignore\''],310-});311-test('Cannot set "stdin" option to "ignore" to use .duplex()', testNodeStream, {312- sourceOptions: {stdin: 'ignore'},313- message: ['stdin', '\'ignore\''],314- writable: true,315-});316-test('Cannot set "stdout" option to "ignore" to use .pipe(1)', testPipeError, {317- sourceOptions: {stdout: 'ignore'},318- from: 'fd1',319- message: ['stdout', '\'ignore\''],320-});321-test('Cannot set "stdout" option to "ignore" to use .duplex(1)', testNodeStream, {322- sourceOptions: {stdout: 'ignore'},323- from: 'fd1',324- message: ['stdout', '\'ignore\''],325-});326-test('Cannot set "stdout" option to "ignore" to use .iterable(1)', testIterable, {327- sourceOptions: {stdout: 'ignore'},328- from: 'fd1',329- message: ['stdout', '\'ignore\''],330-});331-test('Cannot set "stdin" option to "ignore" to use .pipe(0)', testPipeError, {332- destinationOptions: {stdin: 'ignore'},333- message: ['stdin', '\'ignore\''],334- to: 'fd0',335-});336-test('Cannot set "stdin" option to "ignore" to use .duplex(0)', testNodeStream, {337- sourceOptions: {stdin: 'ignore'},338- message: ['stdin', '\'ignore\''],339- to: 'fd0',340-});341-test('Cannot set "stdout" option to "ignore" to use .pipe("stdout")', testPipeError, {342- sourceOptions: {stdout: 'ignore'},343- from: 'stdout',344- message: ['stdout', '\'ignore\''],345-});346-test('Cannot set "stdout" option to "ignore" to use .duplex("stdout")', testNodeStream, {347- sourceOptions: {stdout: 'ignore'},348- from: 'stdout',349- message: ['stdout', '\'ignore\''],350-});351-test('Cannot set "stdout" option to "ignore" to use .iterable("stdout")', testIterable, {352- sourceOptions: {stdout: 'ignore'},353- from: 'stdout',354- message: ['stdout', '\'ignore\''],355-});356-test('Cannot set "stdin" option to "ignore" to use .pipe("stdin")', testPipeError, {357- destinationOptions: {stdin: 'ignore'},358- message: ['stdin', '\'ignore\''],359- to: 'stdin',360-});361-test('Cannot set "stdin" option to "ignore" to use .duplex("stdin")', testNodeStream, {362- sourceOptions: {stdin: 'ignore'},363- message: ['stdin', '\'ignore\''],364- to: 'stdin',365-});366-test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe()', testPipeError, {367- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},368- message: ['stdout', '\'ignore\''],369-});370-test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex()', testNodeStream, {371- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},372- message: ['stdout', '\'ignore\''],373-});374-test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable()', testIterable, {375- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},376- message: ['stdout', '\'ignore\''],377-});378-test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(1)', testPipeError, {379- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},380- from: 'fd1',381- message: ['stdout', '\'ignore\''],382-});383-test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex(1)', testNodeStream, {384- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},385- from: 'fd1',386- message: ['stdout', '\'ignore\''],387-});388-test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable(1)', testIterable, {389- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},390- from: 'fd1',391- message: ['stdout', '\'ignore\''],392-});393-test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stdout")', testPipeError, {394- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},395- from: 'stdout',396- message: ['stdout', '\'ignore\''],397-});398-test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex("stdout")', testNodeStream, {399- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},400- from: 'stdout',401- message: ['stdout', '\'ignore\''],402-});403-test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable("stdout")', testIterable, {404- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},405- from: 'stdout',406- message: ['stdout', '\'ignore\''],407-});408-test('Cannot set "stdio[1]" option to "ignore" to use .pipe()', testPipeError, {409- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},410- message: ['stdio[1]', '\'ignore\''],411-});412-test('Cannot set "stdio[1]" option to "ignore" to use .duplex()', testNodeStream, {413- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},414- message: ['stdio[1]', '\'ignore\''],415-});416-test('Cannot set "stdio[1]" option to "ignore" to use .iterable()', testIterable, {417- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},418- message: ['stdio[1]', '\'ignore\''],419-});420-test('Cannot set "stdio[0]" option to "ignore" to use .pipe()', testPipeError, {421- destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},422- message: ['stdio[0]', '\'ignore\''],423-});424-test('Cannot set "stdio[0]" option to "ignore" to use .duplex()', testNodeStream, {425- sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},426- message: ['stdio[0]', '\'ignore\''],427- writable: true,428-});429-test('Cannot set "stdio[1]" option to "ignore" to use .pipe(1)', testPipeError, {430- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},431- from: 'fd1',432- message: ['stdio[1]', '\'ignore\''],433-});434-test('Cannot set "stdio[1]" option to "ignore" to use .duplex(1)', testNodeStream, {435- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},436- from: 'fd1',437- message: ['stdio[1]', '\'ignore\''],438-});439-test('Cannot set "stdio[1]" option to "ignore" to use .iterable(1)', testIterable, {440- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},441- from: 'fd1',442- message: ['stdio[1]', '\'ignore\''],443-});444-test('Cannot set "stdio[0]" option to "ignore" to use .pipe(0)', testPipeError, {445- destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},446- message: ['stdio[0]', '\'ignore\''],447- to: 'fd0',448-});449-test('Cannot set "stdio[0]" option to "ignore" to use .duplex(0)', testNodeStream, {450- sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},451- message: ['stdio[0]', '\'ignore\''],452- to: 'fd0',453-});454-test('Cannot set "stdio[1]" option to "ignore" to use .pipe("stdout")', testPipeError, {455- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},456- from: 'stdout',457- message: ['stdio[1]', '\'ignore\''],458-});459-test('Cannot set "stdio[1]" option to "ignore" to use .duplex("stdout")', testNodeStream, {460- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},461- from: 'stdout',462- message: ['stdio[1]', '\'ignore\''],463-});464-test('Cannot set "stdio[1]" option to "ignore" to use .iterable("stdout")', testIterable, {465- sourceOptions: {stdio: ['pipe', 'ignore', 'pipe']},466- from: 'stdout',467- message: ['stdio[1]', '\'ignore\''],468-});469-test('Cannot set "stdio[0]" option to "ignore" to use .pipe("stdin")', testPipeError, {470- destinationOptions: {stdio: ['ignore', 'pipe', 'pipe']},471- message: ['stdio[0]', '\'ignore\''],472- to: 'stdin',473-});474-test('Cannot set "stdio[0]" option to "ignore" to use .duplex("stdin")', testNodeStream, {475- sourceOptions: {stdio: ['ignore', 'pipe', 'pipe']},476- message: ['stdio[0]', '\'ignore\''],477- to: 'stdin',478-});479-test('Cannot set "stderr" option to "ignore" to use .pipe(2)', testPipeError, {480- sourceOptions: {stderr: 'ignore'},481- from: 'fd2',482- message: ['stderr', '\'ignore\''],483-});484-test('Cannot set "stderr" option to "ignore" to use .duplex(2)', testNodeStream, {485- sourceOptions: {stderr: 'ignore'},486- from: 'fd2',487- message: ['stderr', '\'ignore\''],488-});489-test('Cannot set "stderr" option to "ignore" to use .iterable(2)', testIterable, {490- sourceOptions: {stderr: 'ignore'},491- from: 'fd2',492- message: ['stderr', '\'ignore\''],493-});494-test('Cannot set "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {495- sourceOptions: {stderr: 'ignore'},496- from: 'stderr',497- message: ['stderr', '\'ignore\''],498-});499-test('Cannot set "stderr" option to "ignore" to use .duplex("stderr")', testNodeStream, {500- sourceOptions: {stderr: 'ignore'},501- from: 'stderr',502- message: ['stderr', '\'ignore\''],503-});504-test('Cannot set "stderr" option to "ignore" to use .iterable("stderr")', testIterable, {505- sourceOptions: {stderr: 'ignore'},506- from: 'stderr',507- message: ['stderr', '\'ignore\''],508-});509-test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe(2)', testPipeError, {510- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},511- from: 'fd2',512- message: ['stderr', '\'ignore\''],513-});514-test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex(2)', testNodeStream, {515- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},516- from: 'fd2',517- message: ['stderr', '\'ignore\''],518-});519-test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable(2)', testIterable, {520- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},521- from: 'fd2',522- message: ['stderr', '\'ignore\''],523-});524-test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("stderr")', testPipeError, {525- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},526- from: 'stderr',527- message: ['stderr', '\'ignore\''],528-});529-test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex("stderr")', testNodeStream, {530- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},531- from: 'stderr',532- message: ['stderr', '\'ignore\''],533-});534-test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable("stderr")', testIterable, {535- sourceOptions: {stdout: 'ignore', stderr: 'ignore'},536- from: 'stderr',537- message: ['stderr', '\'ignore\''],538-});539-test('Cannot set "stdio[2]" option to "ignore" to use .pipe(2)', testPipeError, {540- sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},541- from: 'fd2',542- message: ['stdio[2]', '\'ignore\''],543-});544-test('Cannot set "stdio[2]" option to "ignore" to use .duplex(2)', testNodeStream, {545- sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},546- from: 'fd2',547- message: ['stdio[2]', '\'ignore\''],548-});549-test('Cannot set "stdio[2]" option to "ignore" to use .iterable(2)', testIterable, {550- sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},551- from: 'fd2',552- message: ['stdio[2]', '\'ignore\''],553-});554-test('Cannot set "stdio[2]" option to "ignore" to use .pipe("stderr")', testPipeError, {555- sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},556- from: 'stderr',557- message: ['stdio[2]', '\'ignore\''],558-});559-test('Cannot set "stdio[2]" option to "ignore" to use .duplex("stderr")', testNodeStream, {560- sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},561- from: 'stderr',562- message: ['stdio[2]', '\'ignore\''],563-});564-test('Cannot set "stdio[2]" option to "ignore" to use .iterable("stderr")', testIterable, {565- sourceOptions: {stdio: ['pipe', 'pipe', 'ignore']},566- from: 'stderr',567- message: ['stdio[2]', '\'ignore\''],568-});569-test('Cannot set "stdio[3]" option to "ignore" to use .pipe(3)', testPipeError, {570- sourceOptions: getStdio(3, 'ignore'),571- from: 'fd3',572- message: ['stdio[3]', '\'ignore\''],573-});574-test('Cannot set "stdio[3]" option to "ignore" to use .duplex(3)', testNodeStream, {575- sourceOptions: getStdio(3, 'ignore'),576- from: 'fd3',577- message: ['stdio[3]', '\'ignore\''],578-});579-test('Cannot set "stdio[3]" option to "ignore" to use .iterable(3)', testIterable, {580- sourceOptions: getStdio(3, 'ignore'),581- from: 'fd3',582- message: ['stdio[3]', '\'ignore\''],583-});584-test('Cannot set "stdout" + "stderr" option to "ignore" to use .pipe("all")', testPipeError, {585- sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},586- from: 'all',587- message: ['stdout', '\'ignore\''],588-});589-test('Cannot set "stdout" + "stderr" option to "ignore" to use .duplex("all")', testNodeStream, {590- sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},591- from: 'all',592- message: ['stdout', '\'ignore\''],593-});594-test('Cannot set "stdout" + "stderr" option to "ignore" to use .iterable("all")', testIterable, {595- sourceOptions: {stdout: 'ignore', stderr: 'ignore', all: true},596- from: 'all',597- message: ['stdout', '\'ignore\''],598-});599-test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .pipe("all")', testPipeError, {600- sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},601- from: 'all',602- message: ['stdio[1]', '\'ignore\''],603-});604-test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .duplex("all")', testNodeStream, {605- sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},606- from: 'all',607- message: ['stdio[1]', '\'ignore\''],608-});609-test('Cannot set "stdio[1]" + "stdio[2]" option to "ignore" to use .iterable("all")', testIterable, {610- sourceOptions: {stdio: ['pipe', 'ignore', 'ignore'], all: true},611- from: 'all',612- message: ['stdio[1]', '\'ignore\''],613-});614-test('Cannot set "stdout" option to "inherit" to use .pipe()', testPipeError, {615- sourceOptions: {stdout: 'inherit'},616- message: ['stdout', '\'inherit\''],617-});618-test('Cannot set "stdout" option to "inherit" to use .duplex()', testNodeStream, {619- sourceOptions: {stdout: 'inherit'},620- message: ['stdout', '\'inherit\''],621-});622-test('Cannot set "stdout" option to "inherit" to use .iterable()', testIterable, {623- sourceOptions: {stdout: 'inherit'},624- message: ['stdout', '\'inherit\''],625-});626-test('Cannot set "stdin" option to "inherit" to use .pipe()', testPipeError, {627- destinationOptions: {stdin: 'inherit'},628- message: ['stdin', '\'inherit\''],629-});630-test('Cannot set "stdin" option to "inherit" to use .duplex()', testNodeStream, {631- sourceOptions: {stdin: 'inherit'},632- message: ['stdin', '\'inherit\''],633- writable: true,634-});635-test('Cannot set "stdout" option to "ipc" to use .pipe()', testPipeError, {636- sourceOptions: {stdout: 'ipc'},637- message: ['stdout', '\'ipc\''],638-});639-test('Cannot set "stdout" option to "ipc" to use .duplex()', testNodeStream, {640- sourceOptions: {stdout: 'ipc'},641- message: ['stdout', '\'ipc\''],642-});643-test('Cannot set "stdout" option to "ipc" to use .iterable()', testIterable, {644- sourceOptions: {stdout: 'ipc'},645- message: ['stdout', '\'ipc\''],646-});647-test('Cannot set "stdin" option to "ipc" to use .pipe()', testPipeError, {648- destinationOptions: {stdin: 'ipc'},649- message: ['stdin', '\'ipc\''],650-});651-test('Cannot set "stdin" option to "ipc" to use .duplex()', testNodeStream, {652- sourceOptions: {stdin: 'ipc'},653- message: ['stdin', '\'ipc\''],654- writable: true,655-});656-test('Cannot set "stdout" option to file descriptors to use .pipe()', testPipeError, {657- sourceOptions: {stdout: 1},658- message: ['stdout', '1'],659-});660-test('Cannot set "stdout" option to file descriptors to use .duplex()', testNodeStream, {661- sourceOptions: {stdout: 1},662- message: ['stdout', '1'],663-});664-test('Cannot set "stdout" option to file descriptors to use .iterable()', testIterable, {665- sourceOptions: {stdout: 1},666- message: ['stdout', '1'],667-});668-test('Cannot set "stdin" option to file descriptors to use .pipe()', testPipeError, {669- destinationOptions: {stdin: 0},670- message: ['stdin', '0'],671-});672-test('Cannot set "stdin" option to file descriptors to use .duplex()', testNodeStream, {673- sourceOptions: {stdin: 0},674- message: ['stdin', '0'],675- writable: true,676-});677-test('Cannot set "stdout" option to Node.js streams to use .pipe()', testPipeError, {678- sourceOptions: {stdout: process.stdout},679- message: ['stdout', 'Stream'],680-});681-test('Cannot set "stdout" option to Node.js streams to use .duplex()', testNodeStream, {682- sourceOptions: {stdout: process.stdout},683- message: ['stdout', 'Stream'],684-});685-test('Cannot set "stdout" option to Node.js streams to use .iterable()', testIterable, {686- sourceOptions: {stdout: process.stdout},687- message: ['stdout', 'Stream'],688-});689-test('Cannot set "stdin" option to Node.js streams to use .pipe()', testPipeError, {690- destinationOptions: {stdin: process.stdin},691- message: ['stdin', 'Stream'],692-});693-test('Cannot set "stdin" option to Node.js streams to use .duplex()', testNodeStream, {694- sourceOptions: {stdin: process.stdin},695- message: ['stdin', 'Stream'],696- writable: true,697-});698-test('Cannot set "stdio[3]" option to Node.js Writable streams to use .pipe()', testPipeError, {699- sourceOptions: getStdio(3, process.stdout),700- message: ['stdio[3]', 'Stream'],701- from: 'fd3',702-});703-test('Cannot set "stdio[3]" option to Node.js Writable streams to use .duplex()', testNodeStream, {704- sourceOptions: getStdio(3, process.stdout),705- message: ['stdio[3]', 'Stream'],706- from: 'fd3',707-});708-test('Cannot set "stdio[3]" option to Node.js Writable streams to use .iterable()', testIterable, {709- sourceOptions: getStdio(3, process.stdout),710- message: ['stdio[3]', 'Stream'],711- from: 'fd3',712-});713-test('Cannot set "stdio[3]" option to Node.js Readable streams to use .pipe()', testPipeError, {714- destinationOptions: getStdio(3, process.stdin),715- message: ['stdio[3]', 'Stream'],716- to: 'fd3',717-});718-test('Cannot set "stdio[3]" option to Node.js Readable streams to use .duplex()', testNodeStream, {719- sourceOptions: getStdio(3, process.stdin),720- message: ['stdio[3]', 'Stream'],721- to: 'fd3',722-});218 724-test('Destination stream is ended when first argument is invalid', async t => {725- const source = execa('empty.js', {stdout: 'ignore'});726- const destination = execa('stdin.js');727- const pipePromise = source.pipe(destination);728-729- await assertPipeError(t, pipePromise, 'option is incompatible');730- await source;731- t.like(await destination, {stdout: ''});219+test('$.pipe`command` forces "stdin: pipe"', async t => {220+ const {stdout} = await $`noop.js ${foobarString}`.pipe({stdin: 'ignore'})`stdin.js`;221+ t.is(stdout, foobarString);222 });223 734-test('Destination stream is ended when first argument is invalid - $', async t => {735- const pipePromise = execa('empty.js', {stdout: 'ignore'}).pipe`stdin.js`;736- await assertPipeError(t, pipePromise, 'option is incompatible');224+test('execa.pipe("file") forces "stdin: "pipe"', async t => {225+ const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stdin: 'ignore'});226+ t.is(stdout, foobarString);227 });228 739-test('Source stream is aborted when second argument is invalid', async t => {740- const source = execa('noop.js', [foobarString]);741- const pipePromise = source.pipe(false);742-743- await assertPipeError(t, pipePromise, 'an Execa subprocess');744- t.like(await source, {stdout: ''});229+test('execa.pipe(subprocess) does not force "stdin: pipe"', async t => {230+ await t.throwsAsync(231+ execa('noop.js', [foobarString]).pipe(execa('stdin.js', {stdin: 'ignore'})),232+ {message: /"stdin: 'ignore'" option is incompatible/},233+ );234 });235 747-test('Both arguments might be invalid', async t => {748- const source = execa('empty.js', {stdout: 'ignore'});749- const pipePromise = source.pipe(false);750-751- await assertPipeError(t, pipePromise, 'an Execa subprocess');752- t.like(await source, {stdout: undefined});236+test('$.pipe(options)(subprocess) fails', async t => {237+ await t.throwsAsync(238+ $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`),239+ {message: /Please use \.pipe/},240+ );241 });242 755-test('Sets the right error message when the "all" option is incompatible - execa.$', async t => {756- await assertPipeError(757- t,758- execa('empty.js')759- .pipe({all: false})`stdin.js`760- .pipe(execa('empty.js'), {from: 'all'}),761- '"all" option must be true',243+test('execa.$.pipe(options)(subprocess) fails', async t => {244+ await t.throwsAsync(245+ execa('empty.js').pipe({stdout: 'pipe'})($`empty.js`),246+ {message: /Please use \.pipe/},247 );248 });249 765-test('Sets the right error message when the "all" option is incompatible - execa.execa', async t => {766- await assertPipeError(767- t,768- execa('empty.js')769- .pipe(execa('stdin.js', {all: false}))770- .pipe(execa('empty.js'), {from: 'all'}),771- '"all" option must be true',250+test('$.pipe(options)("file") fails', async t => {251+ await t.throwsAsync(252+ $`empty.js`.pipe({stdout: 'pipe'})('empty.js'),253+ {message: /Please use \.pipe/},254 );255 });256 775-test('Sets the right error message when the "all" option is incompatible - early error', async t => {776- await assertPipeError(777- t,778- getEarlyErrorSubprocess()779- .pipe(execa('stdin.js', {all: false}))780- .pipe(execa('empty.js'), {from: 'all'}),781- '"all" option must be true',257+test('execa.$.pipe(options)("file") fails', async t => {258+ await t.throwsAsync(259+ execa('empty.js').pipe({stdout: 'pipe'})('empty.js'),260+ {message: /Please use \.pipe/},261 );262 });263+264+const testInvalidPipe = async (t, ...args) => {265+ await t.throwsAsync(266+ $`empty.js`.pipe(...args),267+ {message: /must be a template string/},268+ );269+};270+271+test('$.pipe(nonExecaSubprocess) fails', testInvalidPipe, spawn('node', ['--version']));272+test('$.pipe(false) fails', testInvalidPipe, false);modified:test/return/error.js+1 added-86 removed
1 import process from 'node:process';2 import test from 'ava';3 import {execa, execaSync} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5-import {fullStdio, getStdio} from '../helpers/stdio.js';6-import {foobarString} from '../helpers/input.js';7-import {QUOTE} from '../helpers/verbose.js';8-import {noopGenerator, outputObjectGenerator} from '../helpers/generator.js';5+import {fullStdio} from '../helpers/stdio.js';6 7 const isWindows = process.platform === 'win32';8 9 setFixtureDir();53 unmodified lines63 64 test('Error properties are not missing and are ordered', testErrorShape, execa);65 test('Error properties are not missing and are ordered, sync', testErrorShape, execaSync);66 70-test('error.message contains the command', async t => {71- await t.throwsAsync(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});72-});73-74-// eslint-disable-next-line max-params75-const testStdioMessage = async (t, encoding, all, objectMode, execaMethod) => {76- const {exitCode, message} = await execaMethod('echo-fail.js', {...getStdio(1, noopGenerator(objectMode, false, true), 4), encoding, all, reject: false});77- t.is(exitCode, 1);78- const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';79- t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));80-};81-82-test('error.message contains stdout/stderr/stdio if available', testStdioMessage, 'utf8', false, false, execa);83-test('error.message contains stdout/stderr/stdio even with encoding "buffer"', testStdioMessage, 'buffer', false, false, execa);84-test('error.message contains all if available', testStdioMessage, 'utf8', true, false, execa);85-test('error.message contains all even with encoding "buffer"', testStdioMessage, 'buffer', true, false, execa);86-test('error.message contains stdout/stderr/stdio if available, objectMode', testStdioMessage, 'utf8', false, true, execa);87-test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true, execa);88-test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true, execa);89-test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true, execa);90-test('error.message contains stdout/stderr/stdio if available, sync', testStdioMessage, 'utf8', false, false, execaSync);91-test('error.message contains stdout/stderr/stdio even with encoding "buffer", sync', testStdioMessage, 'buffer', false, false, execaSync);92-test('error.message contains all if available, sync', testStdioMessage, 'utf8', true, false, execaSync);93-test('error.message contains all even with encoding "buffer", sync', testStdioMessage, 'buffer', true, false, execaSync);94-test('error.message contains stdout/stderr/stdio if available, objectMode, sync', testStdioMessage, 'utf8', false, true, execaSync);95-test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', false, true, execaSync);96-test('error.message contains all if available, objectMode, sync', testStdioMessage, 'utf8', true, true, execaSync);97-test('error.message contains all even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', true, true, execaSync);98-99-const testLinesMessage = async (t, encoding, stripFinalNewline, execaMethod) => {100- const {failed, message} = await execaMethod('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {101- lines: true,102- encoding,103- stripFinalNewline,104- reject: false,105- });106- t.true(failed);107- t.true(message.endsWith(`noop-fail.js 1 ${QUOTE}${foobarString}\\n${foobarString}\\n${QUOTE}\n\n${foobarString}\n${foobarString}`));108-};109-110-test('error.message handles "lines: true"', testLinesMessage, 'utf8', false, execa);111-test('error.message handles "lines: true", stripFinalNewline', testLinesMessage, 'utf8', true, execa);112-test('error.message handles "lines: true", buffer', testLinesMessage, 'buffer', false, execa);113-test('error.message handles "lines: true", buffer, stripFinalNewline', testLinesMessage, 'buffer', true, execa);114-test('error.message handles "lines: true", sync', testLinesMessage, 'utf8', false, execaSync);115-test('error.message handles "lines: true", stripFinalNewline, sync', testLinesMessage, 'utf8', true, execaSync);116-test('error.message handles "lines: true", buffer, sync', testLinesMessage, 'buffer', false, execaSync);117-test('error.message handles "lines: true", buffer, stripFinalNewline, sync', testLinesMessage, 'buffer', true, execaSync);118-119-const testPartialIgnoreMessage = async (t, fdNumber, stdioOption, output) => {120- const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));121- t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));122-};123-124-test('error.message does not contain stdout if not available', testPartialIgnoreMessage, 1, 'ignore', 'stderr');125-test('error.message does not contain stderr if not available', testPartialIgnoreMessage, 2, 'ignore', 'stdout');126-test('error.message does not contain stdout if it is an object', testPartialIgnoreMessage, 1, outputObjectGenerator(), 'stderr');127-test('error.message does not contain stderr if it is an object', testPartialIgnoreMessage, 2, outputObjectGenerator(), 'stdout');128-129-const testFullIgnoreMessage = async (t, options, resultProperty) => {130- const {[resultProperty]: message} = await t.throwsAsync(execa('echo-fail.js', options));131- t.false(message.includes('stderr'));132- t.false(message.includes('stdout'));133- t.false(message.includes('fd3'));134-};135-136-test('error.message does not contain stdout/stderr/stdio if not available', testFullIgnoreMessage, {stdio: 'ignore'}, 'message');137-test('error.shortMessage does not contain stdout/stderr/stdio', testFullIgnoreMessage, fullStdio, 'shortMessage');138-139-const testErrorMessageConsistent = async (t, stdout) => {140- const {message} = await t.throwsAsync(execa('noop-both-fail-strict.js', [stdout, 'stderr']));141- t.true(message.endsWith(' stderr\n\nstderr\n\nstdout'));142-};143-144-test('error.message newlines are consistent - no newline', testErrorMessageConsistent, 'stdout');145-test('error.message newlines are consistent - newline', testErrorMessageConsistent, 'stdout\n');146-147-test('Original error.message is kept', async t => {148- const {originalMessage} = await t.throwsAsync(execa('noop.js', {uid: true}));149- t.is(originalMessage, 'The "options.uid" property must be int32. Received type boolean (true)');150-});151-67 test('failed is false on success', async t => {68 const {failed} = await execa('noop.js', ['foo']);69 t.false(failed);70 });75 unmodified linesadded:test/return/message.js+91 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {fullStdio, getStdio} from '../helpers/stdio.js';5+import {foobarString} from '../helpers/input.js';6+import {QUOTE} from '../helpers/verbose.js';7+import {noopGenerator, outputObjectGenerator} from '../helpers/generator.js';8+9+setFixtureDir();10+11+test('error.message contains the command', async t => {12+ await t.throwsAsync(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});13+});14+15+// eslint-disable-next-line max-params16+const testStdioMessage = async (t, encoding, all, objectMode, execaMethod) => {17+ const {exitCode, message} = await execaMethod('echo-fail.js', {...getStdio(1, noopGenerator(objectMode, false, true), 4), encoding, all, reject: false});18+ t.is(exitCode, 1);19+ const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';20+ t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));21+};22+23+test('error.message contains stdout/stderr/stdio if available', testStdioMessage, 'utf8', false, false, execa);24+test('error.message contains stdout/stderr/stdio even with encoding "buffer"', testStdioMessage, 'buffer', false, false, execa);25+test('error.message contains all if available', testStdioMessage, 'utf8', true, false, execa);26+test('error.message contains all even with encoding "buffer"', testStdioMessage, 'buffer', true, false, execa);27+test('error.message contains stdout/stderr/stdio if available, objectMode', testStdioMessage, 'utf8', false, true, execa);28+test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true, execa);29+test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true, execa);30+test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true, execa);31+test('error.message contains stdout/stderr/stdio if available, sync', testStdioMessage, 'utf8', false, false, execaSync);32+test('error.message contains stdout/stderr/stdio even with encoding "buffer", sync', testStdioMessage, 'buffer', false, false, execaSync);33+test('error.message contains all if available, sync', testStdioMessage, 'utf8', true, false, execaSync);34+test('error.message contains all even with encoding "buffer", sync', testStdioMessage, 'buffer', true, false, execaSync);35+test('error.message contains stdout/stderr/stdio if available, objectMode, sync', testStdioMessage, 'utf8', false, true, execaSync);36+test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', false, true, execaSync);37+test('error.message contains all if available, objectMode, sync', testStdioMessage, 'utf8', true, true, execaSync);38+test('error.message contains all even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', true, true, execaSync);39+40+const testLinesMessage = async (t, encoding, stripFinalNewline, execaMethod) => {41+ const {failed, message} = await execaMethod('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {42+ lines: true,43+ encoding,44+ stripFinalNewline,45+ reject: false,46+ });47+ t.true(failed);48+ t.true(message.endsWith(`noop-fail.js 1 ${QUOTE}${foobarString}\\n${foobarString}\\n${QUOTE}\n\n${foobarString}\n${foobarString}`));49+};50+51+test('error.message handles "lines: true"', testLinesMessage, 'utf8', false, execa);52+test('error.message handles "lines: true", stripFinalNewline', testLinesMessage, 'utf8', true, execa);53+test('error.message handles "lines: true", buffer', testLinesMessage, 'buffer', false, execa);54+test('error.message handles "lines: true", buffer, stripFinalNewline', testLinesMessage, 'buffer', true, execa);55+test('error.message handles "lines: true", sync', testLinesMessage, 'utf8', false, execaSync);56+test('error.message handles "lines: true", stripFinalNewline, sync', testLinesMessage, 'utf8', true, execaSync);57+test('error.message handles "lines: true", buffer, sync', testLinesMessage, 'buffer', false, execaSync);58+test('error.message handles "lines: true", buffer, stripFinalNewline, sync', testLinesMessage, 'buffer', true, execaSync);59+60+const testPartialIgnoreMessage = async (t, fdNumber, stdioOption, output) => {61+ const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));62+ t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));63+};64+65+test('error.message does not contain stdout if not available', testPartialIgnoreMessage, 1, 'ignore', 'stderr');66+test('error.message does not contain stderr if not available', testPartialIgnoreMessage, 2, 'ignore', 'stdout');67+test('error.message does not contain stdout if it is an object', testPartialIgnoreMessage, 1, outputObjectGenerator(), 'stderr');68+test('error.message does not contain stderr if it is an object', testPartialIgnoreMessage, 2, outputObjectGenerator(), 'stdout');69+70+const testFullIgnoreMessage = async (t, options, resultProperty) => {71+ const {[resultProperty]: message} = await t.throwsAsync(execa('echo-fail.js', options));72+ t.false(message.includes('stderr'));73+ t.false(message.includes('stdout'));74+ t.false(message.includes('fd3'));75+};76+77+test('error.message does not contain stdout/stderr/stdio if not available', testFullIgnoreMessage, {stdio: 'ignore'}, 'message');78+test('error.shortMessage does not contain stdout/stderr/stdio', testFullIgnoreMessage, fullStdio, 'shortMessage');79+80+const testErrorMessageConsistent = async (t, stdout) => {81+ const {message} = await t.throwsAsync(execa('noop-both-fail-strict.js', [stdout, 'stderr']));82+ t.true(message.endsWith(' stderr\n\nstderr\n\nstdout'));83+};84+85+test('error.message newlines are consistent - no newline', testErrorMessageConsistent, 'stdout');86+test('error.message newlines are consistent - newline', testErrorMessageConsistent, 'stdout\n');87+88+test('Original error.message is kept', async t => {89+ const {originalMessage} = await t.throwsAsync(execa('noop.js', {uid: true}));90+ t.is(originalMessage, 'The "options.uid" property must be int32. Received type boolean (true)');91+});modified:test/return/output.js-49 removed
1 import test from 'ava';2 import {execa, execaSync} from '../../index.js';3 import {setFixtureDir} from '../helpers/fixtures-dir.js';4 import {fullStdio, getStdio} from '../helpers/stdio.js';5-import {noopGenerator} from '../helpers/generator.js';5 import {foobarString} from '../helpers/input.js';6 7 setFixtureDir();8 98 unmodified lines107 };108 109 test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);110 test('error.stdout/stderr/stdio is defined, sync', testErrorOutput, execaSync);112-113-// eslint-disable-next-line max-params114-const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, shouldStrip, execaMethod) => {115- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, `${foobarString}\n`], {...fullStdio, stripFinalNewline});116- t.is(stdio[fdNumber], `${foobarString}${shouldStrip ? '' : '\n'}`);117-};118-119-test('stripFinalNewline: default with stdout', testStripFinalNewline, 1, undefined, true, execa);120-test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, true, execa);121-test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, false, execa);122-test('stripFinalNewline: default with stderr', testStripFinalNewline, 2, undefined, true, execa);123-test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, true, execa);124-test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, false, execa);125-test('stripFinalNewline: default with stdio[*]', testStripFinalNewline, 3, undefined, true, execa);126-test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, true, execa);127-test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, false, execa);128-test('stripFinalNewline: default with stdout, fd-specific', testStripFinalNewline, 1, {}, true, execa);129-test('stripFinalNewline: true with stdout, fd-specific', testStripFinalNewline, 1, {stdout: true}, true, execa);130-test('stripFinalNewline: false with stdout, fd-specific', testStripFinalNewline, 1, {stdout: false}, false, execa);131-test('stripFinalNewline: default with stderr, fd-specific', testStripFinalNewline, 2, {}, true, execa);132-test('stripFinalNewline: true with stderr, fd-specific', testStripFinalNewline, 2, {stderr: true}, true, execa);133-test('stripFinalNewline: false with stderr, fd-specific', testStripFinalNewline, 2, {stderr: false}, false, execa);134-test('stripFinalNewline: default with stdio[*], fd-specific', testStripFinalNewline, 3, {}, true, execa);135-test('stripFinalNewline: true with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: true}, true, execa);136-test('stripFinalNewline: false with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: false}, false, execa);137-test('stripFinalNewline: default with stdout, sync', testStripFinalNewline, 1, undefined, true, execaSync);138-test('stripFinalNewline: true with stdout, sync', testStripFinalNewline, 1, true, true, execaSync);139-test('stripFinalNewline: false with stdout, sync', testStripFinalNewline, 1, false, false, execaSync);140-test('stripFinalNewline: default with stderr, sync', testStripFinalNewline, 2, undefined, true, execaSync);141-test('stripFinalNewline: true with stderr, sync', testStripFinalNewline, 2, true, true, execaSync);142-test('stripFinalNewline: false with stderr, sync', testStripFinalNewline, 2, false, false, execaSync);143-test('stripFinalNewline: default with stdio[*], sync', testStripFinalNewline, 3, undefined, true, execaSync);144-test('stripFinalNewline: true with stdio[*], sync', testStripFinalNewline, 3, true, true, execaSync);145-test('stripFinalNewline: false with stdio[*], sync', testStripFinalNewline, 3, false, false, execaSync);146-test('stripFinalNewline: default with stdout, fd-specific, sync', testStripFinalNewline, 1, {}, true, execaSync);147-test('stripFinalNewline: true with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: true}, true, execaSync);148-test('stripFinalNewline: false with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: false}, false, execaSync);149-test('stripFinalNewline: default with stderr, fd-specific, sync', testStripFinalNewline, 2, {}, true, execaSync);150-test('stripFinalNewline: true with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: true}, true, execaSync);151-test('stripFinalNewline: false with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: false}, false, execaSync);152-test('stripFinalNewline: default with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {}, true, execaSync);153-test('stripFinalNewline: true with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: true}, true, execaSync);154-test('stripFinalNewline: false with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: false}, false, execaSync);155-156-test('stripFinalNewline is not used in objectMode', async t => {157- const {stdout} = await execa('noop-fd.js', ['1', `${foobarString}\n`], {stripFinalNewline: true, stdout: noopGenerator(true, false, true)});158- t.deepEqual(stdout, [`${foobarString}\n`]);159-});added:test/return/reject.js+15 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+5+setFixtureDir();6+7+test('skip throwing when using reject option', async t => {8+ const {exitCode} = await execa('fail.js', {reject: false});9+ t.is(exitCode, 2);10+});11+12+test('skip throwing when using reject option in sync mode', t => {13+ const {exitCode} = execaSync('fail.js', {reject: false});14+ t.is(exitCode, 2);15+});added:test/return/strip-newline.js+56 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {fullStdio} from '../helpers/stdio.js';5+import {noopGenerator} from '../helpers/generator.js';6+import {foobarString} from '../helpers/input.js';7+8+setFixtureDir();9+10+// eslint-disable-next-line max-params11+const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, shouldStrip, execaMethod) => {12+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, `${foobarString}\n`], {...fullStdio, stripFinalNewline});13+ t.is(stdio[fdNumber], `${foobarString}${shouldStrip ? '' : '\n'}`);14+};15+16+test('stripFinalNewline: default with stdout', testStripFinalNewline, 1, undefined, true, execa);17+test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, true, execa);18+test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, false, execa);19+test('stripFinalNewline: default with stderr', testStripFinalNewline, 2, undefined, true, execa);20+test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, true, execa);21+test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, false, execa);22+test('stripFinalNewline: default with stdio[*]', testStripFinalNewline, 3, undefined, true, execa);23+test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, true, execa);24+test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, false, execa);25+test('stripFinalNewline: default with stdout, fd-specific', testStripFinalNewline, 1, {}, true, execa);26+test('stripFinalNewline: true with stdout, fd-specific', testStripFinalNewline, 1, {stdout: true}, true, execa);27+test('stripFinalNewline: false with stdout, fd-specific', testStripFinalNewline, 1, {stdout: false}, false, execa);28+test('stripFinalNewline: default with stderr, fd-specific', testStripFinalNewline, 2, {}, true, execa);29+test('stripFinalNewline: true with stderr, fd-specific', testStripFinalNewline, 2, {stderr: true}, true, execa);30+test('stripFinalNewline: false with stderr, fd-specific', testStripFinalNewline, 2, {stderr: false}, false, execa);31+test('stripFinalNewline: default with stdio[*], fd-specific', testStripFinalNewline, 3, {}, true, execa);32+test('stripFinalNewline: true with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: true}, true, execa);33+test('stripFinalNewline: false with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: false}, false, execa);34+test('stripFinalNewline: default with stdout, sync', testStripFinalNewline, 1, undefined, true, execaSync);35+test('stripFinalNewline: true with stdout, sync', testStripFinalNewline, 1, true, true, execaSync);36+test('stripFinalNewline: false with stdout, sync', testStripFinalNewline, 1, false, false, execaSync);37+test('stripFinalNewline: default with stderr, sync', testStripFinalNewline, 2, undefined, true, execaSync);38+test('stripFinalNewline: true with stderr, sync', testStripFinalNewline, 2, true, true, execaSync);39+test('stripFinalNewline: false with stderr, sync', testStripFinalNewline, 2, false, false, execaSync);40+test('stripFinalNewline: default with stdio[*], sync', testStripFinalNewline, 3, undefined, true, execaSync);41+test('stripFinalNewline: true with stdio[*], sync', testStripFinalNewline, 3, true, true, execaSync);42+test('stripFinalNewline: false with stdio[*], sync', testStripFinalNewline, 3, false, false, execaSync);43+test('stripFinalNewline: default with stdout, fd-specific, sync', testStripFinalNewline, 1, {}, true, execaSync);44+test('stripFinalNewline: true with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: true}, true, execaSync);45+test('stripFinalNewline: false with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: false}, false, execaSync);46+test('stripFinalNewline: default with stderr, fd-specific, sync', testStripFinalNewline, 2, {}, true, execaSync);47+test('stripFinalNewline: true with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: true}, true, execaSync);48+test('stripFinalNewline: false with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: false}, false, execaSync);49+test('stripFinalNewline: default with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {}, true, execaSync);50+test('stripFinalNewline: true with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: true}, true, execaSync);51+test('stripFinalNewline: false with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: false}, false, execaSync);52+53+test('stripFinalNewline is not used in objectMode', async t => {54+ const {stdout} = await execa('noop-fd.js', ['1', `${foobarString}\n`], {stripFinalNewline: true, stdout: noopGenerator(true, false, true)});55+ t.deepEqual(stdout, [`${foobarString}\n`]);56+});deleted:test/stdio/async.js-84 removed
1-import {once, defaultMaxListeners} from 'node:events';2-import process from 'node:process';3-import {setImmediate} from 'node:timers/promises';4-import test from 'ava';5-import {execa} from '../../index.js';6-import {STANDARD_STREAMS} from '../helpers/stdio.js';7-import {foobarString} from '../helpers/input.js';8-import {setFixtureDir} from '../helpers/fixtures-dir.js';9-import {assertMaxListeners} from '../helpers/listeners.js';10-11-setFixtureDir();12-13-const getStandardStreamListeners = stream => Object.fromEntries(stream.eventNames().map(eventName => [eventName, stream.listeners(eventName)]));14-const getStandardStreamsListeners = () => STANDARD_STREAMS.map(stream => getStandardStreamListeners(stream));15-16-const getComplexStdio = isMultiple => ({17- stdin: ['pipe', 'inherit', ...(isMultiple ? [0, process.stdin] : [])],18- stdout: ['pipe', 'inherit', ...(isMultiple ? [1, process.stdout] : [])],19- stderr: ['pipe', 'inherit', ...(isMultiple ? [2, process.stderr] : [])],20-});21-22-const onStdinRemoveListener = () => once(process.stdin, 'removeListener');23-24-const testListenersCleanup = async (t, isMultiple) => {25- const streamsPreviousListeners = getStandardStreamsListeners();26- const subprocess = execa('empty.js', getComplexStdio(isMultiple));27- t.notDeepEqual(getStandardStreamsListeners(), streamsPreviousListeners);28- await Promise.all([subprocess, onStdinRemoveListener()]);29- if (isMultiple) {30- await onStdinRemoveListener();31- }32-33- for (const [fdNumber, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {34- const defaultListeners = Object.fromEntries(Reflect.ownKeys(streamNewListeners).map(eventName => [eventName, []]));35- t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[fdNumber]});36- }37-};38-39-test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);40-test.serial('process.std* listeners are cleaned up on success with multiple inputs', testListenersCleanup, true);41-42-const subprocessesCount = 100;43-44-test.serial('Can spawn many subprocesses in parallel', async t => {45- const results = await Promise.all(46- Array.from({length: subprocessesCount}, () => execa('noop.js', [foobarString])),47- );48- t.true(results.every(({stdout}) => stdout === foobarString));49-});50-51-const testMaxListeners = async (t, isMultiple, maxListenersCount) => {52- const checkMaxListeners = assertMaxListeners(t);53-54- for (const standardStream of STANDARD_STREAMS) {55- standardStream.setMaxListeners(maxListenersCount);56- }57-58- try {59- const results = await Promise.all(60- Array.from({length: subprocessesCount}, () => execa('empty.js', getComplexStdio(isMultiple))),61- );62- t.true(results.every(({exitCode}) => exitCode === 0));63- } finally {64- await setImmediate();65- await setImmediate();66- checkMaxListeners();67-68- for (const standardStream of STANDARD_STREAMS) {69- t.is(standardStream.getMaxListeners(), maxListenersCount);70- standardStream.setMaxListeners(defaultMaxListeners);71- }72- }73-};74-75-test.serial('No warning with maxListeners 1 and ["pipe", "inherit"]', testMaxListeners, false, 1);76-test.serial('No warning with maxListeners default and ["pipe", "inherit"]', testMaxListeners, false, defaultMaxListeners);77-test.serial('No warning with maxListeners 100 and ["pipe", "inherit"]', testMaxListeners, false, 100);78-test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"]', testMaxListeners, false, Number.POSITIVE_INFINITY);79-test.serial('No warning with maxListeners 0 and ["pipe", "inherit"]', testMaxListeners, false, 0);80-test.serial('No warning with maxListeners 1 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 1);81-test.serial('No warning with maxListeners default and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, defaultMaxListeners);82-test.serial('No warning with maxListeners 100 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 100);83-test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, Number.POSITIVE_INFINITY);84-test.serial('No warning with maxListeners 0 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 0);modified:test/stdio/encoding-final.js+1 added-110 removed
1 import {Buffer} from 'node:buffer';2 import {exec} from 'node:child_process';3-import process from 'node:process';3 import {promisify} from 'node:util';4 import test from 'ava';5 import getStream from 'get-stream';6 import {execa, execaSync} from '../../index.js';7 import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';8 import {fullStdio} from '../helpers/stdio.js';10-import {outputObjectGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';11-import {foobarString, foobarUint8Array, foobarObject, foobarHex} from '../helpers/input.js';9+import {foobarString, foobarUint8Array, foobarHex} from '../helpers/input.js';10 11 const pExec = promisify(exec);12 13 setFixtureDir();78 unmodified lines92 test('can pass encoding "hex" to stdio[*] - sync', checkEncoding, 'hex', 3, execaSync);93 test('can pass encoding "base64" to stdio[*] - sync', checkEncoding, 'base64', 3, execaSync);94 test('can pass encoding "base64url" to stdio[*] - sync', checkEncoding, 'base64url', 3, execaSync);95 98-const foobarArray = ['fo', 'ob', 'ar', '..'];99-100-const testMultibyteCharacters = async (t, objectMode, addNoopTransform, execaMethod) => {101- const {stdout} = await execaMethod('noop.js', {102- stdout: addNoopGenerator(getOutputsGenerator(foobarArray)(objectMode, true), addNoopTransform, objectMode),103- encoding: 'base64',104- });105- if (objectMode) {106- t.deepEqual(stdout, foobarArray);107- } else {108- t.is(stdout, btoa(foobarArray.join('')));109- }110-};111-112-test('Handle multibyte characters', testMultibyteCharacters, false, false, execa);113-test('Handle multibyte characters, noop transform', testMultibyteCharacters, false, true, execa);114-test('Handle multibyte characters, with objectMode', testMultibyteCharacters, true, false, execa);115-test('Handle multibyte characters, with objectMode, noop transform', testMultibyteCharacters, true, true, execa);116-test('Handle multibyte characters, sync', testMultibyteCharacters, false, false, execaSync);117-test('Handle multibyte characters, noop transform, sync', testMultibyteCharacters, false, true, execaSync);118-test('Handle multibyte characters, with objectMode, sync', testMultibyteCharacters, true, false, execaSync);119-test('Handle multibyte characters, with objectMode, noop transform, sync', testMultibyteCharacters, true, true, execaSync);120-121-const testObjectMode = async (t, addNoopTransform, execaMethod) => {122- const {stdout} = await execaMethod('noop.js', {123- stdout: addNoopGenerator(outputObjectGenerator(), addNoopTransform, true),124- encoding: 'base64',125- });126- t.deepEqual(stdout, [foobarObject]);127-};128-129-test('Other encodings work with transforms that return objects', testObjectMode, false, execa);130-test('Other encodings work with transforms that return objects, noop transform', testObjectMode, true, execa);131-test('Other encodings work with transforms that return objects, sync', testObjectMode, false, execaSync);132-test('Other encodings work with transforms that return objects, noop transform, sync', testObjectMode, true, execaSync);133-96 // eslint-disable-next-line max-params135-const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options, execaMethod) => {136- const {stdout} = await execaMethod('empty.js', {stdout: stdoutOption, ...options});137- t.is(stdout === undefined, isUndefined);138-};139-140-const base64Options = {encoding: 'base64'};141-const linesOptions = {lines: true};142-test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options, execa);143-test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options, execa);144-test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options, execa);145-test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options, execa);146-test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options, execa);147-test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options, execa);148-test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options, execa);149-test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options, execa);150-test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options, execa);151-test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options, execa);152-test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options, execa);153-test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options, execa);154-test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options, execa);155-test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options, execa);156-test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options, execa);157-test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options, execa);158-test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options, execa);159-test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions, execa);160-test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions, execa);161-test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions, execa);162-test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions, execa);163-test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions, execa);164-test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions, execa);165-test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions, execa);166-test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions, execa);167-test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions, execa);168-test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions, execa);169-test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions, execa);170-test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions, execa);171-test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions, execa);172-test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions, execa);173-test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions, execa);174-test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions, execa);175-test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions, execa);176-test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execa);177-test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execa);178-test('Is ignored with other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, base64Options, execaSync);179-test('Is ignored with other encodings and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, base64Options, execaSync);180-test('Is ignored with other encodings and "inherit", sync', testIgnoredEncoding, 'inherit', true, base64Options, execaSync);181-test('Is ignored with other encodings and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, base64Options, execaSync);182-test('Is ignored with other encodings and 1, sync', testIgnoredEncoding, 1, true, base64Options, execaSync);183-test('Is ignored with other encodings and [1], sync', testIgnoredEncoding, [1], true, base64Options, execaSync);184-test('Is ignored with other encodings and process.stdout, sync', testIgnoredEncoding, process.stdout, true, base64Options, execaSync);185-test('Is ignored with other encodings and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, base64Options, execaSync);186-test('Is not ignored with other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, base64Options, execaSync);187-test('Is not ignored with other encodings and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, base64Options, execaSync);188-test('Is not ignored with other encodings and undefined, sync', testIgnoredEncoding, undefined, false, base64Options, execaSync);189-test('Is not ignored with other encodings and null, sync', testIgnoredEncoding, null, false, base64Options, execaSync);190-test('Is ignored with "lines: true" and "ignore", sync', testIgnoredEncoding, 'ignore', true, linesOptions, execaSync);191-test('Is ignored with "lines: true" and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, linesOptions, execaSync);192-test('Is ignored with "lines: true" and "inherit", sync', testIgnoredEncoding, 'inherit', true, linesOptions, execaSync);193-test('Is ignored with "lines: true" and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, linesOptions, execaSync);194-test('Is ignored with "lines: true" and 1, sync', testIgnoredEncoding, 1, true, linesOptions, execaSync);195-test('Is ignored with "lines: true" and [1], sync', testIgnoredEncoding, [1], true, linesOptions, execaSync);196-test('Is ignored with "lines: true" and process.stdout, sync', testIgnoredEncoding, process.stdout, true, linesOptions, execaSync);197-test('Is ignored with "lines: true" and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, linesOptions, execaSync);198-test('Is not ignored with "lines: true" and "pipe", sync', testIgnoredEncoding, 'pipe', false, linesOptions, execaSync);199-test('Is not ignored with "lines: true" and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, linesOptions, execaSync);200-test('Is not ignored with "lines: true" and undefined, sync', testIgnoredEncoding, undefined, false, linesOptions, execaSync);201-test('Is not ignored with "lines: true" and null, sync', testIgnoredEncoding, null, false, linesOptions, execaSync);202-test('Is ignored with "lines: true", other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execaSync);203-test('Is not ignored with "lines: true", other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execaSync);204-205-// eslint-disable-next-line max-params97 const testEncodingInput = async (t, input, expectedStdout, encoding, execaMethod) => {98 const {stdout} = await execaMethod('stdin.js', {input, encoding});99 t.deepEqual(stdout, expectedStdout);100 };29 unmodified linesadded:test/stdio/encoding-ignored.js+92 added
1+import process from 'node:process';2+import test from 'ava';3+import {execa, execaSync} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {outputObjectGenerator, addNoopGenerator} from '../helpers/generator.js';6+import {foobarObject} from '../helpers/input.js';7+8+setFixtureDir();9+10+const testObjectMode = async (t, addNoopTransform, execaMethod) => {11+ const {stdout} = await execaMethod('noop.js', {12+ stdout: addNoopGenerator(outputObjectGenerator(), addNoopTransform, true),13+ encoding: 'base64',14+ });15+ t.deepEqual(stdout, [foobarObject]);16+};17+18+test('Other encodings work with transforms that return objects', testObjectMode, false, execa);19+test('Other encodings work with transforms that return objects, noop transform', testObjectMode, true, execa);20+test('Other encodings work with transforms that return objects, sync', testObjectMode, false, execaSync);21+test('Other encodings work with transforms that return objects, noop transform, sync', testObjectMode, true, execaSync);22+23+// eslint-disable-next-line max-params24+const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options, execaMethod) => {25+ const {stdout} = await execaMethod('empty.js', {stdout: stdoutOption, ...options});26+ t.is(stdout === undefined, isUndefined);27+};28+29+const base64Options = {encoding: 'base64'};30+const linesOptions = {lines: true};31+test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options, execa);32+test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options, execa);33+test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options, execa);34+test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options, execa);35+test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options, execa);36+test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options, execa);37+test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options, execa);38+test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options, execa);39+test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options, execa);40+test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options, execa);41+test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options, execa);42+test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options, execa);43+test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options, execa);44+test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options, execa);45+test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options, execa);46+test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options, execa);47+test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options, execa);48+test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions, execa);49+test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions, execa);50+test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions, execa);51+test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions, execa);52+test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions, execa);53+test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions, execa);54+test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions, execa);55+test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions, execa);56+test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions, execa);57+test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions, execa);58+test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions, execa);59+test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions, execa);60+test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions, execa);61+test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions, execa);62+test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions, execa);63+test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions, execa);64+test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions, execa);65+test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execa);66+test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execa);67+test('Is ignored with other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, base64Options, execaSync);68+test('Is ignored with other encodings and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, base64Options, execaSync);69+test('Is ignored with other encodings and "inherit", sync', testIgnoredEncoding, 'inherit', true, base64Options, execaSync);70+test('Is ignored with other encodings and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, base64Options, execaSync);71+test('Is ignored with other encodings and 1, sync', testIgnoredEncoding, 1, true, base64Options, execaSync);72+test('Is ignored with other encodings and [1], sync', testIgnoredEncoding, [1], true, base64Options, execaSync);73+test('Is ignored with other encodings and process.stdout, sync', testIgnoredEncoding, process.stdout, true, base64Options, execaSync);74+test('Is ignored with other encodings and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, base64Options, execaSync);75+test('Is not ignored with other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, base64Options, execaSync);76+test('Is not ignored with other encodings and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, base64Options, execaSync);77+test('Is not ignored with other encodings and undefined, sync', testIgnoredEncoding, undefined, false, base64Options, execaSync);78+test('Is not ignored with other encodings and null, sync', testIgnoredEncoding, null, false, base64Options, execaSync);79+test('Is ignored with "lines: true" and "ignore", sync', testIgnoredEncoding, 'ignore', true, linesOptions, execaSync);80+test('Is ignored with "lines: true" and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, linesOptions, execaSync);81+test('Is ignored with "lines: true" and "inherit", sync', testIgnoredEncoding, 'inherit', true, linesOptions, execaSync);82+test('Is ignored with "lines: true" and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, linesOptions, execaSync);83+test('Is ignored with "lines: true" and 1, sync', testIgnoredEncoding, 1, true, linesOptions, execaSync);84+test('Is ignored with "lines: true" and [1], sync', testIgnoredEncoding, [1], true, linesOptions, execaSync);85+test('Is ignored with "lines: true" and process.stdout, sync', testIgnoredEncoding, process.stdout, true, linesOptions, execaSync);86+test('Is ignored with "lines: true" and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, linesOptions, execaSync);87+test('Is not ignored with "lines: true" and "pipe", sync', testIgnoredEncoding, 'pipe', false, linesOptions, execaSync);88+test('Is not ignored with "lines: true" and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, linesOptions, execaSync);89+test('Is not ignored with "lines: true" and undefined, sync', testIgnoredEncoding, undefined, false, linesOptions, execaSync);90+test('Is not ignored with "lines: true" and null, sync', testIgnoredEncoding, null, false, linesOptions, execaSync);91+test('Is ignored with "lines: true", other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execaSync);92+test('Is not ignored with "lines: true", other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execaSync);added:test/stdio/encoding-multibyte.js+73 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {noopGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';5+import {multibyteChar, multibyteString, multibyteUint8Array, breakingLength, brokenSymbol} from '../helpers/encoding.js';6+7+setFixtureDir();8+9+const foobarArray = ['fo', 'ob', 'ar', '..'];10+11+const testMultibyteCharacters = async (t, objectMode, addNoopTransform, execaMethod) => {12+ const {stdout} = await execaMethod('noop.js', {13+ stdout: addNoopGenerator(getOutputsGenerator(foobarArray)(objectMode, true), addNoopTransform, objectMode),14+ encoding: 'base64',15+ });16+ if (objectMode) {17+ t.deepEqual(stdout, foobarArray);18+ } else {19+ t.is(stdout, btoa(foobarArray.join('')));20+ }21+};22+23+test('Handle multibyte characters', testMultibyteCharacters, false, false, execa);24+test('Handle multibyte characters, noop transform', testMultibyteCharacters, false, true, execa);25+test('Handle multibyte characters, with objectMode', testMultibyteCharacters, true, false, execa);26+test('Handle multibyte characters, with objectMode, noop transform', testMultibyteCharacters, true, true, execa);27+test('Handle multibyte characters, sync', testMultibyteCharacters, false, false, execaSync);28+test('Handle multibyte characters, noop transform, sync', testMultibyteCharacters, false, true, execaSync);29+test('Handle multibyte characters, with objectMode, sync', testMultibyteCharacters, true, false, execaSync);30+test('Handle multibyte characters, with objectMode, noop transform, sync', testMultibyteCharacters, true, true, execaSync);31+32+const testMultibyte = async (t, objectMode, execaMethod) => {33+ const {stdout} = await execaMethod('stdin.js', {34+ stdin: [35+ [multibyteUint8Array.slice(0, breakingLength), multibyteUint8Array.slice(breakingLength)],36+ noopGenerator(objectMode, true),37+ ],38+ });39+ t.is(stdout, multibyteString);40+};41+42+test('Generator handles multibyte characters with Uint8Array', testMultibyte, false, execa);43+test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true, execa);44+test('Generator handles multibyte characters with Uint8Array, sync', testMultibyte, false, execaSync);45+test('Generator handles multibyte characters with Uint8Array, objectMode, sync', testMultibyte, true, execaSync);46+47+const testMultibytePartial = async (t, objectMode, execaMethod) => {48+ const {stdout} = await execaMethod('stdin.js', {49+ stdin: [50+ [multibyteUint8Array.slice(0, breakingLength)],51+ noopGenerator(objectMode, true),52+ ],53+ });54+ t.is(stdout, `${multibyteChar}${brokenSymbol}`);55+};56+57+test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false, execa);58+test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true, execa);59+test('Generator handles partial multibyte characters with Uint8Array, sync', testMultibytePartial, false, execaSync);60+test('Generator handles partial multibyte characters with Uint8Array, objectMode, sync', testMultibytePartial, true, execaSync);61+62+const testMultibytePartialOutput = async (t, execaMethod) => {63+ const {stdout} = await execaMethod('noop.js', {64+ stdout: getOutputsGenerator([65+ multibyteUint8Array.slice(0, breakingLength),66+ multibyteUint8Array.slice(breakingLength),67+ ])(false, true),68+ });69+ t.is(stdout, multibyteString);70+};71+72+test('Generator handles output multibyte characters with Uint8Array', testMultibytePartialOutput, execa);73+test('Generator handles output multibyte characters with Uint8Array, sync', testMultibytePartialOutput, execaSync);modified:test/stdio/encoding-transform.js+1 added-187 removed
2 unmodified lines3 import {execa, execaSync} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 import {getStdio} from '../helpers/stdio.js';6 import {foobarString, foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';7-import {noopGenerator, getOutputGenerator, getOutputsGenerator, convertTransformToFinal} from '../helpers/generator.js';8-import {multibyteChar, multibyteString, multibyteUint8Array, breakingLength, brokenSymbol} from '../helpers/encoding.js';7+import {noopGenerator, getOutputGenerator} from '../helpers/generator.js';8 9 setFixtureDir();10 11 const getTypeofGenerator = lines => (objectMode, binary) => ({157 unmodified lines169 test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 3, execa);170 test('The first generator with result.stdout does not receive an object argument even in objectMode, sync', testFirstOutputGeneratorArgument, 1, execaSync);171 test('The first generator with result.stderr does not receive an object argument even in objectMode, sync', testFirstOutputGeneratorArgument, 2, execaSync);172 test('The first generator with result.stdio[*] does not receive an object argument even in objectMode, sync', testFirstOutputGeneratorArgument, 3, execaSync);174-175-// eslint-disable-next-line max-params176-const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final, execaMethod) => {177- const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';178- const {stdout} = await execaMethod(fixtureName, ['1', foobarString], {179- stdout: convertTransformToFinal(getOutputGenerator(input)(objectMode, true), final),180- encoding,181- reject,182- });183- const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;184- const output = Buffer.from(typeofChunk, encoding === 'buffer' || objectMode ? undefined : encoding).toString();185- t.is(output, foobarString);186-};187-188-test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false, execa);189-test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false, execa);190-test('Generator can return string with encoding "utf16le"', testGeneratorReturnType, foobarString, 'utf16le', true, false, false, execa);191-test('Generator can return Uint8Array with encoding "utf16le"', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, false, execa);192-test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false, execa);193-test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false, execa);194-test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false, execa);195-test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false, execa);196-test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false, execa);197-test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false, execa);198-test('Generator can return string with encoding "utf16le", failure', testGeneratorReturnType, foobarString, 'utf16le', false, false, false, execa);199-test('Generator can return Uint8Array with encoding "utf16le", failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, false, execa);200-test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false, execa);201-test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false, execa);202-test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false, execa);203-test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false, execa);204-test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false, execa);205-test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false, execa);206-test('Generator can return string with encoding "utf16le", objectMode', testGeneratorReturnType, foobarString, 'utf16le', true, true, false, execa);207-test('Generator can return Uint8Array with encoding "utf16le", objectMode', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, false, execa);208-test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false, execa);209-test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false, execa);210-test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false, execa);211-test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false, execa);212-test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false, execa);213-test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false, execa);214-test('Generator can return string with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarString, 'utf16le', false, true, false, execa);215-test('Generator can return Uint8Array with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, false, execa);216-test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false, execa);217-test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false, execa);218-test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false, execa);219-test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false, execa);220-test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true, execa);221-test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true, execa);222-test('Generator can return final string with encoding "utf16le"', testGeneratorReturnType, foobarString, 'utf16le', true, false, true, execa);223-test('Generator can return final Uint8Array with encoding "utf16le"', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, true, execa);224-test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true, execa);225-test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true, execa);226-test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true, execa);227-test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true, execa);228-test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true, execa);229-test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true, execa);230-test('Generator can return final string with encoding "utf16le", failure', testGeneratorReturnType, foobarString, 'utf16le', false, false, true, execa);231-test('Generator can return final Uint8Array with encoding "utf16le", failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, true, execa);232-test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true, execa);233-test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true, execa);234-test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true, execa);235-test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true, execa);236-test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true, execa);237-test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true, execa);238-test('Generator can return final string with encoding "utf16le", objectMode', testGeneratorReturnType, foobarString, 'utf16le', true, true, true, execa);239-test('Generator can return final Uint8Array with encoding "utf16le", objectMode', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, true, execa);240-test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true, execa);241-test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true, execa);242-test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true, execa);243-test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true, execa);244-test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true, execa);245-test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true, execa);246-test('Generator can return final string with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarString, 'utf16le', false, true, true, execa);247-test('Generator can return final Uint8Array with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, true, execa);248-test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true, execa);249-test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true, execa);250-test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true, execa);251-test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true, execa);252-test('Generator can return string with default encoding, sync', testGeneratorReturnType, foobarString, 'utf8', true, false, false, execaSync);253-test('Generator can return Uint8Array with default encoding, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false, execaSync);254-test('Generator can return string with encoding "utf16le", sync', testGeneratorReturnType, foobarString, 'utf16le', true, false, false, execaSync);255-test('Generator can return Uint8Array with encoding "utf16le", sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, false, execaSync);256-test('Generator can return string with encoding "buffer", sync', testGeneratorReturnType, foobarString, 'buffer', true, false, false, execaSync);257-test('Generator can return Uint8Array with encoding "buffer", sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false, execaSync);258-test('Generator can return string with encoding "hex", sync', testGeneratorReturnType, foobarString, 'hex', true, false, false, execaSync);259-test('Generator can return Uint8Array with encoding "hex", sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false, execaSync);260-test('Generator can return string with default encoding, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, false, false, execaSync);261-test('Generator can return Uint8Array with default encoding, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false, execaSync);262-test('Generator can return string with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, false, false, execaSync);263-test('Generator can return Uint8Array with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, false, execaSync);264-test('Generator can return string with encoding "buffer", failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, false, false, execaSync);265-test('Generator can return Uint8Array with encoding "buffer", failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false, execaSync);266-test('Generator can return string with encoding "hex", failure, sync', testGeneratorReturnType, foobarString, 'hex', false, false, false, execaSync);267-test('Generator can return Uint8Array with encoding "hex", failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false, execaSync);268-test('Generator can return string with default encoding, objectMode, sync', testGeneratorReturnType, foobarString, 'utf8', true, true, false, execaSync);269-test('Generator can return Uint8Array with default encoding, objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false, execaSync);270-test('Generator can return string with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarString, 'utf16le', true, true, false, execaSync);271-test('Generator can return Uint8Array with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, false, execaSync);272-test('Generator can return string with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarString, 'buffer', true, true, false, execaSync);273-test('Generator can return Uint8Array with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false, execaSync);274-test('Generator can return string with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarString, 'hex', true, true, false, execaSync);275-test('Generator can return Uint8Array with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false, execaSync);276-test('Generator can return string with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, true, false, execaSync);277-test('Generator can return Uint8Array with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false, execaSync);278-test('Generator can return string with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, true, false, execaSync);279-test('Generator can return Uint8Array with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, false, execaSync);280-test('Generator can return string with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, true, false, execaSync);281-test('Generator can return Uint8Array with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false, execaSync);282-test('Generator can return string with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'hex', false, true, false, execaSync);283-test('Generator can return Uint8Array with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false, execaSync);284-test('Generator can return final string with default encoding, sync', testGeneratorReturnType, foobarString, 'utf8', true, false, true, execaSync);285-test('Generator can return final Uint8Array with default encoding, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true, execaSync);286-test('Generator can return final string with encoding "utf16le", sync', testGeneratorReturnType, foobarString, 'utf16le', true, false, true, execaSync);287-test('Generator can return final Uint8Array with encoding "utf16le", sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, true, execaSync);288-test('Generator can return final string with encoding "buffer", sync', testGeneratorReturnType, foobarString, 'buffer', true, false, true, execaSync);289-test('Generator can return final Uint8Array with encoding "buffer", sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true, execaSync);290-test('Generator can return final string with encoding "hex", sync', testGeneratorReturnType, foobarString, 'hex', true, false, true, execaSync);291-test('Generator can return final Uint8Array with encoding "hex", sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true, execaSync);292-test('Generator can return final string with default encoding, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, false, true, execaSync);293-test('Generator can return final Uint8Array with default encoding, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true, execaSync);294-test('Generator can return final string with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, false, true, execaSync);295-test('Generator can return final Uint8Array with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, true, execaSync);296-test('Generator can return final string with encoding "buffer", failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, false, true, execaSync);297-test('Generator can return final Uint8Array with encoding "buffer", failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true, execaSync);298-test('Generator can return final string with encoding "hex", failure, sync', testGeneratorReturnType, foobarString, 'hex', false, false, true, execaSync);299-test('Generator can return final Uint8Array with encoding "hex", failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true, execaSync);300-test('Generator can return final string with default encoding, objectMode, sync', testGeneratorReturnType, foobarString, 'utf8', true, true, true, execaSync);301-test('Generator can return final Uint8Array with default encoding, objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true, execaSync);302-test('Generator can return final string with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarString, 'utf16le', true, true, true, execaSync);303-test('Generator can return final Uint8Array with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, true, execaSync);304-test('Generator can return final string with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarString, 'buffer', true, true, true, execaSync);305-test('Generator can return final Uint8Array with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true, execaSync);306-test('Generator can return final string with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarString, 'hex', true, true, true, execaSync);307-test('Generator can return final Uint8Array with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true, execaSync);308-test('Generator can return final string with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, true, true, execaSync);309-test('Generator can return final Uint8Array with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true, execaSync);310-test('Generator can return final string with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, true, true, execaSync);311-test('Generator can return final Uint8Array with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, true, execaSync);312-test('Generator can return final string with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, true, true, execaSync);313-test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true, execaSync);314-test('Generator can return final string with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'hex', false, true, true, execaSync);315-test('Generator can return final Uint8Array with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true, execaSync);316-317-const testMultibyte = async (t, objectMode, execaMethod) => {318- const {stdout} = await execaMethod('stdin.js', {319- stdin: [320- [multibyteUint8Array.slice(0, breakingLength), multibyteUint8Array.slice(breakingLength)],321- noopGenerator(objectMode, true),322- ],323- });324- t.is(stdout, multibyteString);325-};326-327-test('Generator handles multibyte characters with Uint8Array', testMultibyte, false, execa);328-test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true, execa);329-test('Generator handles multibyte characters with Uint8Array, sync', testMultibyte, false, execaSync);330-test('Generator handles multibyte characters with Uint8Array, objectMode, sync', testMultibyte, true, execaSync);331-332-const testMultibytePartial = async (t, objectMode, execaMethod) => {333- const {stdout} = await execaMethod('stdin.js', {334- stdin: [335- [multibyteUint8Array.slice(0, breakingLength)],336- noopGenerator(objectMode, true),337- ],338- });339- t.is(stdout, `${multibyteChar}${brokenSymbol}`);340-};341-342-test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false, execa);343-test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true, execa);344-test('Generator handles partial multibyte characters with Uint8Array, sync', testMultibytePartial, false, execaSync);345-test('Generator handles partial multibyte characters with Uint8Array, objectMode, sync', testMultibytePartial, true, execaSync);346-347-const testMultibytePartialOutput = async (t, execaMethod) => {348- const {stdout} = await execaMethod('noop.js', {349- stdout: getOutputsGenerator([350- multibyteUint8Array.slice(0, breakingLength),351- multibyteUint8Array.slice(breakingLength),352- ])(false, true),353- });354- t.is(stdout, multibyteString);355-};356-357-test('Generator handles output multibyte characters with Uint8Array', testMultibytePartialOutput, execa);358-test('Generator handles output multibyte characters with Uint8Array, sync', testMultibytePartialOutput, execaSync);added:test/stdio/file-path-error.js+168 added
1+import {readFile, writeFile, rm} from 'node:fs/promises';2+import {pathToFileURL} from 'node:url';3+import test from 'ava';4+import {pathExists} from 'path-exists';5+import tempfile from 'tempfile';6+import {execa, execaSync} from '../../index.js';7+import {setFixtureDir} from '../helpers/fixtures-dir.js';8+import {identity, getStdio} from '../helpers/stdio.js';9+import {foobarString, foobarUppercase} from '../helpers/input.js';10+import {outputObjectGenerator, uppercaseGenerator, serializeGenerator, throwingGenerator} from '../helpers/generator.js';11+import {getAbsolutePath} from '../helpers/file-path.js';12+13+setFixtureDir();14+15+const nonFileUrl = new URL('https://example.com');16+17+const testStdioNonFileUrl = (t, fdNumber, execaMethod) => {18+ t.throws(() => {19+ execaMethod('empty.js', getStdio(fdNumber, nonFileUrl));20+ }, {message: /pathToFileURL/});21+};22+23+test('inputFile cannot be a non-file URL', testStdioNonFileUrl, 'inputFile', execa);24+test('stdin cannot be a non-file URL', testStdioNonFileUrl, 0, execa);25+test('stdout cannot be a non-file URL', testStdioNonFileUrl, 1, execa);26+test('stderr cannot be a non-file URL', testStdioNonFileUrl, 2, execa);27+test('stdio[*] cannot be a non-file URL', testStdioNonFileUrl, 3, execa);28+test('inputFile cannot be a non-file URL - sync', testStdioNonFileUrl, 'inputFile', execaSync);29+test('stdin cannot be a non-file URL - sync', testStdioNonFileUrl, 0, execaSync);30+test('stdout cannot be a non-file URL - sync', testStdioNonFileUrl, 1, execaSync);31+test('stderr cannot be a non-file URL - sync', testStdioNonFileUrl, 2, execaSync);32+test('stdio[*] cannot be a non-file URL - sync', testStdioNonFileUrl, 3, execaSync);33+34+const testInvalidInputFile = (t, execaMethod) => {35+ t.throws(() => {36+ execaMethod('empty.js', getStdio('inputFile', false));37+ }, {message: /a file path string or a file URL/});38+};39+40+test('inputFile must be a file URL or string', testInvalidInputFile, execa);41+test('inputFile must be a file URL or string - sync', testInvalidInputFile, execaSync);42+43+const testFilePathObject = (t, fdNumber, execaMethod) => {44+ t.throws(() => {45+ execaMethod('empty.js', getStdio(fdNumber, foobarString));46+ }, {message: /must be used/});47+};48+49+test('stdin must be an object when it is a file path string', testFilePathObject, 0, execa);50+test('stdout must be an object when it is a file path string', testFilePathObject, 1, execa);51+test('stderr must be an object when it is a file path string', testFilePathObject, 2, execa);52+test('stdio[*] must be an object when it is a file path string', testFilePathObject, 3, execa);53+test('stdin be an object when it is a file path string - sync', testFilePathObject, 0, execaSync);54+test('stdout be an object when it is a file path string - sync', testFilePathObject, 1, execaSync);55+test('stderr be an object when it is a file path string - sync', testFilePathObject, 2, execaSync);56+test('stdio[*] must be an object when it is a file path string - sync', testFilePathObject, 3, execaSync);57+58+const testFileError = async (t, fixtureName, mapFile, fdNumber) => {59+ await t.throwsAsync(60+ execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, mapFile('./unknown/file'))),61+ {code: 'ENOENT'},62+ );63+};64+65+test.serial('inputFile file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 'inputFile');66+test.serial('stdin file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 0);67+test.serial('stdout file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 1);68+test.serial('stderr file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 2);69+test.serial('stdio[*] file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 3);70+test.serial('inputFile file path errors should be handled', testFileError, 'stdin-fd.js', identity, 'inputFile');71+test.serial('stdin file path errors should be handled', testFileError, 'stdin-fd.js', getAbsolutePath, 0);72+test.serial('stdout file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 1);73+test.serial('stderr file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 2);74+test.serial('stdio[*] file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 3);75+76+const testFileErrorSync = (t, mapFile, fdNumber) => {77+ t.throws(() => {78+ execaSync('empty.js', getStdio(fdNumber, mapFile('./unknown/file')));79+ }, {code: 'ENOENT'});80+};81+82+test('inputFile file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 'inputFile');83+test('stdin file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 0);84+test('stdout file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 1);85+test('stderr file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 2);86+test('stdio[*] file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 3);87+test('inputFile file path errors should be handled - sync', testFileErrorSync, identity, 'inputFile');88+test('stdin file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 0);89+test('stdout file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 1);90+test('stderr file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 2);91+test('stdio[*] file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 3);92+93+const testInputFileObject = async (t, fdNumber, mapFile, execaMethod) => {94+ const filePath = tempfile();95+ await writeFile(filePath, foobarString);96+ t.throws(() => {97+ execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [98+ new Uint8Array(),99+ mapFile(filePath),100+ serializeGenerator(true),101+ ]));102+ }, {message: /cannot use both files and transforms in objectMode/});103+ await rm(filePath);104+};105+106+test('stdin cannot use objectMode together with input file paths', testInputFileObject, 0, getAbsolutePath, execa);107+test('stdin cannot use objectMode together with input file URLs', testInputFileObject, 0, pathToFileURL, execa);108+test('stdio[*] cannot use objectMode together with input file paths', testInputFileObject, 3, getAbsolutePath, execa);109+test('stdio[*] cannot use objectMode together with input file URLs', testInputFileObject, 3, pathToFileURL, execa);110+test('stdin cannot use objectMode together with input file paths, sync', testInputFileObject, 0, getAbsolutePath, execaSync);111+test('stdin cannot use objectMode together with input file URLs, sync', testInputFileObject, 0, pathToFileURL, execaSync);112+113+const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {114+ const filePath = tempfile();115+ t.throws(() => {116+ execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [117+ outputObjectGenerator(),118+ mapFile(filePath),119+ ]));120+ }, {message: /cannot use both files and transforms in objectMode/});121+ t.false(await pathExists(filePath));122+};123+124+test('stdout cannot use objectMode together with output file paths', testOutputFileObject, 1, getAbsolutePath, execa);125+test('stdout cannot use objectMode together with output file URLs', testOutputFileObject, 1, pathToFileURL, execa);126+test('stderr cannot use objectMode together with output file paths', testOutputFileObject, 2, getAbsolutePath, execa);127+test('stderr cannot use objectMode together with output file URLs', testOutputFileObject, 2, pathToFileURL, execa);128+test('stdio[*] cannot use objectMode together with output file paths', testOutputFileObject, 3, getAbsolutePath, execa);129+test('stdio[*] cannot use objectMode together with output file URLs', testOutputFileObject, 3, pathToFileURL, execa);130+test('stdout cannot use objectMode together with output file paths, sync', testOutputFileObject, 1, getAbsolutePath, execaSync);131+test('stdout cannot use objectMode together with output file URLs, sync', testOutputFileObject, 1, pathToFileURL, execaSync);132+test('stderr cannot use objectMode together with output file paths, sync', testOutputFileObject, 2, getAbsolutePath, execaSync);133+test('stderr cannot use objectMode together with output file URLs, sync', testOutputFileObject, 2, pathToFileURL, execaSync);134+test('stdio[*] cannot use objectMode together with output file paths, sync', testOutputFileObject, 3, getAbsolutePath, execaSync);135+test('stdio[*] cannot use objectMode together with output file URLs, sync', testOutputFileObject, 3, pathToFileURL, execaSync);136+137+test('Generator error stops writing to output file', async t => {138+ const filePath = tempfile();139+ const cause = new Error(foobarString);140+ const error = await t.throwsAsync(execa('noop.js', {141+ stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],142+ }));143+ t.is(error.cause, cause);144+ t.is(await readFile(filePath, 'utf8'), '');145+});146+147+test('Generator error does not create output file, sync', async t => {148+ const filePath = tempfile();149+ const cause = new Error(foobarString);150+ const error = t.throws(() => {151+ execaSync('noop.js', {152+ stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],153+ });154+ });155+ t.is(error.cause, cause);156+ t.false(await pathExists(filePath));157+});158+159+test('Output file error still returns transformed output, sync', async t => {160+ const filePath = tempfile();161+ const {stdout} = t.throws(() => {162+ execaSync('noop-fd.js', ['1', foobarString], {163+ stdout: [uppercaseGenerator(), getAbsolutePath('./unknown/file')],164+ });165+ }, {code: 'ENOENT'});166+ t.false(await pathExists(filePath));167+ t.is(stdout, foobarUppercase);168+});added:test/stdio/file-path-main.js+155 added
1+import {readFile, writeFile, rm} from 'node:fs/promises';2+import {dirname, basename} from 'node:path';3+import process from 'node:process';4+import {pathToFileURL} from 'node:url';5+import test from 'ava';6+import tempfile from 'tempfile';7+import {execa, execaSync} from '../../index.js';8+import {setFixtureDir} from '../helpers/fixtures-dir.js';9+import {identity, getStdio} from '../helpers/stdio.js';10+import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';11+import {foobarString, foobarUint8Array} from '../helpers/input.js';12+import {getAbsolutePath, getRelativePath} from '../helpers/file-path.js';13+14+setFixtureDir();15+16+const getStdioInput = (fdNumberOrName, file) => {17+ if (fdNumberOrName === 'string') {18+ return {input: foobarString};19+ }20+21+ if (fdNumberOrName === 'binary') {22+ return {input: foobarUint8Array};23+ }24+25+ return getStdioInputFile(fdNumberOrName, file);26+};27+28+const getStdioInputFile = (fdNumberOrName, file) => getStdio(fdNumberOrName, typeof fdNumberOrName === 'string' ? file : {file});29+30+const testStdinFile = async (t, mapFilePath, fdNumber, execaMethod) => {31+ const filePath = tempfile();32+ await writeFile(filePath, foobarString);33+ const {stdout} = await execaMethod('stdin.js', getStdio(fdNumber, mapFilePath(filePath)));34+ t.is(stdout, foobarString);35+ await rm(filePath);36+};37+38+test('inputFile can be a file URL', testStdinFile, pathToFileURL, 'inputFile', execa);39+test('stdin can be a file URL', testStdinFile, pathToFileURL, 0, execa);40+test('inputFile can be an absolute file path', testStdinFile, identity, 'inputFile', execa);41+test('stdin can be an absolute file path', testStdinFile, getAbsolutePath, 0, execa);42+test('inputFile can be a relative file path', testStdinFile, identity, 'inputFile', execa);43+test('stdin can be a relative file path', testStdinFile, getRelativePath, 0, execa);44+test('inputFile can be a file URL - sync', testStdinFile, pathToFileURL, 'inputFile', execaSync);45+test('stdin can be a file URL - sync', testStdinFile, pathToFileURL, 0, execaSync);46+test('inputFile can be an absolute file path - sync', testStdinFile, identity, 'inputFile', execaSync);47+test('stdin can be an absolute file path - sync', testStdinFile, getAbsolutePath, 0, execaSync);48+test('inputFile can be a relative file path - sync', testStdinFile, identity, 'inputFile', execaSync);49+test('stdin can be a relative file path - sync', testStdinFile, getRelativePath, 0, execaSync);50+51+const testOutputFile = async (t, mapFile, fdNumber, execaMethod) => {52+ const filePath = tempfile();53+ await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, mapFile(filePath)));54+ t.is(await readFile(filePath, 'utf8'), foobarString);55+ await rm(filePath);56+};57+58+test('stdout can be a file URL', testOutputFile, pathToFileURL, 1, execa);59+test('stderr can be a file URL', testOutputFile, pathToFileURL, 2, execa);60+test('stdio[*] can be a file URL', testOutputFile, pathToFileURL, 3, execa);61+test('stdout can be an absolute file path', testOutputFile, getAbsolutePath, 1, execa);62+test('stderr can be an absolute file path', testOutputFile, getAbsolutePath, 2, execa);63+test('stdio[*] can be an absolute file path', testOutputFile, getAbsolutePath, 3, execa);64+test('stdout can be a relative file path', testOutputFile, getRelativePath, 1, execa);65+test('stderr can be a relative file path', testOutputFile, getRelativePath, 2, execa);66+test('stdio[*] can be a relative file path', testOutputFile, getRelativePath, 3, execa);67+test('stdout can be a file URL - sync', testOutputFile, pathToFileURL, 1, execaSync);68+test('stderr can be a file URL - sync', testOutputFile, pathToFileURL, 2, execaSync);69+test('stdio[*] can be a file URL - sync', testOutputFile, pathToFileURL, 3, execaSync);70+test('stdout can be an absolute file path - sync', testOutputFile, getAbsolutePath, 1, execaSync);71+test('stderr can be an absolute file path - sync', testOutputFile, getAbsolutePath, 2, execaSync);72+test('stdio[*] can be an absolute file path - sync', testOutputFile, getAbsolutePath, 3, execaSync);73+test('stdout can be a relative file path - sync', testOutputFile, getRelativePath, 1, execaSync);74+test('stderr can be a relative file path - sync', testOutputFile, getRelativePath, 2, execaSync);75+test('stdio[*] can be a relative file path - sync', testOutputFile, getRelativePath, 3, execaSync);76+77+const testInputFileValidUrl = async (t, fdNumber, execaMethod) => {78+ const filePath = tempfile();79+ await writeFile(filePath, foobarString);80+ const currentCwd = process.cwd();81+ process.chdir(dirname(filePath));82+83+ try {84+ const {stdout} = await execaMethod('stdin.js', getStdioInputFile(fdNumber, basename(filePath)));85+ t.is(stdout, foobarString);86+ } finally {87+ process.chdir(currentCwd);88+ await rm(filePath);89+ }90+};91+92+test.serial('inputFile does not need to start with . when being a relative file path', testInputFileValidUrl, 'inputFile', execa);93+test.serial('stdin does not need to start with . when being a relative file path', testInputFileValidUrl, 0, execa);94+test.serial('inputFile does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 'inputFile', execaSync);95+test.serial('stdin does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 0, execaSync);96+97+const testMultipleInputs = async (t, indices, execaMethod) => {98+ const filePath = tempfile();99+ await writeFile(filePath, foobarString);100+ const options = Object.assign({}, ...indices.map(fdNumber => getStdioInput(fdNumber, filePath)));101+ const {stdout} = await execaMethod('stdin.js', options);102+ t.is(stdout, foobarString.repeat(indices.length));103+ await rm(filePath);104+};105+106+test('inputFile can be set', testMultipleInputs, ['inputFile'], runExeca);107+test('inputFile can be set - sync', testMultipleInputs, ['inputFile'], runExecaSync);108+test('inputFile can be set with $', testMultipleInputs, ['inputFile'], runScript);109+test('inputFile can be set with $.sync', testMultipleInputs, ['inputFile'], runScriptSync);110+test('input String and inputFile can be both set', testMultipleInputs, ['inputFile', 'string'], execa);111+test('input String and stdin can be both set', testMultipleInputs, [0, 'string'], execa);112+test('input Uint8Array and inputFile can be both set', testMultipleInputs, ['inputFile', 'binary'], execa);113+test('input Uint8Array and stdin can be both set', testMultipleInputs, [0, 'binary'], execa);114+test('stdin and inputFile can be both set', testMultipleInputs, [0, 'inputFile'], execa);115+test('input String, stdin and inputFile can be all set', testMultipleInputs, ['inputFile', 0, 'string'], execa);116+test('input Uint8Array, stdin and inputFile can be all set', testMultipleInputs, ['inputFile', 0, 'binary'], execa);117+test('input String and inputFile can be both set - sync', testMultipleInputs, ['inputFile', 'string'], execaSync);118+test('input String and stdin can be both set - sync', testMultipleInputs, [0, 'string'], execaSync);119+test('input Uint8Array and inputFile can be both set - sync', testMultipleInputs, ['inputFile', 'binary'], execaSync);120+test('input Uint8Array and stdin can be both set - sync', testMultipleInputs, [0, 'binary'], execaSync);121+test('stdin and inputFile can be both set - sync', testMultipleInputs, [0, 'inputFile'], execaSync);122+test('input String, stdin and inputFile can be all set - sync', testMultipleInputs, ['inputFile', 0, 'string'], execaSync);123+test('input Uint8Array, stdin and inputFile can be all set - sync', testMultipleInputs, ['inputFile', 0, 'binary'], execaSync);124+125+const testMultipleOutputs = async (t, mapFile, fdNumber, execaMethod) => {126+ const filePath = tempfile();127+ const filePathTwo = tempfile();128+ await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [mapFile(filePath), mapFile(filePathTwo)]));129+ t.is(await readFile(filePath, 'utf8'), foobarString);130+ t.is(await readFile(filePathTwo, 'utf8'), foobarString);131+ await Promise.all([rm(filePath), rm(filePathTwo)]);132+};133+134+test('stdout can be two file URLs', testMultipleOutputs, pathToFileURL, 1, execa);135+test('stdout can be two file paths', testMultipleOutputs, getAbsolutePath, 1, execa);136+test('stdout can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 1, execaSync);137+test('stdout can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 1, execaSync);138+test('stderr can be two file URLs', testMultipleOutputs, pathToFileURL, 2, execa);139+test('stderr can be two file paths', testMultipleOutputs, getAbsolutePath, 2, execa);140+test('stderr can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 2, execaSync);141+test('stderr can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 2, execaSync);142+test('stdio[*] can be two file URLs', testMultipleOutputs, pathToFileURL, 3, execa);143+test('stdio[*] can be two file paths', testMultipleOutputs, getAbsolutePath, 3, execa);144+test('stdio[*] can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 3, execaSync);145+test('stdio[*] can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 3, execaSync);146+147+const testInputFileHanging = async (t, mapFilePath) => {148+ const filePath = tempfile();149+ await writeFile(filePath, foobarString);150+ await t.throwsAsync(execa('stdin.js', {stdin: mapFilePath(filePath), timeout: 1}), {message: /timed out/});151+ await rm(filePath);152+};153+154+test('Passing an input file path when subprocess exits does not make promise hang', testInputFileHanging, getAbsolutePath);155+test('Passing an input file URL when subprocess exits does not make promise hang', testInputFileHanging, pathToFileURL);added:test/stdio/file-path-mixed.js+94 added
1+import {readFile, writeFile, rm} from 'node:fs/promises';2+import {pathToFileURL} from 'node:url';3+import test from 'ava';4+import tempfile from 'tempfile';5+import {execa, execaSync} from '../../index.js';6+import {setFixtureDir} from '../helpers/fixtures-dir.js';7+import {getStdio} from '../helpers/stdio.js';8+import {foobarString, foobarUppercase} from '../helpers/input.js';9+import {uppercaseGenerator} from '../helpers/generator.js';10+import {getAbsolutePath} from '../helpers/file-path.js';11+12+setFixtureDir();13+14+const testInputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {15+ const filePath = tempfile();16+ await writeFile(filePath, foobarString);17+ const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [18+ new Uint8Array(),19+ mapFile(filePath),20+ uppercaseGenerator(),21+ ]));22+ t.is(stdout, foobarUppercase);23+ await rm(filePath);24+};25+26+test('stdin can use generators together with input file paths', testInputFileTransform, 0, getAbsolutePath, execa);27+test('stdin can use generators together with input file URLs', testInputFileTransform, 0, pathToFileURL, execa);28+test('stdio[*] can use generators together with input file paths', testInputFileTransform, 3, getAbsolutePath, execa);29+test('stdio[*] can use generators together with input file URLs', testInputFileTransform, 3, pathToFileURL, execa);30+test('stdin can use generators together with input file paths, sync', testInputFileTransform, 0, getAbsolutePath, execaSync);31+test('stdin can use generators together with input file URLs, sync', testInputFileTransform, 0, pathToFileURL, execaSync);32+33+const testOutputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {34+ const filePath = tempfile();35+ await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [36+ uppercaseGenerator(),37+ mapFile(filePath),38+ ]));39+ t.is(await readFile(filePath, 'utf8'), `${foobarUppercase}\n`);40+ await rm(filePath);41+};42+43+test('stdout can use generators together with output file paths', testOutputFileTransform, 1, getAbsolutePath, execa);44+test('stdout can use generators together with output file URLs', testOutputFileTransform, 1, pathToFileURL, execa);45+test('stderr can use generators together with output file paths', testOutputFileTransform, 2, getAbsolutePath, execa);46+test('stderr can use generators together with output file URLs', testOutputFileTransform, 2, pathToFileURL, execa);47+test('stdio[*] can use generators together with output file paths', testOutputFileTransform, 3, getAbsolutePath, execa);48+test('stdio[*] can use generators together with output file URLs', testOutputFileTransform, 3, pathToFileURL, execa);49+test('stdout can use generators together with output file paths, sync', testOutputFileTransform, 1, getAbsolutePath, execaSync);50+test('stdout can use generators together with output file URLs, sync', testOutputFileTransform, 1, pathToFileURL, execaSync);51+test('stderr can use generators together with output file paths, sync', testOutputFileTransform, 2, getAbsolutePath, execaSync);52+test('stderr can use generators together with output file URLs, sync', testOutputFileTransform, 2, pathToFileURL, execaSync);53+test('stdio[*] can use generators together with output file paths, sync', testOutputFileTransform, 3, getAbsolutePath, execaSync);54+test('stdio[*] can use generators together with output file URLs, sync', testOutputFileTransform, 3, pathToFileURL, execaSync);55+56+const testOutputFileLines = async (t, fdNumber, mapFile, execaMethod) => {57+ const filePath = tempfile();58+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {59+ ...getStdio(fdNumber, mapFile(filePath)),60+ lines: true,61+ });62+ t.deepEqual(stdio[fdNumber], [foobarString]);63+ t.is(await readFile(filePath, 'utf8'), foobarString);64+ await rm(filePath);65+};66+67+test('stdout can use "lines: true" together with output file paths', testOutputFileLines, 1, getAbsolutePath, execa);68+test('stdout can use "lines: true" together with output file URLs', testOutputFileLines, 1, pathToFileURL, execa);69+test('stderr can use "lines: true" together with output file paths', testOutputFileLines, 2, getAbsolutePath, execa);70+test('stderr can use "lines: true" together with output file URLs', testOutputFileLines, 2, pathToFileURL, execa);71+test('stdio[*] can use "lines: true" together with output file paths', testOutputFileLines, 3, getAbsolutePath, execa);72+test('stdio[*] can use "lines: true" together with output file URLs', testOutputFileLines, 3, pathToFileURL, execa);73+test('stdout can use "lines: true" together with output file paths, sync', testOutputFileLines, 1, getAbsolutePath, execaSync);74+test('stdout can use "lines: true" together with output file URLs, sync', testOutputFileLines, 1, pathToFileURL, execaSync);75+test('stderr can use "lines: true" together with output file paths, sync', testOutputFileLines, 2, getAbsolutePath, execaSync);76+test('stderr can use "lines: true" together with output file URLs, sync', testOutputFileLines, 2, pathToFileURL, execaSync);77+test('stdio[*] can use "lines: true" together with output file paths, sync', testOutputFileLines, 3, getAbsolutePath, execaSync);78+test('stdio[*] can use "lines: true" together with output file URLs, sync', testOutputFileLines, 3, pathToFileURL, execaSync);79+80+const testOutputFileNoBuffer = async (t, buffer, execaMethod) => {81+ const filePath = tempfile();82+ const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {83+ stdout: getAbsolutePath(filePath),84+ buffer,85+ });86+ t.is(stdout, undefined);87+ t.is(await readFile(filePath, 'utf8'), foobarString);88+ await rm(filePath);89+};90+91+test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, false, execa);92+test('stdout can use "buffer: false" together with output file paths, fd-specific', testOutputFileNoBuffer, {stdout: false}, execa);93+test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, false, execaSync);94+test('stdout can use "buffer: false" together with output file paths, fd-specific, sync', testOutputFileNoBuffer, {stdout: false}, execaSync);deleted:test/stdio/file-path.js-396 removed
1-import {readFile, writeFile, rm} from 'node:fs/promises';2-import {relative, dirname, basename} from 'node:path';3-import process from 'node:process';4-import {pathToFileURL} from 'node:url';5-import test from 'ava';6-import {pathExists} from 'path-exists';7-import tempfile from 'tempfile';8-import {execa, execaSync} from '../../index.js';9-import {setFixtureDir} from '../helpers/fixtures-dir.js';10-import {identity, getStdio} from '../helpers/stdio.js';11-import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';12-import {foobarString, foobarUint8Array, foobarUppercase} from '../helpers/input.js';13-import {outputObjectGenerator, uppercaseGenerator, serializeGenerator, throwingGenerator} from '../helpers/generator.js';14-15-setFixtureDir();16-17-const nonFileUrl = new URL('https://example.com');18-19-const getAbsolutePath = file => ({file});20-const getRelativePath = filePath => ({file: relative('.', filePath)});21-22-const getStdioInput = (fdNumberOrName, file) => {23- if (fdNumberOrName === 'string') {24- return {input: foobarString};25- }26-27- if (fdNumberOrName === 'binary') {28- return {input: foobarUint8Array};29- }30-31- return getStdioInputFile(fdNumberOrName, file);32-};33-34-const getStdioInputFile = (fdNumberOrName, file) => getStdio(fdNumberOrName, typeof fdNumberOrName === 'string' ? file : {file});35-36-const testStdinFile = async (t, mapFilePath, fdNumber, execaMethod) => {37- const filePath = tempfile();38- await writeFile(filePath, foobarString);39- const {stdout} = await execaMethod('stdin.js', getStdio(fdNumber, mapFilePath(filePath)));40- t.is(stdout, foobarString);41- await rm(filePath);42-};43-44-test('inputFile can be a file URL', testStdinFile, pathToFileURL, 'inputFile', execa);45-test('stdin can be a file URL', testStdinFile, pathToFileURL, 0, execa);46-test('inputFile can be an absolute file path', testStdinFile, identity, 'inputFile', execa);47-test('stdin can be an absolute file path', testStdinFile, getAbsolutePath, 0, execa);48-test('inputFile can be a relative file path', testStdinFile, identity, 'inputFile', execa);49-test('stdin can be a relative file path', testStdinFile, getRelativePath, 0, execa);50-test('inputFile can be a file URL - sync', testStdinFile, pathToFileURL, 'inputFile', execaSync);51-test('stdin can be a file URL - sync', testStdinFile, pathToFileURL, 0, execaSync);52-test('inputFile can be an absolute file path - sync', testStdinFile, identity, 'inputFile', execaSync);53-test('stdin can be an absolute file path - sync', testStdinFile, getAbsolutePath, 0, execaSync);54-test('inputFile can be a relative file path - sync', testStdinFile, identity, 'inputFile', execaSync);55-test('stdin can be a relative file path - sync', testStdinFile, getRelativePath, 0, execaSync);56-57-const testOutputFile = async (t, mapFile, fdNumber, execaMethod) => {58- const filePath = tempfile();59- await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, mapFile(filePath)));60- t.is(await readFile(filePath, 'utf8'), foobarString);61- await rm(filePath);62-};63-64-test('stdout can be a file URL', testOutputFile, pathToFileURL, 1, execa);65-test('stderr can be a file URL', testOutputFile, pathToFileURL, 2, execa);66-test('stdio[*] can be a file URL', testOutputFile, pathToFileURL, 3, execa);67-test('stdout can be an absolute file path', testOutputFile, getAbsolutePath, 1, execa);68-test('stderr can be an absolute file path', testOutputFile, getAbsolutePath, 2, execa);69-test('stdio[*] can be an absolute file path', testOutputFile, getAbsolutePath, 3, execa);70-test('stdout can be a relative file path', testOutputFile, getRelativePath, 1, execa);71-test('stderr can be a relative file path', testOutputFile, getRelativePath, 2, execa);72-test('stdio[*] can be a relative file path', testOutputFile, getRelativePath, 3, execa);73-test('stdout can be a file URL - sync', testOutputFile, pathToFileURL, 1, execaSync);74-test('stderr can be a file URL - sync', testOutputFile, pathToFileURL, 2, execaSync);75-test('stdio[*] can be a file URL - sync', testOutputFile, pathToFileURL, 3, execaSync);76-test('stdout can be an absolute file path - sync', testOutputFile, getAbsolutePath, 1, execaSync);77-test('stderr can be an absolute file path - sync', testOutputFile, getAbsolutePath, 2, execaSync);78-test('stdio[*] can be an absolute file path - sync', testOutputFile, getAbsolutePath, 3, execaSync);79-test('stdout can be a relative file path - sync', testOutputFile, getRelativePath, 1, execaSync);80-test('stderr can be a relative file path - sync', testOutputFile, getRelativePath, 2, execaSync);81-test('stdio[*] can be a relative file path - sync', testOutputFile, getRelativePath, 3, execaSync);82-83-const testStdioNonFileUrl = (t, fdNumber, execaMethod) => {84- t.throws(() => {85- execaMethod('empty.js', getStdio(fdNumber, nonFileUrl));86- }, {message: /pathToFileURL/});87-};88-89-test('inputFile cannot be a non-file URL', testStdioNonFileUrl, 'inputFile', execa);90-test('stdin cannot be a non-file URL', testStdioNonFileUrl, 0, execa);91-test('stdout cannot be a non-file URL', testStdioNonFileUrl, 1, execa);92-test('stderr cannot be a non-file URL', testStdioNonFileUrl, 2, execa);93-test('stdio[*] cannot be a non-file URL', testStdioNonFileUrl, 3, execa);94-test('inputFile cannot be a non-file URL - sync', testStdioNonFileUrl, 'inputFile', execaSync);95-test('stdin cannot be a non-file URL - sync', testStdioNonFileUrl, 0, execaSync);96-test('stdout cannot be a non-file URL - sync', testStdioNonFileUrl, 1, execaSync);97-test('stderr cannot be a non-file URL - sync', testStdioNonFileUrl, 2, execaSync);98-test('stdio[*] cannot be a non-file URL - sync', testStdioNonFileUrl, 3, execaSync);99-100-const testInvalidInputFile = (t, execaMethod) => {101- t.throws(() => {102- execaMethod('empty.js', getStdio('inputFile', false));103- }, {message: /a file path string or a file URL/});104-};105-106-test('inputFile must be a file URL or string', testInvalidInputFile, execa);107-test('inputFile must be a file URL or string - sync', testInvalidInputFile, execaSync);108-109-const testInputFileValidUrl = async (t, fdNumber, execaMethod) => {110- const filePath = tempfile();111- await writeFile(filePath, foobarString);112- const currentCwd = process.cwd();113- process.chdir(dirname(filePath));114-115- try {116- const {stdout} = await execaMethod('stdin.js', getStdioInputFile(fdNumber, basename(filePath)));117- t.is(stdout, foobarString);118- } finally {119- process.chdir(currentCwd);120- await rm(filePath);121- }122-};123-124-test.serial('inputFile does not need to start with . when being a relative file path', testInputFileValidUrl, 'inputFile', execa);125-test.serial('stdin does not need to start with . when being a relative file path', testInputFileValidUrl, 0, execa);126-test.serial('inputFile does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 'inputFile', execaSync);127-test.serial('stdin does not need to start with . when being a relative file path - sync', testInputFileValidUrl, 0, execaSync);128-129-const testFilePathObject = (t, fdNumber, execaMethod) => {130- t.throws(() => {131- execaMethod('empty.js', getStdio(fdNumber, foobarString));132- }, {message: /must be used/});133-};134-135-test('stdin must be an object when it is a file path string', testFilePathObject, 0, execa);136-test('stdout must be an object when it is a file path string', testFilePathObject, 1, execa);137-test('stderr must be an object when it is a file path string', testFilePathObject, 2, execa);138-test('stdio[*] must be an object when it is a file path string', testFilePathObject, 3, execa);139-test('stdin be an object when it is a file path string - sync', testFilePathObject, 0, execaSync);140-test('stdout be an object when it is a file path string - sync', testFilePathObject, 1, execaSync);141-test('stderr be an object when it is a file path string - sync', testFilePathObject, 2, execaSync);142-test('stdio[*] must be an object when it is a file path string - sync', testFilePathObject, 3, execaSync);143-144-const testFileError = async (t, fixtureName, mapFile, fdNumber) => {145- await t.throwsAsync(146- execa(fixtureName, [`${fdNumber}`], getStdio(fdNumber, mapFile('./unknown/file'))),147- {code: 'ENOENT'},148- );149-};150-151-test.serial('inputFile file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 'inputFile');152-test.serial('stdin file URL errors should be handled', testFileError, 'stdin-fd.js', pathToFileURL, 0);153-test.serial('stdout file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 1);154-test.serial('stderr file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 2);155-test.serial('stdio[*] file URL errors should be handled', testFileError, 'noop-fd.js', pathToFileURL, 3);156-test.serial('inputFile file path errors should be handled', testFileError, 'stdin-fd.js', identity, 'inputFile');157-test.serial('stdin file path errors should be handled', testFileError, 'stdin-fd.js', getAbsolutePath, 0);158-test.serial('stdout file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 1);159-test.serial('stderr file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 2);160-test.serial('stdio[*] file path errors should be handled', testFileError, 'noop-fd.js', getAbsolutePath, 3);161-162-const testFileErrorSync = (t, mapFile, fdNumber) => {163- t.throws(() => {164- execaSync('empty.js', getStdio(fdNumber, mapFile('./unknown/file')));165- }, {code: 'ENOENT'});166-};167-168-test('inputFile file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 'inputFile');169-test('stdin file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 0);170-test('stdout file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 1);171-test('stderr file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 2);172-test('stdio[*] file URL errors should be handled - sync', testFileErrorSync, pathToFileURL, 3);173-test('inputFile file path errors should be handled - sync', testFileErrorSync, identity, 'inputFile');174-test('stdin file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 0);175-test('stdout file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 1);176-test('stderr file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 2);177-test('stdio[*] file path errors should be handled - sync', testFileErrorSync, getAbsolutePath, 3);178-179-const testMultipleInputs = async (t, indices, execaMethod) => {180- const filePath = tempfile();181- await writeFile(filePath, foobarString);182- const options = Object.assign({}, ...indices.map(fdNumber => getStdioInput(fdNumber, filePath)));183- const {stdout} = await execaMethod('stdin.js', options);184- t.is(stdout, foobarString.repeat(indices.length));185- await rm(filePath);186-};187-188-test('inputFile can be set', testMultipleInputs, ['inputFile'], runExeca);189-test('inputFile can be set - sync', testMultipleInputs, ['inputFile'], runExecaSync);190-test('inputFile can be set with $', testMultipleInputs, ['inputFile'], runScript);191-test('inputFile can be set with $.sync', testMultipleInputs, ['inputFile'], runScriptSync);192-test('input String and inputFile can be both set', testMultipleInputs, ['inputFile', 'string'], execa);193-test('input String and stdin can be both set', testMultipleInputs, [0, 'string'], execa);194-test('input Uint8Array and inputFile can be both set', testMultipleInputs, ['inputFile', 'binary'], execa);195-test('input Uint8Array and stdin can be both set', testMultipleInputs, [0, 'binary'], execa);196-test('stdin and inputFile can be both set', testMultipleInputs, [0, 'inputFile'], execa);197-test('input String, stdin and inputFile can be all set', testMultipleInputs, ['inputFile', 0, 'string'], execa);198-test('input Uint8Array, stdin and inputFile can be all set', testMultipleInputs, ['inputFile', 0, 'binary'], execa);199-test('input String and inputFile can be both set - sync', testMultipleInputs, ['inputFile', 'string'], execaSync);200-test('input String and stdin can be both set - sync', testMultipleInputs, [0, 'string'], execaSync);201-test('input Uint8Array and inputFile can be both set - sync', testMultipleInputs, ['inputFile', 'binary'], execaSync);202-test('input Uint8Array and stdin can be both set - sync', testMultipleInputs, [0, 'binary'], execaSync);203-test('stdin and inputFile can be both set - sync', testMultipleInputs, [0, 'inputFile'], execaSync);204-test('input String, stdin and inputFile can be all set - sync', testMultipleInputs, ['inputFile', 0, 'string'], execaSync);205-test('input Uint8Array, stdin and inputFile can be all set - sync', testMultipleInputs, ['inputFile', 0, 'binary'], execaSync);206-207-const testMultipleOutputs = async (t, mapFile, fdNumber, execaMethod) => {208- const filePath = tempfile();209- const filePathTwo = tempfile();210- await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [mapFile(filePath), mapFile(filePathTwo)]));211- t.is(await readFile(filePath, 'utf8'), foobarString);212- t.is(await readFile(filePathTwo, 'utf8'), foobarString);213- await Promise.all([rm(filePath), rm(filePathTwo)]);214-};215-216-test('stdout can be two file URLs', testMultipleOutputs, pathToFileURL, 1, execa);217-test('stdout can be two file paths', testMultipleOutputs, getAbsolutePath, 1, execa);218-test('stdout can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 1, execaSync);219-test('stdout can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 1, execaSync);220-test('stderr can be two file URLs', testMultipleOutputs, pathToFileURL, 2, execa);221-test('stderr can be two file paths', testMultipleOutputs, getAbsolutePath, 2, execa);222-test('stderr can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 2, execaSync);223-test('stderr can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 2, execaSync);224-test('stdio[*] can be two file URLs', testMultipleOutputs, pathToFileURL, 3, execa);225-test('stdio[*] can be two file paths', testMultipleOutputs, getAbsolutePath, 3, execa);226-test('stdio[*] can be two file URLs - sync', testMultipleOutputs, pathToFileURL, 3, execaSync);227-test('stdio[*] can be two file paths - sync', testMultipleOutputs, getAbsolutePath, 3, execaSync);228-229-const testInputFileHanging = async (t, mapFilePath) => {230- const filePath = tempfile();231- await writeFile(filePath, foobarString);232- await t.throwsAsync(execa('stdin.js', {stdin: mapFilePath(filePath), timeout: 1}), {message: /timed out/});233- await rm(filePath);234-};235-236-test('Passing an input file path when subprocess exits does not make promise hang', testInputFileHanging, getAbsolutePath);237-test('Passing an input file URL when subprocess exits does not make promise hang', testInputFileHanging, pathToFileURL);238-239-const 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-};250-251-test('stdin can use generators together with input file paths', testInputFileTransform, 0, getAbsolutePath, execa);252-test('stdin can use generators together with input file URLs', testInputFileTransform, 0, pathToFileURL, execa);253-test('stdio[*] can use generators together with input file paths', testInputFileTransform, 3, getAbsolutePath, execa);254-test('stdio[*] can use generators together with input file URLs', testInputFileTransform, 3, pathToFileURL, execa);255-test('stdin can use generators together with input file paths, sync', testInputFileTransform, 0, getAbsolutePath, execaSync);256-test('stdin can use generators together with input file URLs, sync', testInputFileTransform, 0, pathToFileURL, execaSync);257-258-const 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-};270-271-test('stdin cannot use objectMode together with input file paths', testInputFileObject, 0, getAbsolutePath, execa);272-test('stdin cannot use objectMode together with input file URLs', testInputFileObject, 0, pathToFileURL, execa);273-test('stdio[*] cannot use objectMode together with input file paths', testInputFileObject, 3, getAbsolutePath, execa);274-test('stdio[*] cannot use objectMode together with input file URLs', testInputFileObject, 3, pathToFileURL, execa);275-test('stdin cannot use objectMode together with input file paths, sync', testInputFileObject, 0, getAbsolutePath, execaSync);276-test('stdin cannot use objectMode together with input file URLs, sync', testInputFileObject, 0, pathToFileURL, execaSync);277-278-const 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-};287-288-test('stdout can use generators together with output file paths', testOutputFileTransform, 1, getAbsolutePath, execa);289-test('stdout can use generators together with output file URLs', testOutputFileTransform, 1, pathToFileURL, execa);290-test('stderr can use generators together with output file paths', testOutputFileTransform, 2, getAbsolutePath, execa);291-test('stderr can use generators together with output file URLs', testOutputFileTransform, 2, pathToFileURL, execa);292-test('stdio[*] can use generators together with output file paths', testOutputFileTransform, 3, getAbsolutePath, execa);293-test('stdio[*] can use generators together with output file URLs', testOutputFileTransform, 3, pathToFileURL, execa);294-test('stdout can use generators together with output file paths, sync', testOutputFileTransform, 1, getAbsolutePath, execaSync);295-test('stdout can use generators together with output file URLs, sync', testOutputFileTransform, 1, pathToFileURL, execaSync);296-test('stderr can use generators together with output file paths, sync', testOutputFileTransform, 2, getAbsolutePath, execaSync);297-test('stderr can use generators together with output file URLs, sync', testOutputFileTransform, 2, pathToFileURL, execaSync);298-test('stdio[*] can use generators together with output file paths, sync', testOutputFileTransform, 3, getAbsolutePath, execaSync);299-test('stdio[*] can use generators together with output file URLs, sync', testOutputFileTransform, 3, pathToFileURL, execaSync);300-301-const testOutputFileLines = async (t, fdNumber, mapFile, execaMethod) => {302- const filePath = tempfile();303- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {304- ...getStdio(fdNumber, mapFile(filePath)),305- lines: true,306- });307- t.deepEqual(stdio[fdNumber], [foobarString]);308- t.is(await readFile(filePath, 'utf8'), foobarString);309- await rm(filePath);310-};311-312-test('stdout can use "lines: true" together with output file paths', testOutputFileLines, 1, getAbsolutePath, execa);313-test('stdout can use "lines: true" together with output file URLs', testOutputFileLines, 1, pathToFileURL, execa);314-test('stderr can use "lines: true" together with output file paths', testOutputFileLines, 2, getAbsolutePath, execa);315-test('stderr can use "lines: true" together with output file URLs', testOutputFileLines, 2, pathToFileURL, execa);316-test('stdio[*] can use "lines: true" together with output file paths', testOutputFileLines, 3, getAbsolutePath, execa);317-test('stdio[*] can use "lines: true" together with output file URLs', testOutputFileLines, 3, pathToFileURL, execa);318-test('stdout can use "lines: true" together with output file paths, sync', testOutputFileLines, 1, getAbsolutePath, execaSync);319-test('stdout can use "lines: true" together with output file URLs, sync', testOutputFileLines, 1, pathToFileURL, execaSync);320-test('stderr can use "lines: true" together with output file paths, sync', testOutputFileLines, 2, getAbsolutePath, execaSync);321-test('stderr can use "lines: true" together with output file URLs, sync', testOutputFileLines, 2, pathToFileURL, execaSync);322-test('stdio[*] can use "lines: true" together with output file paths, sync', testOutputFileLines, 3, getAbsolutePath, execaSync);323-test('stdio[*] can use "lines: true" together with output file URLs, sync', testOutputFileLines, 3, pathToFileURL, execaSync);324-325-const testOutputFileNoBuffer = async (t, buffer, execaMethod) => {326- const filePath = tempfile();327- const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {328- stdout: getAbsolutePath(filePath),329- buffer,330- });331- t.is(stdout, undefined);332- t.is(await readFile(filePath, 'utf8'), foobarString);333- await rm(filePath);334-};335-336-test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, false, execa);337-test('stdout can use "buffer: false" together with output file paths, fd-specific', testOutputFileNoBuffer, {stdout: false}, execa);338-test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, false, execaSync);339-test('stdout can use "buffer: false" together with output file paths, fd-specific, sync', testOutputFileNoBuffer, {stdout: false}, execaSync);340-341-const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {342- const filePath = tempfile();343- t.throws(() => {344- execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [345- outputObjectGenerator(),346- mapFile(filePath),347- ]));348- }, {message: /cannot use both files and transforms in objectMode/});349- t.false(await pathExists(filePath));350-};351-352-test('stdout cannot use objectMode together with output file paths', testOutputFileObject, 1, getAbsolutePath, execa);353-test('stdout cannot use objectMode together with output file URLs', testOutputFileObject, 1, pathToFileURL, execa);354-test('stderr cannot use objectMode together with output file paths', testOutputFileObject, 2, getAbsolutePath, execa);355-test('stderr cannot use objectMode together with output file URLs', testOutputFileObject, 2, pathToFileURL, execa);356-test('stdio[*] cannot use objectMode together with output file paths', testOutputFileObject, 3, getAbsolutePath, execa);357-test('stdio[*] cannot use objectMode together with output file URLs', testOutputFileObject, 3, pathToFileURL, execa);358-test('stdout cannot use objectMode together with output file paths, sync', testOutputFileObject, 1, getAbsolutePath, execaSync);359-test('stdout cannot use objectMode together with output file URLs, sync', testOutputFileObject, 1, pathToFileURL, execaSync);360-test('stderr cannot use objectMode together with output file paths, sync', testOutputFileObject, 2, getAbsolutePath, execaSync);361-test('stderr cannot use objectMode together with output file URLs, sync', testOutputFileObject, 2, pathToFileURL, execaSync);362-test('stdio[*] cannot use objectMode together with output file paths, sync', testOutputFileObject, 3, getAbsolutePath, execaSync);363-test('stdio[*] cannot use objectMode together with output file URLs, sync', testOutputFileObject, 3, pathToFileURL, execaSync);364-365-test('Generator error stops writing to output file', async t => {366- const filePath = tempfile();367- const cause = new Error(foobarString);368- const error = await t.throwsAsync(execa('noop.js', {369- stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],370- }));371- t.is(error.cause, cause);372- t.is(await readFile(filePath, 'utf8'), '');373-});374-375-test('Generator error does not create output file, sync', async t => {376- const filePath = tempfile();377- const cause = new Error(foobarString);378- const error = t.throws(() => {379- execaSync('noop.js', {380- stdout: [throwingGenerator(cause)(), getAbsolutePath(filePath)],381- });382- });383- t.is(error.cause, cause);384- t.false(await pathExists(filePath));385-});386-387-test('Output file error still returns transformed output, sync', async t => {388- const filePath = tempfile();389- const {stdout} = t.throws(() => {390- execaSync('noop-fd.js', ['1', foobarString], {391- stdout: [uppercaseGenerator(), getAbsolutePath('./unknown/file')],392- });393- }, {code: 'ENOENT'});394- t.false(await pathExists(filePath));395- t.is(stdout, foobarUppercase);396-});added:test/stdio/generator-return.js+150 added
1+import {Buffer} from 'node:buffer';2+import test from 'ava';3+import {execa, execaSync} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {foobarString, foobarUint8Array} from '../helpers/input.js';6+import {getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';7+8+setFixtureDir();9+10+// eslint-disable-next-line max-params11+const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final, execaMethod) => {12+ const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';13+ const {stdout} = await execaMethod(fixtureName, ['1', foobarString], {14+ stdout: convertTransformToFinal(getOutputGenerator(input)(objectMode, true), final),15+ encoding,16+ reject,17+ });18+ const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;19+ const output = Buffer.from(typeofChunk, encoding === 'buffer' || objectMode ? undefined : encoding).toString();20+ t.is(output, foobarString);21+};22+23+test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false, execa);24+test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false, execa);25+test('Generator can return string with encoding "utf16le"', testGeneratorReturnType, foobarString, 'utf16le', true, false, false, execa);26+test('Generator can return Uint8Array with encoding "utf16le"', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, false, execa);27+test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false, execa);28+test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false, execa);29+test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false, execa);30+test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false, execa);31+test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false, execa);32+test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false, execa);33+test('Generator can return string with encoding "utf16le", failure', testGeneratorReturnType, foobarString, 'utf16le', false, false, false, execa);34+test('Generator can return Uint8Array with encoding "utf16le", failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, false, execa);35+test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false, execa);36+test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false, execa);37+test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false, execa);38+test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false, execa);39+test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false, execa);40+test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false, execa);41+test('Generator can return string with encoding "utf16le", objectMode', testGeneratorReturnType, foobarString, 'utf16le', true, true, false, execa);42+test('Generator can return Uint8Array with encoding "utf16le", objectMode', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, false, execa);43+test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false, execa);44+test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false, execa);45+test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false, execa);46+test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false, execa);47+test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false, execa);48+test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false, execa);49+test('Generator can return string with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarString, 'utf16le', false, true, false, execa);50+test('Generator can return Uint8Array with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, false, execa);51+test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false, execa);52+test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false, execa);53+test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false, execa);54+test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false, execa);55+test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true, execa);56+test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true, execa);57+test('Generator can return final string with encoding "utf16le"', testGeneratorReturnType, foobarString, 'utf16le', true, false, true, execa);58+test('Generator can return final Uint8Array with encoding "utf16le"', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, true, execa);59+test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true, execa);60+test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true, execa);61+test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true, execa);62+test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true, execa);63+test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true, execa);64+test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true, execa);65+test('Generator can return final string with encoding "utf16le", failure', testGeneratorReturnType, foobarString, 'utf16le', false, false, true, execa);66+test('Generator can return final Uint8Array with encoding "utf16le", failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, true, execa);67+test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true, execa);68+test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true, execa);69+test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true, execa);70+test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true, execa);71+test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true, execa);72+test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true, execa);73+test('Generator can return final string with encoding "utf16le", objectMode', testGeneratorReturnType, foobarString, 'utf16le', true, true, true, execa);74+test('Generator can return final Uint8Array with encoding "utf16le", objectMode', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, true, execa);75+test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true, execa);76+test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true, execa);77+test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true, execa);78+test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true, execa);79+test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true, execa);80+test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true, execa);81+test('Generator can return final string with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarString, 'utf16le', false, true, true, execa);82+test('Generator can return final Uint8Array with encoding "utf16le", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, true, execa);83+test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true, execa);84+test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true, execa);85+test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true, execa);86+test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true, execa);87+test('Generator can return string with default encoding, sync', testGeneratorReturnType, foobarString, 'utf8', true, false, false, execaSync);88+test('Generator can return Uint8Array with default encoding, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false, execaSync);89+test('Generator can return string with encoding "utf16le", sync', testGeneratorReturnType, foobarString, 'utf16le', true, false, false, execaSync);90+test('Generator can return Uint8Array with encoding "utf16le", sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, false, execaSync);91+test('Generator can return string with encoding "buffer", sync', testGeneratorReturnType, foobarString, 'buffer', true, false, false, execaSync);92+test('Generator can return Uint8Array with encoding "buffer", sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false, execaSync);93+test('Generator can return string with encoding "hex", sync', testGeneratorReturnType, foobarString, 'hex', true, false, false, execaSync);94+test('Generator can return Uint8Array with encoding "hex", sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false, execaSync);95+test('Generator can return string with default encoding, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, false, false, execaSync);96+test('Generator can return Uint8Array with default encoding, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false, execaSync);97+test('Generator can return string with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, false, false, execaSync);98+test('Generator can return Uint8Array with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, false, execaSync);99+test('Generator can return string with encoding "buffer", failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, false, false, execaSync);100+test('Generator can return Uint8Array with encoding "buffer", failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false, execaSync);101+test('Generator can return string with encoding "hex", failure, sync', testGeneratorReturnType, foobarString, 'hex', false, false, false, execaSync);102+test('Generator can return Uint8Array with encoding "hex", failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false, execaSync);103+test('Generator can return string with default encoding, objectMode, sync', testGeneratorReturnType, foobarString, 'utf8', true, true, false, execaSync);104+test('Generator can return Uint8Array with default encoding, objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false, execaSync);105+test('Generator can return string with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarString, 'utf16le', true, true, false, execaSync);106+test('Generator can return Uint8Array with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, false, execaSync);107+test('Generator can return string with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarString, 'buffer', true, true, false, execaSync);108+test('Generator can return Uint8Array with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false, execaSync);109+test('Generator can return string with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarString, 'hex', true, true, false, execaSync);110+test('Generator can return Uint8Array with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false, execaSync);111+test('Generator can return string with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, true, false, execaSync);112+test('Generator can return Uint8Array with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false, execaSync);113+test('Generator can return string with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, true, false, execaSync);114+test('Generator can return Uint8Array with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, false, execaSync);115+test('Generator can return string with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, true, false, execaSync);116+test('Generator can return Uint8Array with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false, execaSync);117+test('Generator can return string with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'hex', false, true, false, execaSync);118+test('Generator can return Uint8Array with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false, execaSync);119+test('Generator can return final string with default encoding, sync', testGeneratorReturnType, foobarString, 'utf8', true, false, true, execaSync);120+test('Generator can return final Uint8Array with default encoding, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true, execaSync);121+test('Generator can return final string with encoding "utf16le", sync', testGeneratorReturnType, foobarString, 'utf16le', true, false, true, execaSync);122+test('Generator can return final Uint8Array with encoding "utf16le", sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, false, true, execaSync);123+test('Generator can return final string with encoding "buffer", sync', testGeneratorReturnType, foobarString, 'buffer', true, false, true, execaSync);124+test('Generator can return final Uint8Array with encoding "buffer", sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true, execaSync);125+test('Generator can return final string with encoding "hex", sync', testGeneratorReturnType, foobarString, 'hex', true, false, true, execaSync);126+test('Generator can return final Uint8Array with encoding "hex", sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true, execaSync);127+test('Generator can return final string with default encoding, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, false, true, execaSync);128+test('Generator can return final Uint8Array with default encoding, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true, execaSync);129+test('Generator can return final string with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, false, true, execaSync);130+test('Generator can return final Uint8Array with encoding "utf16le", failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, false, true, execaSync);131+test('Generator can return final string with encoding "buffer", failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, false, true, execaSync);132+test('Generator can return final Uint8Array with encoding "buffer", failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true, execaSync);133+test('Generator can return final string with encoding "hex", failure, sync', testGeneratorReturnType, foobarString, 'hex', false, false, true, execaSync);134+test('Generator can return final Uint8Array with encoding "hex", failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true, execaSync);135+test('Generator can return final string with default encoding, objectMode, sync', testGeneratorReturnType, foobarString, 'utf8', true, true, true, execaSync);136+test('Generator can return final Uint8Array with default encoding, objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true, execaSync);137+test('Generator can return final string with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarString, 'utf16le', true, true, true, execaSync);138+test('Generator can return final Uint8Array with encoding "utf16le", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', true, true, true, execaSync);139+test('Generator can return final string with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarString, 'buffer', true, true, true, execaSync);140+test('Generator can return final Uint8Array with encoding "buffer", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true, execaSync);141+test('Generator can return final string with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarString, 'hex', true, true, true, execaSync);142+test('Generator can return final Uint8Array with encoding "hex", objectMode, sync', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true, execaSync);143+test('Generator can return final string with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf8', false, true, true, execaSync);144+test('Generator can return final Uint8Array with default encoding, objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true, execaSync);145+test('Generator can return final string with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'utf16le', false, true, true, execaSync);146+test('Generator can return final Uint8Array with encoding "utf16le", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'utf16le', false, true, true, execaSync);147+test('Generator can return final string with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'buffer', false, true, true, execaSync);148+test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true, execaSync);149+test('Generator can return final string with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarString, 'hex', false, true, true, execaSync);150+test('Generator can return final Uint8Array with encoding "hex", objectMode, failure, sync', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true, execaSync);deleted:test/stdio/generator.js-792 removed
1-import {Buffer} from 'node:buffer';2-import {readFile, writeFile, rm} from 'node:fs/promises';3-import {PassThrough} from 'node:stream';4-import test from 'ava';5-import getStream, {getStreamAsArray} from 'get-stream';6-import tempfile from 'tempfile';7-import {execa, execaSync} from '../../index.js';8-import {setFixtureDir} from '../helpers/fixtures-dir.js';9-import {getStdio} from '../helpers/stdio.js';10-import {11- foobarString,12- foobarUppercase,13- foobarHex,14- foobarUint8Array,15- foobarBuffer,16- foobarObject,17- foobarObjectString,18-} from '../helpers/input.js';19-import {20- outputObjectGenerator,21- uppercaseGenerator,22- uppercaseBufferGenerator,23- appendGenerator,24- appendAsyncGenerator,25- casedSuffix,26-} from '../helpers/generator.js';27-import {appendDuplex, uppercaseBufferDuplex} from '../helpers/duplex.js';28-import {appendWebTransform, uppercaseBufferWebTransform} from '../helpers/web-transform.js';29-import {generatorsMap} from '../helpers/map.js';30-31-setFixtureDir();32-33-const textEncoder = new TextEncoder();34-35-const getInputObjectMode = (objectMode, addNoopTransform, type) => objectMode36- ? {37- input: [foobarObject],38- generators: generatorsMap[type].addNoop(generatorsMap[type].serialize(objectMode), addNoopTransform, objectMode),39- output: foobarObjectString,40- }41- : {42- input: foobarUint8Array,43- generators: generatorsMap[type].addNoop(generatorsMap[type].uppercase(objectMode), addNoopTransform, objectMode),44- output: foobarUppercase,45- };46-47-const getOutputObjectMode = (objectMode, addNoopTransform, type, binary) => objectMode48- ? {49- generators: generatorsMap[type].addNoop(generatorsMap[type].outputObject(), addNoopTransform, objectMode, binary),50- output: [foobarObject],51- getStreamMethod: getStreamAsArray,52- }53- : {54- generators: generatorsMap[type].addNoop(generatorsMap[type].uppercaseBuffer(objectMode, true), addNoopTransform, objectMode, binary),55- output: foobarUppercase,56- getStreamMethod: getStream,57- };58-59-// eslint-disable-next-line max-params60-const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform, type, execaMethod) => {61- const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);62- const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, ...generators]));63- t.is(stdout, output);64-};65-66-test('Can use generators with result.stdin', testGeneratorInput, 0, false, false, 'generator', execa);67-test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'generator', execa);68-test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'generator', execa);69-test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'generator', execa);70-test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'generator', execa);71-test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'generator', execa);72-test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'generator', execa);73-test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'generator', execa);74-test('Can use generators with result.stdin, sync', testGeneratorInput, 0, false, false, 'generator', execaSync);75-test('Can use generators with result.stdin, objectMode, sync', testGeneratorInput, 0, true, false, 'generator', execaSync);76-test('Can use generators with result.stdin, noop transform, sync', testGeneratorInput, 0, false, true, 'generator', execaSync);77-test('Can use generators with result.stdin, objectMode, noop transform, sync', testGeneratorInput, 0, true, true, 'generator', execaSync);78-test('Can use duplexes with result.stdin', testGeneratorInput, 0, false, false, 'duplex', execa);79-test('Can use duplexes with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'duplex', execa);80-test('Can use duplexes with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'duplex', execa);81-test('Can use duplexes with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'duplex', execa);82-test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex', execa);83-test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex', execa);84-test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex', execa);85-test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex', execa);86-test('Can use webTransforms with result.stdin', testGeneratorInput, 0, false, false, 'webTransform', execa);87-test('Can use webTransforms with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'webTransform', execa);88-test('Can use webTransforms with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'webTransform', execa);89-test('Can use webTransforms with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'webTransform', execa);90-test('Can use webTransforms with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'webTransform', execa);91-test('Can use webTransforms with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'webTransform', execa);92-test('Can use webTransforms with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'webTransform', execa);93-test('Can use webTransforms with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'webTransform', execa);94-95-// eslint-disable-next-line max-params96-const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {97- const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);98- const subprocess = execa('stdin-fd.js', ['0'], getStdio(0, generators));99- const stream = useShortcutProperty ? subprocess.stdin : subprocess.stdio[0];100- stream.end(...input);101- const {stdout} = await subprocess;102- const expectedOutput = input[1] === 'utf16le' ? Buffer.from(output, input[1]).toString() : output;103- t.is(stdout, expectedOutput);104-};105-106-test('Can use generators with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'generator', [foobarString, 'utf8']);107-test('Can use generators with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'generator', [foobarString, 'utf8']);108-test('Can use generators with subprocess.stdio[0] and encoding "utf16le"', testGeneratorInputPipe, false, false, false, 'generator', [foobarString, 'utf16le']);109-test('Can use generators with subprocess.stdin and encoding "utf16le"', testGeneratorInputPipe, true, false, false, 'generator', [foobarString, 'utf16le']);110-test('Can use generators with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'generator', [foobarBuffer, 'buffer']);111-test('Can use generators with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'generator', [foobarBuffer, 'buffer']);112-test('Can use generators with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'generator', [foobarHex, 'hex']);113-test('Can use generators with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'generator', [foobarHex, 'hex']);114-test('Can use generators with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'generator', [foobarObject]);115-test('Can use generators with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'generator', [foobarObject]);116-test('Can use generators with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarString, 'utf8']);117-test('Can use generators with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarString, 'utf8']);118-test('Can use generators with subprocess.stdio[0] and encoding "utf16le", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarString, 'utf16le']);119-test('Can use generators with subprocess.stdin and encoding "utf16le", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarString, 'utf16le']);120-test('Can use generators with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarBuffer, 'buffer']);121-test('Can use generators with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarBuffer, 'buffer']);122-test('Can use generators with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarHex, 'hex']);123-test('Can use generators with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarHex, 'hex']);124-test('Can use generators with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'generator', [foobarObject]);125-test('Can use generators with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'generator', [foobarObject]);126-test('Can use duplexes with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'duplex', [foobarString, 'utf8']);127-test('Can use duplexes with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'duplex', [foobarString, 'utf8']);128-test('Can use duplexes with subprocess.stdio[0] and encoding "utf16le"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarString, 'utf16le']);129-test('Can use duplexes with subprocess.stdin and encoding "utf16le"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarString, 'utf16le']);130-test('Can use duplexes with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarBuffer, 'buffer']);131-test('Can use duplexes with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarBuffer, 'buffer']);132-test('Can use duplexes with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarHex, 'hex']);133-test('Can use duplexes with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarHex, 'hex']);134-test('Can use duplexes with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'duplex', [foobarObject]);135-test('Can use duplexes with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'duplex', [foobarObject]);136-test('Can use duplexes with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarString, 'utf8']);137-test('Can use duplexes with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarString, 'utf8']);138-test('Can use duplexes with subprocess.stdio[0] and encoding "utf16le", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarString, 'utf16le']);139-test('Can use duplexes with subprocess.stdin and encoding "utf16le", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarString, 'utf16le']);140-test('Can use duplexes with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarBuffer, 'buffer']);141-test('Can use duplexes with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarBuffer, 'buffer']);142-test('Can use duplexes with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarHex, 'hex']);143-test('Can use duplexes with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarHex, 'hex']);144-test('Can use duplexes with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'duplex', [foobarObject]);145-test('Can use duplexes with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'duplex', [foobarObject]);146-test('Can use webTransforms with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarString, 'utf8']);147-test('Can use webTransforms with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarString, 'utf8']);148-test('Can use webTransforms with subprocess.stdio[0] and encoding "utf16le"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarString, 'utf16le']);149-test('Can use webTransforms with subprocess.stdin and encoding "utf16le"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarString, 'utf16le']);150-test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarBuffer, 'buffer']);151-test('Can use webTransforms with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarBuffer, 'buffer']);152-test('Can use webTransforms with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarHex, 'hex']);153-test('Can use webTransforms with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarHex, 'hex']);154-test('Can use webTransforms with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'webTransform', [foobarObject]);155-test('Can use webTransforms with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'webTransform', [foobarObject]);156-test('Can use webTransforms with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarString, 'utf8']);157-test('Can use webTransforms with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarString, 'utf8']);158-test('Can use webTransforms with subprocess.stdio[0] and encoding "utf16le", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarString, 'utf16le']);159-test('Can use webTransforms with subprocess.stdin and encoding "utf16le", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarString, 'utf16le']);160-test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarBuffer, 'buffer']);161-test('Can use webTransforms with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarBuffer, 'buffer']);162-test('Can use webTransforms with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarHex, 'hex']);163-test('Can use webTransforms with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarHex, 'hex']);164-test('Can use webTransforms with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'webTransform', [foobarObject]);165-test('Can use webTransforms with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'webTransform', [foobarObject]);166-167-const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform, type) => {168- const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);169- const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, [[], ...generators]));170- subprocess.stdio[3].write(Array.isArray(input) ? input[0] : input);171- const {stdout} = await subprocess;172- t.is(stdout, output);173-};174-175-test('Can use generators with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'generator');176-test('Can use generators with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'generator');177-test('Can use generators with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'generator');178-test('Can use generators with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'generator');179-test('Can use duplexes with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'duplex');180-test('Can use duplexes with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'duplex');181-test('Can use duplexes with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'duplex');182-test('Can use duplexes with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'duplex');183-test('Can use webTransforms with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'webTransform');184-test('Can use webTransforms with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'webTransform');185-test('Can use webTransforms with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'webTransform');186-test('Can use webTransforms with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'webTransform');187-188-// eslint-disable-next-line max-params189-const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type, execaMethod) => {190- const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);191- const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';192- const {stdout, stderr, stdio} = await execaMethod(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generators), reject});193- const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];194- t.deepEqual(result, output);195-};196-197-test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'generator', execa);198-test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'generator', execa);199-test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'generator', execa);200-test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'generator', execa);201-test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'generator', execa);202-test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'generator', execa);203-test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'generator', execa);204-test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'generator', execa);205-test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'generator', execa);206-test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'generator', execa);207-test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'generator', execa);208-test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'generator', execa);209-test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'generator', execa);210-test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'generator', execa);211-test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'generator', execa);212-test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'generator', execa);213-test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'generator', execa);214-test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'generator', execa);215-test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'generator', execa);216-test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'generator', execa);217-test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'generator', execa);218-test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'generator', execa);219-test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'generator', execa);220-test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'generator', execa);221-test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'generator', execa);222-test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'generator', execa);223-test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'generator', execa);224-test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'generator', execa);225-test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'generator', execa);226-test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'generator', execa);227-test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'generator', execa);228-test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'generator', execa);229-test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'generator', execa);230-test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'generator', execa);231-test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'generator', execa);232-test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'generator', execa);233-test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'generator', execa);234-test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'generator', execa);235-test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'generator', execa);236-test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'generator', execa);237-test('Can use generators with result.stdio[1], sync', testGeneratorOutput, 1, true, false, false, false, 'generator', execaSync);238-test('Can use generators with result.stdout, sync', testGeneratorOutput, 1, true, true, false, false, 'generator', execaSync);239-test('Can use generators with result.stdio[2], sync', testGeneratorOutput, 2, true, false, false, false, 'generator', execaSync);240-test('Can use generators with result.stderr, sync', testGeneratorOutput, 2, true, true, false, false, 'generator', execaSync);241-test('Can use generators with result.stdio[*] as output, sync', testGeneratorOutput, 3, true, false, false, false, 'generator', execaSync);242-test('Can use generators with error.stdio[1], sync', testGeneratorOutput, 1, false, false, false, false, 'generator', execaSync);243-test('Can use generators with error.stdout, sync', testGeneratorOutput, 1, false, true, false, false, 'generator', execaSync);244-test('Can use generators with error.stdio[2], sync', testGeneratorOutput, 2, false, false, false, false, 'generator', execaSync);245-test('Can use generators with error.stderr, sync', testGeneratorOutput, 2, false, true, false, false, 'generator', execaSync);246-test('Can use generators with error.stdio[*] as output, sync', testGeneratorOutput, 3, false, false, false, false, 'generator', execaSync);247-test('Can use generators with result.stdio[1], objectMode, sync', testGeneratorOutput, 1, true, false, true, false, 'generator', execaSync);248-test('Can use generators with result.stdout, objectMode, sync', testGeneratorOutput, 1, true, true, true, false, 'generator', execaSync);249-test('Can use generators with result.stdio[2], objectMode, sync', testGeneratorOutput, 2, true, false, true, false, 'generator', execaSync);250-test('Can use generators with result.stderr, objectMode, sync', testGeneratorOutput, 2, true, true, true, false, 'generator', execaSync);251-test('Can use generators with result.stdio[*] as output, objectMode, sync', testGeneratorOutput, 3, true, false, true, false, 'generator', execaSync);252-test('Can use generators with error.stdio[1], objectMode, sync', testGeneratorOutput, 1, false, false, true, false, 'generator', execaSync);253-test('Can use generators with error.stdout, objectMode, sync', testGeneratorOutput, 1, false, true, true, false, 'generator', execaSync);254-test('Can use generators with error.stdio[2], objectMode, sync', testGeneratorOutput, 2, false, false, true, false, 'generator', execaSync);255-test('Can use generators with error.stderr, objectMode, sync', testGeneratorOutput, 2, false, true, true, false, 'generator', execaSync);256-test('Can use generators with error.stdio[*] as output, objectMode, sync', testGeneratorOutput, 3, false, false, true, false, 'generator', execaSync);257-test('Can use generators with result.stdio[1], noop transform, sync', testGeneratorOutput, 1, true, false, false, true, 'generator', execaSync);258-test('Can use generators with result.stdout, noop transform, sync', testGeneratorOutput, 1, true, true, false, true, 'generator', execaSync);259-test('Can use generators with result.stdio[2], noop transform, sync', testGeneratorOutput, 2, true, false, false, true, 'generator', execaSync);260-test('Can use generators with result.stderr, noop transform, sync', testGeneratorOutput, 2, true, true, false, true, 'generator', execaSync);261-test('Can use generators with result.stdio[*] as output, noop transform, sync', testGeneratorOutput, 3, true, false, false, true, 'generator', execaSync);262-test('Can use generators with error.stdio[1], noop transform, sync', testGeneratorOutput, 1, false, false, false, true, 'generator', execaSync);263-test('Can use generators with error.stdout, noop transform, sync', testGeneratorOutput, 1, false, true, false, true, 'generator', execaSync);264-test('Can use generators with error.stdio[2], noop transform, sync', testGeneratorOutput, 2, false, false, false, true, 'generator', execaSync);265-test('Can use generators with error.stderr, noop transform, sync', testGeneratorOutput, 2, false, true, false, true, 'generator', execaSync);266-test('Can use generators with error.stdio[*] as output, noop transform, sync', testGeneratorOutput, 3, false, false, false, true, 'generator', execaSync);267-test('Can use generators with result.stdio[1], objectMode, noop transform, sync', testGeneratorOutput, 1, true, false, true, true, 'generator', execaSync);268-test('Can use generators with result.stdout, objectMode, noop transform, sync', testGeneratorOutput, 1, true, true, true, true, 'generator', execaSync);269-test('Can use generators with result.stdio[2], objectMode, noop transform, sync', testGeneratorOutput, 2, true, false, true, true, 'generator', execaSync);270-test('Can use generators with result.stderr, objectMode, noop transform, sync', testGeneratorOutput, 2, true, true, true, true, 'generator', execaSync);271-test('Can use generators with result.stdio[*] as output, objectMode, noop transform, sync', testGeneratorOutput, 3, true, false, true, true, 'generator', execaSync);272-test('Can use generators with error.stdio[1], objectMode, noop transform, sync', testGeneratorOutput, 1, false, false, true, true, 'generator', execaSync);273-test('Can use generators with error.stdout, objectMode, noop transform, sync', testGeneratorOutput, 1, false, true, true, true, 'generator', execaSync);274-test('Can use generators with error.stdio[2], objectMode, noop transform, sync', testGeneratorOutput, 2, false, false, true, true, 'generator', execaSync);275-test('Can use generators with error.stderr, objectMode, noop transform, sync', testGeneratorOutput, 2, false, true, true, true, 'generator', execaSync);276-test('Can use generators with error.stdio[*] as output, objectMode, noop transform, sync', testGeneratorOutput, 3, false, false, true, true, 'generator', execaSync);277-test('Can use duplexes with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'duplex', execa);278-test('Can use duplexes with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'duplex', execa);279-test('Can use duplexes with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'duplex', execa);280-test('Can use duplexes with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'duplex', execa);281-test('Can use duplexes with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'duplex', execa);282-test('Can use duplexes with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'duplex', execa);283-test('Can use duplexes with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'duplex', execa);284-test('Can use duplexes with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'duplex', execa);285-test('Can use duplexes with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'duplex', execa);286-test('Can use duplexes with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'duplex', execa);287-test('Can use duplexes with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'duplex', execa);288-test('Can use duplexes with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'duplex', execa);289-test('Can use duplexes with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'duplex', execa);290-test('Can use duplexes with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'duplex', execa);291-test('Can use duplexes with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'duplex', execa);292-test('Can use duplexes with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'duplex', execa);293-test('Can use duplexes with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'duplex', execa);294-test('Can use duplexes with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'duplex', execa);295-test('Can use duplexes with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'duplex', execa);296-test('Can use duplexes with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'duplex', execa);297-test('Can use duplexes with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'duplex', execa);298-test('Can use duplexes with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'duplex', execa);299-test('Can use duplexes with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'duplex', execa);300-test('Can use duplexes with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'duplex', execa);301-test('Can use duplexes with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'duplex', execa);302-test('Can use duplexes with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'duplex', execa);303-test('Can use duplexes with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'duplex', execa);304-test('Can use duplexes with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'duplex', execa);305-test('Can use duplexes with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'duplex', execa);306-test('Can use duplexes with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'duplex', execa);307-test('Can use duplexes with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'duplex', execa);308-test('Can use duplexes with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'duplex', execa);309-test('Can use duplexes with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'duplex', execa);310-test('Can use duplexes with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'duplex', execa);311-test('Can use duplexes with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'duplex', execa);312-test('Can use duplexes with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'duplex', execa);313-test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex', execa);314-test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex', execa);315-test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex', execa);316-test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex', execa);317-test('Can use webTransforms with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'webTransform', execa);318-test('Can use webTransforms with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'webTransform', execa);319-test('Can use webTransforms with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'webTransform', execa);320-test('Can use webTransforms with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'webTransform', execa);321-test('Can use webTransforms with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'webTransform', execa);322-test('Can use webTransforms with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'webTransform', execa);323-test('Can use webTransforms with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'webTransform', execa);324-test('Can use webTransforms with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'webTransform', execa);325-test('Can use webTransforms with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'webTransform', execa);326-test('Can use webTransforms with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'webTransform', execa);327-test('Can use webTransforms with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'webTransform', execa);328-test('Can use webTransforms with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'webTransform', execa);329-test('Can use webTransforms with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'webTransform', execa);330-test('Can use webTransforms with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'webTransform', execa);331-test('Can use webTransforms with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'webTransform', execa);332-test('Can use webTransforms with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'webTransform', execa);333-test('Can use webTransforms with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'webTransform', execa);334-test('Can use webTransforms with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'webTransform', execa);335-test('Can use webTransforms with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'webTransform', execa);336-test('Can use webTransforms with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'webTransform', execa);337-test('Can use webTransforms with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'webTransform', execa);338-test('Can use webTransforms with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'webTransform', execa);339-test('Can use webTransforms with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'webTransform', execa);340-test('Can use webTransforms with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'webTransform', execa);341-test('Can use webTransforms with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'webTransform', execa);342-test('Can use webTransforms with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'webTransform', execa);343-test('Can use webTransforms with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'webTransform', execa);344-test('Can use webTransforms with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'webTransform', execa);345-test('Can use webTransforms with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'webTransform', execa);346-test('Can use webTransforms with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'webTransform', execa);347-test('Can use webTransforms with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'webTransform', execa);348-test('Can use webTransforms with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'webTransform', execa);349-test('Can use webTransforms with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'webTransform', execa);350-test('Can use webTransforms with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'webTransform', execa);351-test('Can use webTransforms with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'webTransform', execa);352-test('Can use webTransforms with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'webTransform', execa);353-test('Can use webTransforms with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'webTransform', execa);354-test('Can use webTransforms with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'webTransform', execa);355-test('Can use webTransforms with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'webTransform', execa);356-test('Can use webTransforms with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'webTransform', execa);357-358-// eslint-disable-next-line max-params359-const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {360- const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);361- const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, generators));362- const stream = useShortcutProperty ? [subprocess.stdout, subprocess.stderr][fdNumber - 1] : subprocess.stdio[fdNumber];363- const [result] = await Promise.all([getStreamMethod(stream), subprocess]);364- t.deepEqual(result, output);365-};366-367-test('Can use generators with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'generator');368-test('Can use generators with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'generator');369-test('Can use generators with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'generator');370-test('Can use generators with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'generator');371-test('Can use generators with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'generator');372-test('Can use generators with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'generator');373-test('Can use generators with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'generator');374-test('Can use generators with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'generator');375-test('Can use generators with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'generator');376-test('Can use generators with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'generator');377-test('Can use generators with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'generator');378-test('Can use generators with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'generator');379-test('Can use generators with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'generator');380-test('Can use generators with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'generator');381-test('Can use generators with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'generator');382-test('Can use generators with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'generator');383-test('Can use generators with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'generator');384-test('Can use generators with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'generator');385-test('Can use generators with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'generator');386-test('Can use generators with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'generator');387-test('Can use duplexes with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'duplex');388-test('Can use duplexes with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'duplex');389-test('Can use duplexes with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'duplex');390-test('Can use duplexes with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'duplex');391-test('Can use duplexes with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'duplex');392-test('Can use duplexes with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'duplex');393-test('Can use duplexes with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'duplex');394-test('Can use duplexes with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'duplex');395-test('Can use duplexes with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'duplex');396-test('Can use duplexes with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'duplex');397-test('Can use duplexes with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'duplex');398-test('Can use duplexes with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'duplex');399-test('Can use duplexes with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'duplex');400-test('Can use duplexes with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'duplex');401-test('Can use duplexes with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'duplex');402-test('Can use duplexes with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'duplex');403-test('Can use duplexes with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'duplex');404-test('Can use duplexes with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'duplex');405-test('Can use duplexes with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'duplex');406-test('Can use duplexes with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'duplex');407-test('Can use webTransforms with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'webTransform');408-test('Can use webTransforms with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'webTransform');409-test('Can use webTransforms with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'webTransform');410-test('Can use webTransforms with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'webTransform');411-test('Can use webTransforms with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'webTransform');412-test('Can use webTransforms with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'webTransform');413-test('Can use webTransforms with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'webTransform');414-test('Can use webTransforms with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'webTransform');415-test('Can use webTransforms with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'webTransform');416-test('Can use webTransforms with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'webTransform');417-test('Can use webTransforms with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'webTransform');418-test('Can use webTransforms with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'webTransform');419-test('Can use webTransforms with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'webTransform');420-test('Can use webTransforms with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'webTransform');421-test('Can use webTransforms with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'webTransform');422-test('Can use webTransforms with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'webTransform');423-test('Can use webTransforms with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'webTransform');424-test('Can use webTransforms with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'webTransform');425-test('Can use webTransforms with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'webTransform');426-test('Can use webTransforms with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'webTransform');427-428-const getAllStdioOption = (stdioOption, encoding, objectMode) => {429- if (stdioOption) {430- return 'pipe';431- }432-433- if (objectMode) {434- return outputObjectGenerator();435- }436-437- return encoding === 'utf8' ? uppercaseGenerator() : uppercaseBufferGenerator();438-};439-440-const getStdoutStderrOutput = ({output, stdioOption, encoding, objectMode, lines}) => {441- if (objectMode && !stdioOption) {442- return encoding === 'utf8' ? [foobarObject, foobarObject] : [foobarObject];443- }444-445- const stdioOutput = stdioOption ? output : output.toUpperCase();446-447- if (encoding === 'hex') {448- return Buffer.from(stdioOutput).toString('hex');449- }450-451- if (encoding === 'buffer') {452- return textEncoder.encode(stdioOutput);453- }454-455- return lines ? stdioOutput.trim().split('\n').map(string => `${string}\n`) : stdioOutput;456-};457-458-const getAllOutput = ({stdoutOutput, stderrOutput, encoding, objectMode, lines}) => {459- if (objectMode || (lines && encoding === 'utf8')) {460- return [stdoutOutput, stderrOutput].flat();461- }462-463- return encoding === 'buffer'464- ? new Uint8Array([...stdoutOutput, ...stderrOutput])465- : `${stdoutOutput}${stderrOutput}`;466-};467-468-// eslint-disable-next-line max-params469-const testGeneratorAll = async (t, reject, encoding, objectMode, stdoutOption, stderrOption, lines, execaMethod) => {470- const fixtureName = reject ? 'all.js' : 'all-fail.js';471- const {stdout, stderr, all} = await execaMethod(fixtureName, {472- all: true,473- reject,474- stdout: getAllStdioOption(stdoutOption, encoding, objectMode),475- stderr: getAllStdioOption(stderrOption, encoding, objectMode),476- encoding,477- lines,478- stripFinalNewline: false,479- });480-481- const stdoutOutput = getStdoutStderrOutput({output: 'std\nout\n', stdioOption: stdoutOption, encoding, objectMode, lines});482- t.deepEqual(stdout, stdoutOutput);483- const stderrOutput = getStdoutStderrOutput({output: 'std\nerr\n', stdioOption: stderrOption, encoding, objectMode, lines});484- t.deepEqual(stderr, stderrOutput);485- const allOutput = getAllOutput({stdoutOutput, stderrOutput, encoding, objectMode, lines});486- if (Array.isArray(all) && Array.isArray(allOutput)) {487- t.deepEqual([...all].sort(), [...allOutput].sort());488- } else {489- t.deepEqual(all, allOutput);490- }491-};492-493-test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false, false, execa);494-test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false, false, execa);495-test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false, false, execa);496-test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false, false, execa);497-test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false, false, execa);498-test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false, false, execa);499-test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true, false, execa);500-test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true, false, execa);501-test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true, false, execa);502-test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true, false, execa);503-test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true, false, execa);504-test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true, false, execa);505-test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false, false, execa);506-test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false, false, execa);507-test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false, false, execa);508-test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false, false, execa);509-test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false, false, execa);510-test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false, false, execa);511-test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false, false, execa);512-test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false, false, execa);513-test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false, false, execa);514-test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false, false, execa);515-test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false, false, execa);516-test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false, false, execa);517-test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true, false, execa);518-test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true, false, execa);519-test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true, false, execa);520-test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true, false, execa);521-test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true, false, execa);522-test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true, false, execa);523-test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false, false, execa);524-test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false, false, execa);525-test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false, false, execa);526-test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false, false, execa);527-test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false, false, execa);528-test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false, false, execa);529-test('Can use generators with result.all = transform + transform, sync', testGeneratorAll, true, 'utf8', false, false, false, false, execaSync);530-test('Can use generators with error.all = transform + transform, sync', testGeneratorAll, false, 'utf8', false, false, false, false, execaSync);531-test('Can use generators with result.all = transform + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, false, false, execaSync);532-test('Can use generators with error.all = transform + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, false, false, execaSync);533-test('Can use generators with result.all = transform + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, false, false, execaSync);534-test('Can use generators with error.all = transform + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, false, false, execaSync);535-test('Can use generators with result.all = transform + pipe, sync', testGeneratorAll, true, 'utf8', false, false, true, false, execaSync);536-test('Can use generators with error.all = transform + pipe, sync', testGeneratorAll, false, 'utf8', false, false, true, false, execaSync);537-test('Can use generators with result.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, true, false, execaSync);538-test('Can use generators with error.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, true, false, execaSync);539-test('Can use generators with result.all = transform + pipe, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, true, false, execaSync);540-test('Can use generators with error.all = transform + pipe, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, true, false, execaSync);541-test('Can use generators with result.all = pipe + transform, sync', testGeneratorAll, true, 'utf8', false, true, false, false, execaSync);542-test('Can use generators with error.all = pipe + transform, sync', testGeneratorAll, false, 'utf8', false, true, false, false, execaSync);543-test('Can use generators with result.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, true, false, false, execaSync);544-test('Can use generators with error.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, true, false, false, execaSync);545-test('Can use generators with result.all = pipe + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, true, false, false, execaSync);546-test('Can use generators with error.all = pipe + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, true, false, false, execaSync);547-test('Can use generators with result.all = transform + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, false, false, execaSync);548-test('Can use generators with error.all = transform + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, false, false, execaSync);549-test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, false, false, execaSync);550-test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, false, false, execaSync);551-test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, false, false, execaSync);552-test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, false, false, execaSync);553-test('Can use generators with result.all = transform + pipe, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, true, false, execaSync);554-test('Can use generators with error.all = transform + pipe, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, true, false, execaSync);555-test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, true, false, execaSync);556-test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, true, false, execaSync);557-test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, true, false, execaSync);558-test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, true, false, execaSync);559-test('Can use generators with result.all = pipe + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, true, false, false, execaSync);560-test('Can use generators with error.all = pipe + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, true, false, false, execaSync);561-test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, true, false, false, execaSync);562-test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, true, false, false, execaSync);563-test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, true, false, false, execaSync);564-test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, true, false, false, execaSync);565-test('Can use generators with result.all = transform + transform, lines', testGeneratorAll, true, 'utf8', false, false, false, true, execa);566-test('Can use generators with error.all = transform + transform, lines', testGeneratorAll, false, 'utf8', false, false, false, true, execa);567-test('Can use generators with result.all = transform + transform, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, false, false, true, execa);568-test('Can use generators with error.all = transform + transform, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, false, false, true, execa);569-test('Can use generators with result.all = transform + transform, encoding "hex", lines', testGeneratorAll, true, 'hex', false, false, false, true, execa);570-test('Can use generators with error.all = transform + transform, encoding "hex", lines', testGeneratorAll, false, 'hex', false, false, false, true, execa);571-test('Can use generators with result.all = transform + pipe, lines', testGeneratorAll, true, 'utf8', false, false, true, true, execa);572-test('Can use generators with error.all = transform + pipe, lines', testGeneratorAll, false, 'utf8', false, false, true, true, execa);573-test('Can use generators with result.all = transform + pipe, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, false, true, true, execa);574-test('Can use generators with error.all = transform + pipe, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, false, true, true, execa);575-test('Can use generators with result.all = transform + pipe, encoding "hex", lines', testGeneratorAll, true, 'hex', false, false, true, true, execa);576-test('Can use generators with error.all = transform + pipe, encoding "hex", lines', testGeneratorAll, false, 'hex', false, false, true, true, execa);577-test('Can use generators with result.all = pipe + transform, lines', testGeneratorAll, true, 'utf8', false, true, false, true, execa);578-test('Can use generators with error.all = pipe + transform, lines', testGeneratorAll, false, 'utf8', false, true, false, true, execa);579-test('Can use generators with result.all = pipe + transform, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, true, false, true, execa);580-test('Can use generators with error.all = pipe + transform, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, true, false, true, execa);581-test('Can use generators with result.all = pipe + transform, encoding "hex", lines', testGeneratorAll, true, 'hex', false, true, false, true, execa);582-test('Can use generators with error.all = pipe + transform, encoding "hex", lines', testGeneratorAll, false, 'hex', false, true, false, true, execa);583-test('Can use generators with result.all = transform + transform, objectMode, lines', testGeneratorAll, true, 'utf8', true, false, false, true, execa);584-test('Can use generators with error.all = transform + transform, objectMode, lines', testGeneratorAll, false, 'utf8', true, false, false, true, execa);585-test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, false, false, true, execa);586-test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, false, false, true, execa);587-test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, false, false, true, execa);588-test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, false, false, true, execa);589-test('Can use generators with result.all = transform + pipe, objectMode, lines', testGeneratorAll, true, 'utf8', true, false, true, true, execa);590-test('Can use generators with error.all = transform + pipe, objectMode, lines', testGeneratorAll, false, 'utf8', true, false, true, true, execa);591-test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, false, true, true, execa);592-test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, false, true, true, execa);593-test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, false, true, true, execa);594-test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, false, true, true, execa);595-test('Can use generators with result.all = pipe + transform, objectMode, lines', testGeneratorAll, true, 'utf8', true, true, false, true, execa);596-test('Can use generators with error.all = pipe + transform, objectMode, lines', testGeneratorAll, false, 'utf8', true, true, false, true, execa);597-test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, true, false, true, execa);598-test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, true, false, true, execa);599-test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, true, false, true, execa);600-test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, true, false, true, execa);601-test('Can use generators with result.all = transform + transform, sync, lines', testGeneratorAll, true, 'utf8', false, false, false, true, execaSync);602-test('Can use generators with error.all = transform + transform, sync, lines', testGeneratorAll, false, 'utf8', false, false, false, true, execaSync);603-test('Can use generators with result.all = transform + transform, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, false, false, true, execaSync);604-test('Can use generators with error.all = transform + transform, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, false, false, true, execaSync);605-test('Can use generators with result.all = transform + transform, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, false, false, true, execaSync);606-test('Can use generators with error.all = transform + transform, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, false, false, true, execaSync);607-test('Can use generators with result.all = transform + pipe, sync, lines', testGeneratorAll, true, 'utf8', false, false, true, true, execaSync);608-test('Can use generators with error.all = transform + pipe, sync, lines', testGeneratorAll, false, 'utf8', false, false, true, true, execaSync);609-test('Can use generators with result.all = transform + pipe, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, false, true, true, execaSync);610-test('Can use generators with error.all = transform + pipe, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, false, true, true, execaSync);611-test('Can use generators with result.all = transform + pipe, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, false, true, true, execaSync);612-test('Can use generators with error.all = transform + pipe, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, false, true, true, execaSync);613-test('Can use generators with result.all = pipe + transform, sync, lines', testGeneratorAll, true, 'utf8', false, true, false, true, execaSync);614-test('Can use generators with error.all = pipe + transform, sync, lines', testGeneratorAll, false, 'utf8', false, true, false, true, execaSync);615-test('Can use generators with result.all = pipe + transform, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, true, false, true, execaSync);616-test('Can use generators with error.all = pipe + transform, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, true, false, true, execaSync);617-test('Can use generators with result.all = pipe + transform, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, true, false, true, execaSync);618-test('Can use generators with error.all = pipe + transform, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, true, false, true, execaSync);619-test('Can use generators with result.all = transform + transform, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, false, false, true, execaSync);620-test('Can use generators with error.all = transform + transform, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, false, false, true, execaSync);621-test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, false, false, true, execaSync);622-test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, false, false, true, execaSync);623-test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, false, false, true, execaSync);624-test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, false, false, true, execaSync);625-test('Can use generators with result.all = transform + pipe, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, false, true, true, execaSync);626-test('Can use generators with error.all = transform + pipe, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, false, true, true, execaSync);627-test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, false, true, true, execaSync);628-test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, false, true, true, execaSync);629-test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, false, true, true, execaSync);630-test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, false, true, true, execaSync);631-test('Can use generators with result.all = pipe + transform, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, true, false, true, execaSync);632-test('Can use generators with error.all = pipe + transform, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, true, false, true, execaSync);633-test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, true, false, true, execaSync);634-test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, true, false, true, execaSync);635-test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, true, false, true, execaSync);636-test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, true, false, true, execaSync);637-638-const testInputOption = async (t, type, execaMethod) => {639- const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});640- t.is(stdout, foobarUppercase);641-};642-643-test('Can use generators with input option', testInputOption, 'generator', execa);644-test('Can use generators with input option, sync', testInputOption, 'generator', execaSync);645-test('Can use duplexes with input option', testInputOption, 'duplex', execa);646-test('Can use webTransforms with input option', testInputOption, 'webTransform', execa);647-648-// eslint-disable-next-line max-params649-const testInputFile = async (t, stdinOption, useInputFile, reversed, execaMethod) => {650- const filePath = tempfile();651- await writeFile(filePath, foobarString);652- const options = useInputFile653- ? {inputFile: filePath, stdin: stdinOption}654- : {stdin: [{file: filePath}, stdinOption]};655- options.stdin = reversed ? options.stdin.reverse() : options.stdin;656- const {stdout} = await execaMethod('stdin-fd.js', ['0'], options);657- t.is(stdout, foobarUppercase);658- await rm(filePath);659-};660-661-test('Can use generators with a file as input', testInputFile, uppercaseGenerator(), false, false, execa);662-test('Can use generators with a file as input, reversed', testInputFile, uppercaseGenerator(), false, true, execa);663-test('Can use generators with inputFile option', testInputFile, uppercaseGenerator(), true, false, execa);664-test('Can use generators with a file as input, sync', testInputFile, uppercaseGenerator(), false, false, execaSync);665-test('Can use generators with a file as input, reversed, sync', testInputFile, uppercaseGenerator(), false, true, execaSync);666-test('Can use generators with inputFile option, sync', testInputFile, uppercaseGenerator(), true, false, execaSync);667-test('Can use duplexes with a file as input', testInputFile, uppercaseBufferDuplex(), false, false, execa);668-test('Can use duplexes with a file as input, reversed', testInputFile, uppercaseBufferDuplex(), false, true, execa);669-test('Can use duplexes with inputFile option', testInputFile, uppercaseBufferDuplex(), true, false, execa);670-test('Can use webTransforms with a file as input', testInputFile, uppercaseBufferWebTransform(), false, false, execa);671-test('Can use webTransforms with a file as input, reversed', testInputFile, uppercaseBufferWebTransform(), false, true, execa);672-test('Can use webTransforms with inputFile option', testInputFile, uppercaseBufferWebTransform(), true, false, execa);673-674-const testOutputFile = async (t, reversed, type, execaMethod) => {675- const filePath = tempfile();676- const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];677- const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;678- const {stdout} = await execaMethod('noop-fd.js', ['1'], {stdout: reversedStdoutOption});679- t.is(stdout, foobarUppercase);680- t.is(await readFile(filePath, 'utf8'), foobarUppercase);681- await rm(filePath);682-};683-684-test('Can use generators with a file as output', testOutputFile, false, 'generator', execa);685-test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator', execa);686-test('Can use generators with a file as output, sync', testOutputFile, false, 'generator', execaSync);687-test('Can use generators with a file as output, reversed, sync', testOutputFile, true, 'generator', execaSync);688-test('Can use duplexes with a file as output', testOutputFile, false, 'duplex', execa);689-test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex', execa);690-test('Can use webTransforms with a file as output', testOutputFile, false, 'webTransform', execa);691-test('Can use webTransforms with a file as output, reversed', testOutputFile, true, 'webTransform', execa);692-693-const testWritableDestination = async (t, type) => {694- const passThrough = new PassThrough();695- const [{stdout}, streamOutput] = await Promise.all([696- execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].uppercaseBuffer(false, true), passThrough]}),697- getStream(passThrough),698- ]);699- t.is(stdout, foobarUppercase);700- t.is(streamOutput, foobarUppercase);701-};702-703-test('Can use generators to a Writable stream', testWritableDestination, 'generator');704-test('Can use duplexes to a Writable stream', testWritableDestination, 'duplex');705-test('Can use webTransforms to a Writable stream', testWritableDestination, 'webTransform');706-707-const testReadableSource = async (t, type) => {708- const passThrough = new PassThrough();709- const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});710- passThrough.end(foobarString);711- const {stdout} = await subprocess;712- t.is(stdout, foobarUppercase);713-};714-715-test('Can use generators from a Readable stream', testReadableSource, 'generator');716-test('Can use duplexes from a Readable stream', testReadableSource, 'duplex');717-test('Can use webTransforms from a Readable stream', testReadableSource, 'webTransform');718-719-const testInherit = async (t, type) => {720- const {stdout} = await execa('nested-inherit.js', [type]);721- t.is(stdout, foobarUppercase);722-};723-724-test('Can use generators with "inherit"', testInherit, 'generator');725-test('Can use duplexes with "inherit"', testInherit, 'duplex');726-test('Can use webTransforms with "inherit"', testInherit, 'webTransform');727-728-const testAppendInput = async (t, reversed, type, execaMethod) => {729- const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];730- const reversedStdin = reversed ? stdin.reverse() : stdin;731- const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: reversedStdin});732- const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;733- t.is(stdout, `${foobarUppercase}${reversedSuffix}`);734-};735-736-test('Can use multiple generators as input', testAppendInput, false, 'generator', execa);737-test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator', execa);738-test('Can use multiple generators as input, sync', testAppendInput, false, 'generator', execaSync);739-test('Can use multiple generators as input, reversed, sync', testAppendInput, true, 'generator', execaSync);740-test('Can use multiple duplexes as input', testAppendInput, false, 'duplex', execa);741-test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex', execa);742-test('Can use multiple webTransforms as input', testAppendInput, false, 'webTransform', execa);743-test('Can use multiple webTransforms as input, reversed', testAppendInput, true, 'webTransform', execa);744-745-const testAppendOutput = async (t, reversed, type, execaMethod) => {746- const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];747- const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;748- const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: reversedStdoutOption});749- const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;750- t.is(stdout, `${foobarUppercase}${reversedSuffix}`);751-};752-753-test('Can use multiple generators as output', testAppendOutput, false, 'generator', execa);754-test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator', execa);755-test('Can use multiple generators as output, sync', testAppendOutput, false, 'generator', execaSync);756-test('Can use multiple generators as output, reversed, sync', testAppendOutput, true, 'generator', execaSync);757-test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex', execa);758-test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex', execa);759-test('Can use multiple webTransforms as output', testAppendOutput, false, 'webTransform', execa);760-test('Can use multiple webTransforms as output, reversed', testAppendOutput, true, 'webTransform', execa);761-762-// eslint-disable-next-line max-params763-const testTwoGenerators = async (t, producesTwo, execaMethod, firstGenerator, secondGenerator = firstGenerator) => {764- const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});765- const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;766- t.is(stdout, `${foobarString}${expectedSuffix}`);767-};768-769-test('Can use multiple identical generators', testTwoGenerators, true, execa, appendGenerator().transform);770-test('Can use multiple identical generators, options object', testTwoGenerators, true, execa, appendGenerator());771-test('Can use multiple identical generators, async', testTwoGenerators, true, execa, appendAsyncGenerator().transform);772-test('Can use multiple identical generators, options object, async', testTwoGenerators, true, execa, appendAsyncGenerator());773-test('Can use multiple identical generators, sync', testTwoGenerators, true, execaSync, appendGenerator().transform);774-test('Can use multiple identical generators, options object, sync', testTwoGenerators, true, execaSync, appendGenerator());775-test('Ignore duplicate identical duplexes', testTwoGenerators, false, execa, appendDuplex());776-test('Ignore duplicate identical webTransforms', testTwoGenerators, false, execa, appendWebTransform());777-test('Can use multiple generators with duplexes', testTwoGenerators, true, execa, appendGenerator(false, false, true), appendDuplex());778-test('Can use multiple generators with webTransforms', testTwoGenerators, true, execa, appendGenerator(false, false, true), appendWebTransform());779-test('Can use multiple duplexes with webTransforms', testTwoGenerators, true, execa, appendDuplex(), appendWebTransform());780-781-const testGeneratorSyntax = async (t, type, usePlainObject, execaMethod) => {782- const transform = generatorsMap[type].uppercase();783- const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: usePlainObject ? transform : transform.transform});784- t.is(stdout, foobarUppercase);785-};786-787-test('Can pass generators with an options plain object', testGeneratorSyntax, 'generator', false, execa);788-test('Can pass generators without an options plain object', testGeneratorSyntax, 'generator', true, execa);789-test('Can pass generators with an options plain object, sync', testGeneratorSyntax, 'generator', false, execaSync);790-test('Can pass generators without an options plain object, sync', testGeneratorSyntax, 'generator', true, execaSync);791-test('Can pass webTransforms with an options plain object', testGeneratorSyntax, 'webTransform', true, execa);792-test('Can pass webTransforms without an options plain object', testGeneratorSyntax, 'webTransform', false, execa);added:test/stdio/handle-invalid.js+60 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {getStdio} from '../helpers/stdio.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+6+setFixtureDir();7+8+const testEmptyArray = (t, fdNumber, optionName, execaMethod) => {9+ t.throws(() => {10+ execaMethod('empty.js', getStdio(fdNumber, []));11+ }, {message: `The \`${optionName}\` option must not be an empty array.`});12+};13+14+test('Cannot pass an empty array to stdin', testEmptyArray, 0, 'stdin', execa);15+test('Cannot pass an empty array to stdout', testEmptyArray, 1, 'stdout', execa);16+test('Cannot pass an empty array to stderr', testEmptyArray, 2, 'stderr', execa);17+test('Cannot pass an empty array to stdio[*]', testEmptyArray, 3, 'stdio[3]', execa);18+test('Cannot pass an empty array to stdin - sync', testEmptyArray, 0, 'stdin', execaSync);19+test('Cannot pass an empty array to stdout - sync', testEmptyArray, 1, 'stdout', execaSync);20+test('Cannot pass an empty array to stderr - sync', testEmptyArray, 2, 'stderr', execaSync);21+test('Cannot pass an empty array to stdio[*] - sync', testEmptyArray, 3, 'stdio[3]', execaSync);22+23+const testInvalidValueSync = (t, fdNumber, stdioOption) => {24+ const {message} = t.throws(() => {25+ execaSync('empty.js', getStdio(fdNumber, stdioOption));26+ });27+ t.true(message.includes(`cannot be "${stdioOption}" with synchronous methods`));28+};29+30+test('stdin cannot be "ipc", sync', testInvalidValueSync, 0, 'ipc');31+test('stdout cannot be "ipc", sync', testInvalidValueSync, 1, 'ipc');32+test('stderr cannot be "ipc", sync', testInvalidValueSync, 2, 'ipc');33+test('stdio[*] cannot be "ipc", sync', testInvalidValueSync, 3, 'ipc');34+test('stdin cannot be "overlapped", sync', testInvalidValueSync, 0, 'overlapped');35+test('stdout cannot be "overlapped", sync', testInvalidValueSync, 1, 'overlapped');36+test('stderr cannot be "overlapped", sync', testInvalidValueSync, 2, 'overlapped');37+test('stdio[*] cannot be "overlapped", sync', testInvalidValueSync, 3, 'overlapped');38+39+const testInvalidArrayValue = (t, invalidStdio, fdNumber, execaMethod) => {40+ t.throws(() => {41+ execaMethod('empty.js', getStdio(fdNumber, ['pipe', invalidStdio]));42+ }, {message: /must not include/});43+};44+45+test('Cannot pass "ignore" and another value to stdin', testInvalidArrayValue, 'ignore', 0, execa);46+test('Cannot pass "ignore" and another value to stdout', testInvalidArrayValue, 'ignore', 1, execa);47+test('Cannot pass "ignore" and another value to stderr', testInvalidArrayValue, 'ignore', 2, execa);48+test('Cannot pass "ignore" and another value to stdio[*]', testInvalidArrayValue, 'ignore', 3, execa);49+test('Cannot pass "ignore" and another value to stdin - sync', testInvalidArrayValue, 'ignore', 0, execaSync);50+test('Cannot pass "ignore" and another value to stdout - sync', testInvalidArrayValue, 'ignore', 1, execaSync);51+test('Cannot pass "ignore" and another value to stderr - sync', testInvalidArrayValue, 'ignore', 2, execaSync);52+test('Cannot pass "ignore" and another value to stdio[*] - sync', testInvalidArrayValue, 'ignore', 3, execaSync);53+test('Cannot pass "ipc" and another value to stdin', testInvalidArrayValue, 'ipc', 0, execa);54+test('Cannot pass "ipc" and another value to stdout', testInvalidArrayValue, 'ipc', 1, execa);55+test('Cannot pass "ipc" and another value to stderr', testInvalidArrayValue, 'ipc', 2, execa);56+test('Cannot pass "ipc" and another value to stdio[*]', testInvalidArrayValue, 'ipc', 3, execa);57+test('Cannot pass "ipc" and another value to stdin - sync', testInvalidArrayValue, 'ipc', 0, execaSync);58+test('Cannot pass "ipc" and another value to stdout - sync', testInvalidArrayValue, 'ipc', 1, execaSync);59+test('Cannot pass "ipc" and another value to stderr - sync', testInvalidArrayValue, 'ipc', 2, execaSync);60+test('Cannot pass "ipc" and another value to stdio[*] - sync', testInvalidArrayValue, 'ipc', 3, execaSync);added:test/stdio/handle-options.js+72 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {getStdio} from '../helpers/stdio.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {appendGenerator, appendAsyncGenerator, casedSuffix} from '../helpers/generator.js';6+import {appendDuplex} from '../helpers/duplex.js';7+import {appendWebTransform} from '../helpers/web-transform.js';8+import {foobarString} from '../helpers/input.js';9+10+setFixtureDir();11+12+const testNoPipeOption = async (t, stdioOption, fdNumber) => {13+ const subprocess = execa('empty.js', getStdio(fdNumber, stdioOption));14+ t.is(subprocess.stdio[fdNumber], null);15+ await subprocess;16+};17+18+test('stdin can be "ignore"', testNoPipeOption, 'ignore', 0);19+test('stdin can be ["ignore"]', testNoPipeOption, ['ignore'], 0);20+test('stdin can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 0);21+test('stdin can be "ipc"', testNoPipeOption, 'ipc', 0);22+test('stdin can be ["ipc"]', testNoPipeOption, ['ipc'], 0);23+test('stdin can be "inherit"', testNoPipeOption, 'inherit', 0);24+test('stdin can be ["inherit"]', testNoPipeOption, ['inherit'], 0);25+test('stdin can be 0', testNoPipeOption, 0, 0);26+test('stdin can be [0]', testNoPipeOption, [0], 0);27+test('stdout can be "ignore"', testNoPipeOption, 'ignore', 1);28+test('stdout can be ["ignore"]', testNoPipeOption, ['ignore'], 1);29+test('stdout can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 1);30+test('stdout can be "ipc"', testNoPipeOption, 'ipc', 1);31+test('stdout can be ["ipc"]', testNoPipeOption, ['ipc'], 1);32+test('stdout can be "inherit"', testNoPipeOption, 'inherit', 1);33+test('stdout can be ["inherit"]', testNoPipeOption, ['inherit'], 1);34+test('stdout can be 1', testNoPipeOption, 1, 1);35+test('stdout can be [1]', testNoPipeOption, [1], 1);36+test('stderr can be "ignore"', testNoPipeOption, 'ignore', 2);37+test('stderr can be ["ignore"]', testNoPipeOption, ['ignore'], 2);38+test('stderr can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 2);39+test('stderr can be "ipc"', testNoPipeOption, 'ipc', 2);40+test('stderr can be ["ipc"]', testNoPipeOption, ['ipc'], 2);41+test('stderr can be "inherit"', testNoPipeOption, 'inherit', 2);42+test('stderr can be ["inherit"]', testNoPipeOption, ['inherit'], 2);43+test('stderr can be 2', testNoPipeOption, 2, 2);44+test('stderr can be [2]', testNoPipeOption, [2], 2);45+test('stdio[*] can be "ignore"', testNoPipeOption, 'ignore', 3);46+test('stdio[*] can be ["ignore"]', testNoPipeOption, ['ignore'], 3);47+test('stdio[*] can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 3);48+test('stdio[*] can be "ipc"', testNoPipeOption, 'ipc', 3);49+test('stdio[*] can be ["ipc"]', testNoPipeOption, ['ipc'], 3);50+test('stdio[*] can be "inherit"', testNoPipeOption, 'inherit', 3);51+test('stdio[*] can be ["inherit"]', testNoPipeOption, ['inherit'], 3);52+test('stdio[*] can be 3', testNoPipeOption, 3, 3);53+test('stdio[*] can be [3]', testNoPipeOption, [3], 3);54+55+// eslint-disable-next-line max-params56+const testTwoGenerators = async (t, producesTwo, execaMethod, firstGenerator, secondGenerator = firstGenerator) => {57+ const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});58+ const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;59+ t.is(stdout, `${foobarString}${expectedSuffix}`);60+};61+62+test('Can use multiple identical generators', testTwoGenerators, true, execa, appendGenerator().transform);63+test('Can use multiple identical generators, options object', testTwoGenerators, true, execa, appendGenerator());64+test('Can use multiple identical generators, async', testTwoGenerators, true, execa, appendAsyncGenerator().transform);65+test('Can use multiple identical generators, options object, async', testTwoGenerators, true, execa, appendAsyncGenerator());66+test('Can use multiple identical generators, sync', testTwoGenerators, true, execaSync, appendGenerator().transform);67+test('Can use multiple identical generators, options object, sync', testTwoGenerators, true, execaSync, appendGenerator());68+test('Ignore duplicate identical duplexes', testTwoGenerators, false, execa, appendDuplex());69+test('Ignore duplicate identical webTransforms', testTwoGenerators, false, execa, appendWebTransform());70+test('Can use multiple generators with duplexes', testTwoGenerators, true, execa, appendGenerator(false, false, true), appendDuplex());71+test('Can use multiple generators with webTransforms', testTwoGenerators, true, execa, appendGenerator(false, false, true), appendWebTransform());72+test('Can use multiple duplexes with webTransforms', testTwoGenerators, true, execa, appendDuplex(), appendWebTransform());deleted:test/stdio/handle.js-103 removed
1-import test from 'ava';2-import {execa, execaSync} from '../../index.js';3-import {getStdio} from '../helpers/stdio.js';4-import {setFixtureDir} from '../helpers/fixtures-dir.js';5-6-setFixtureDir();7-8-const testEmptyArray = (t, fdNumber, optionName, execaMethod) => {9- t.throws(() => {10- execaMethod('empty.js', getStdio(fdNumber, []));11- }, {message: `The \`${optionName}\` option must not be an empty array.`});12-};13-14-test('Cannot pass an empty array to stdin', testEmptyArray, 0, 'stdin', execa);15-test('Cannot pass an empty array to stdout', testEmptyArray, 1, 'stdout', execa);16-test('Cannot pass an empty array to stderr', testEmptyArray, 2, 'stderr', execa);17-test('Cannot pass an empty array to stdio[*]', testEmptyArray, 3, 'stdio[3]', execa);18-test('Cannot pass an empty array to stdin - sync', testEmptyArray, 0, 'stdin', execaSync);19-test('Cannot pass an empty array to stdout - sync', testEmptyArray, 1, 'stdout', execaSync);20-test('Cannot pass an empty array to stderr - sync', testEmptyArray, 2, 'stderr', execaSync);21-test('Cannot pass an empty array to stdio[*] - sync', testEmptyArray, 3, 'stdio[3]', execaSync);22-23-const testNoPipeOption = async (t, stdioOption, fdNumber) => {24- const subprocess = execa('empty.js', getStdio(fdNumber, stdioOption));25- t.is(subprocess.stdio[fdNumber], null);26- await subprocess;27-};28-29-test('stdin can be "ignore"', testNoPipeOption, 'ignore', 0);30-test('stdin can be ["ignore"]', testNoPipeOption, ['ignore'], 0);31-test('stdin can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 0);32-test('stdin can be "ipc"', testNoPipeOption, 'ipc', 0);33-test('stdin can be ["ipc"]', testNoPipeOption, ['ipc'], 0);34-test('stdin can be "inherit"', testNoPipeOption, 'inherit', 0);35-test('stdin can be ["inherit"]', testNoPipeOption, ['inherit'], 0);36-test('stdin can be 0', testNoPipeOption, 0, 0);37-test('stdin can be [0]', testNoPipeOption, [0], 0);38-test('stdout can be "ignore"', testNoPipeOption, 'ignore', 1);39-test('stdout can be ["ignore"]', testNoPipeOption, ['ignore'], 1);40-test('stdout can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 1);41-test('stdout can be "ipc"', testNoPipeOption, 'ipc', 1);42-test('stdout can be ["ipc"]', testNoPipeOption, ['ipc'], 1);43-test('stdout can be "inherit"', testNoPipeOption, 'inherit', 1);44-test('stdout can be ["inherit"]', testNoPipeOption, ['inherit'], 1);45-test('stdout can be 1', testNoPipeOption, 1, 1);46-test('stdout can be [1]', testNoPipeOption, [1], 1);47-test('stderr can be "ignore"', testNoPipeOption, 'ignore', 2);48-test('stderr can be ["ignore"]', testNoPipeOption, ['ignore'], 2);49-test('stderr can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 2);50-test('stderr can be "ipc"', testNoPipeOption, 'ipc', 2);51-test('stderr can be ["ipc"]', testNoPipeOption, ['ipc'], 2);52-test('stderr can be "inherit"', testNoPipeOption, 'inherit', 2);53-test('stderr can be ["inherit"]', testNoPipeOption, ['inherit'], 2);54-test('stderr can be 2', testNoPipeOption, 2, 2);55-test('stderr can be [2]', testNoPipeOption, [2], 2);56-test('stdio[*] can be "ignore"', testNoPipeOption, 'ignore', 3);57-test('stdio[*] can be ["ignore"]', testNoPipeOption, ['ignore'], 3);58-test('stdio[*] can be ["ignore", "ignore"]', testNoPipeOption, ['ignore', 'ignore'], 3);59-test('stdio[*] can be "ipc"', testNoPipeOption, 'ipc', 3);60-test('stdio[*] can be ["ipc"]', testNoPipeOption, ['ipc'], 3);61-test('stdio[*] can be "inherit"', testNoPipeOption, 'inherit', 3);62-test('stdio[*] can be ["inherit"]', testNoPipeOption, ['inherit'], 3);63-test('stdio[*] can be 3', testNoPipeOption, 3, 3);64-test('stdio[*] can be [3]', testNoPipeOption, [3], 3);65-66-const testInvalidValueSync = (t, fdNumber, stdioOption) => {67- const {message} = t.throws(() => {68- execaSync('empty.js', getStdio(fdNumber, stdioOption));69- });70- t.true(message.includes(`cannot be "${stdioOption}" with synchronous methods`));71-};72-73-test('stdin cannot be "ipc", sync', testInvalidValueSync, 0, 'ipc');74-test('stdout cannot be "ipc", sync', testInvalidValueSync, 1, 'ipc');75-test('stderr cannot be "ipc", sync', testInvalidValueSync, 2, 'ipc');76-test('stdio[*] cannot be "ipc", sync', testInvalidValueSync, 3, 'ipc');77-test('stdin cannot be "overlapped", sync', testInvalidValueSync, 0, 'overlapped');78-test('stdout cannot be "overlapped", sync', testInvalidValueSync, 1, 'overlapped');79-test('stderr cannot be "overlapped", sync', testInvalidValueSync, 2, 'overlapped');80-test('stdio[*] cannot be "overlapped", sync', testInvalidValueSync, 3, 'overlapped');81-82-const testInvalidArrayValue = (t, invalidStdio, fdNumber, execaMethod) => {83- t.throws(() => {84- execaMethod('empty.js', getStdio(fdNumber, ['pipe', invalidStdio]));85- }, {message: /must not include/});86-};87-88-test('Cannot pass "ignore" and another value to stdin', testInvalidArrayValue, 'ignore', 0, execa);89-test('Cannot pass "ignore" and another value to stdout', testInvalidArrayValue, 'ignore', 1, execa);90-test('Cannot pass "ignore" and another value to stderr', testInvalidArrayValue, 'ignore', 2, execa);91-test('Cannot pass "ignore" and another value to stdio[*]', testInvalidArrayValue, 'ignore', 3, execa);92-test('Cannot pass "ignore" and another value to stdin - sync', testInvalidArrayValue, 'ignore', 0, execaSync);93-test('Cannot pass "ignore" and another value to stdout - sync', testInvalidArrayValue, 'ignore', 1, execaSync);94-test('Cannot pass "ignore" and another value to stderr - sync', testInvalidArrayValue, 'ignore', 2, execaSync);95-test('Cannot pass "ignore" and another value to stdio[*] - sync', testInvalidArrayValue, 'ignore', 3, execaSync);96-test('Cannot pass "ipc" and another value to stdin', testInvalidArrayValue, 'ipc', 0, execa);97-test('Cannot pass "ipc" and another value to stdout', testInvalidArrayValue, 'ipc', 1, execa);98-test('Cannot pass "ipc" and another value to stderr', testInvalidArrayValue, 'ipc', 2, execa);99-test('Cannot pass "ipc" and another value to stdio[*]', testInvalidArrayValue, 'ipc', 3, execa);100-test('Cannot pass "ipc" and another value to stdin - sync', testInvalidArrayValue, 'ipc', 0, execaSync);101-test('Cannot pass "ipc" and another value to stdout - sync', testInvalidArrayValue, 'ipc', 1, execaSync);102-test('Cannot pass "ipc" and another value to stderr - sync', testInvalidArrayValue, 'ipc', 2, execaSync);103-test('Cannot pass "ipc" and another value to stdio[*] - sync', testInvalidArrayValue, 'ipc', 3, execaSync);added:test/stdio/lines-main.js+108 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {fullStdio} from '../helpers/stdio.js';5+import {getOutputsGenerator} from '../helpers/generator.js';6+import {foobarString} from '../helpers/input.js';7+import {8+ simpleFull,9+ simpleChunks,10+ simpleFullEndChunks,11+ simpleLines,12+ simpleFullEndLines,13+ noNewlinesChunks,14+ getSimpleChunkSubprocessAsync,15+} from '../helpers/lines.js';16+17+setFixtureDir();18+19+// eslint-disable-next-line max-params20+const testStreamLines = async (t, fdNumber, input, expectedOutput, lines, stripFinalNewline, execaMethod) => {21+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {...fullStdio, lines, stripFinalNewline});22+ t.deepEqual(stdio[fdNumber], expectedOutput);23+};24+25+test('"lines: true" splits lines, stdout', testStreamLines, 1, simpleFull, simpleLines, true, false, execa);26+test('"lines: true" splits lines, stdout, fd-specific', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execa);27+test('"lines: true" splits lines, stderr', testStreamLines, 2, simpleFull, simpleLines, true, false, execa);28+test('"lines: true" splits lines, stderr, fd-specific', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execa);29+test('"lines: true" splits lines, stdio[*]', testStreamLines, 3, simpleFull, simpleLines, true, false, execa);30+test('"lines: true" splits lines, stdio[*], fd-specific', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execa);31+test('"lines: true" splits lines, stdout, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execa);32+test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execa);33+test('"lines: true" splits lines, stderr, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execa);34+test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execa);35+test('"lines: true" splits lines, stdio[*], stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execa);36+test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execa);37+test('"lines: true" splits lines, stdout, sync', testStreamLines, 1, simpleFull, simpleLines, true, false, execaSync);38+test('"lines: true" splits lines, stdout, fd-specific, sync', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execaSync);39+test('"lines: true" splits lines, stderr, sync', testStreamLines, 2, simpleFull, simpleLines, true, false, execaSync);40+test('"lines: true" splits lines, stderr, fd-specific, sync', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execaSync);41+test('"lines: true" splits lines, stdio[*], sync', testStreamLines, 3, simpleFull, simpleLines, true, false, execaSync);42+test('"lines: true" splits lines, stdio[*], fd-specific, sync', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execaSync);43+test('"lines: true" splits lines, stdout, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execaSync);44+test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execaSync);45+test('"lines: true" splits lines, stderr, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execaSync);46+test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execaSync);47+test('"lines: true" splits lines, stdio[*], stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execaSync);48+test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execaSync);49+50+const bigArray = Array.from({length: 1e5}).fill('.\n');51+const bigString = bigArray.join('');52+const bigStringNoNewlines = '.'.repeat(1e6);53+const bigStringNoNewlinesEnd = `${bigStringNoNewlines}\n`;54+55+// eslint-disable-next-line max-params56+const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary, stripFinalNewline, execaMethod) => {57+ const {stdout} = await execaMethod('noop.js', {58+ stdout: getOutputsGenerator(input)(objectMode, binary),59+ lines: true,60+ stripFinalNewline,61+ });62+ t.deepEqual(stdout, expectedLines);63+};64+65+test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execa);66+test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execa);67+test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execa);68+test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execa);69+test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execa);70+test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execa);71+test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execa);72+test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execa);73+test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execa);74+test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execa);75+test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execaSync);76+test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execaSync);77+test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execaSync);78+test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execaSync);79+test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execaSync);80+test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execaSync);81+test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execaSync);82+test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execaSync);83+test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execaSync);84+test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync);85+86+test('"lines: true" stops on stream error', async t => {87+ const cause = new Error(foobarString);88+ const error = await t.throwsAsync(getSimpleChunkSubprocessAsync({89+ * stdout(line) {90+ if (line === noNewlinesChunks[2]) {91+ throw cause;92+ }93+94+ yield line;95+ },96+ }));97+ t.is(error.cause, cause);98+ t.deepEqual(error.stdout, noNewlinesChunks.slice(0, 2));99+});100+101+test('"lines: true" stops on stream error event', async t => {102+ const cause = new Error(foobarString);103+ const subprocess = getSimpleChunkSubprocessAsync();104+ subprocess.stdout.emit('error', cause);105+ const error = await t.throwsAsync(subprocess);106+ t.is(error.cause, cause);107+ t.deepEqual(error.stdout, []);108+});added:test/stdio/lines-max-buffer.js+50 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {simpleLines, noNewlinesChunks, getSimpleChunkSubprocessAsync} from '../helpers/lines.js';5+import {assertErrorMessage} from '../helpers/max-buffer.js';6+7+setFixtureDir();8+9+const maxBuffer = simpleLines.length - 1;10+11+const testBelowMaxBuffer = async (t, lines) => {12+ const {isMaxBuffer, stdout} = await getSimpleChunkSubprocessAsync({lines, maxBuffer: maxBuffer + 1});13+ t.false(isMaxBuffer);14+ t.deepEqual(stdout, noNewlinesChunks);15+};16+17+test('"lines: true" can be below "maxBuffer"', testBelowMaxBuffer, true);18+test('"lines: true" can be below "maxBuffer", fd-specific', testBelowMaxBuffer, {stdout: true});19+20+const testAboveMaxBuffer = async (t, lines) => {21+ const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(getSimpleChunkSubprocessAsync({lines, maxBuffer}));22+ t.true(isMaxBuffer);23+ assertErrorMessage(t, shortMessage, {length: maxBuffer, unit: 'lines'});24+ t.deepEqual(stdout, noNewlinesChunks.slice(0, maxBuffer));25+};26+27+test('"lines: true" can be above "maxBuffer"', testAboveMaxBuffer, true);28+test('"lines: true" can be above "maxBuffer", fd-specific', testAboveMaxBuffer, {stdout: true});29+30+const testMaxBufferUnit = async (t, lines) => {31+ const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(execa('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer}));32+ t.true(isMaxBuffer);33+ assertErrorMessage(t, shortMessage, {length: maxBuffer, unit: 'lines'});34+ t.deepEqual(stdout, ['...', '...']);35+};36+37+test('"maxBuffer" is measured in lines with "lines: true"', testMaxBufferUnit, true);38+test('"maxBuffer" is measured in lines with "lines: true", fd-specific', testMaxBufferUnit, {stdout: true});39+40+const testMaxBufferUnitSync = (t, lines) => {41+ const {isMaxBuffer, shortMessage, stdout} = t.throws(() => {42+ execaSync('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer});43+ }, {code: 'ENOBUFS'});44+ t.true(isMaxBuffer);45+ assertErrorMessage(t, shortMessage, {execaMethod: execaSync, length: maxBuffer});46+ t.deepEqual(stdout, ['..']);47+};48+49+test('"maxBuffer" is measured in bytes with "lines: true", sync', testMaxBufferUnitSync, true);50+test('"maxBuffer" is measured in bytes with "lines: true", fd-specific, sync', testMaxBufferUnitSync, {stdout: true});added:test/stdio/lines-mixed.js+55 added
1+import {Writable} from 'node:stream';2+import test from 'ava';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';5+import {simpleFull, simpleLines, noNewlinesChunks, getSimpleChunkSubprocessAsync} from '../helpers/lines.js';6+7+setFixtureDir();8+9+const testAsyncIteration = async (t, expectedLines, stripFinalNewline) => {10+ const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});11+ t.false(subprocess.stdout.readableObjectMode);12+ await assertStreamOutput(t, subprocess.stdout, simpleFull);13+ const {stdout} = await subprocess;14+ t.deepEqual(stdout, expectedLines);15+};16+17+test('"lines: true" works with stream async iteration', testAsyncIteration, simpleLines, false);18+test('"lines: true" works with stream async iteration, stripFinalNewline', testAsyncIteration, noNewlinesChunks, true);19+20+const testDataEvents = async (t, expectedLines, stripFinalNewline) => {21+ const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});22+ await assertStreamDataEvents(t, subprocess.stdout, simpleFull);23+ const {stdout} = await subprocess;24+ t.deepEqual(stdout, expectedLines);25+};26+27+test('"lines: true" works with stream "data" events', testDataEvents, simpleLines, false);28+test('"lines: true" works with stream "data" events, stripFinalNewline', testDataEvents, noNewlinesChunks, true);29+30+const testWritableStream = async (t, expectedLines, stripFinalNewline) => {31+ let output = '';32+ const writable = new Writable({33+ write(line, encoding, done) {34+ output += line.toString();35+ done();36+ },37+ decodeStrings: false,38+ });39+ const {stdout} = await getSimpleChunkSubprocessAsync({stripFinalNewline, stdout: ['pipe', writable]});40+ t.deepEqual(output, simpleFull);41+ t.deepEqual(stdout, expectedLines);42+};43+44+test('"lines: true" works with writable streams targets', testWritableStream, simpleLines, false);45+test('"lines: true" works with writable streams targets, stripFinalNewline', testWritableStream, noNewlinesChunks, true);46+47+const testIterable = async (t, expectedLines, stripFinalNewline) => {48+ const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});49+ await assertIterableChunks(t, subprocess, noNewlinesChunks);50+ const {stdout} = await subprocess;51+ t.deepEqual(stdout, expectedLines);52+};53+54+test('"lines: true" works with subprocess.iterable()', testIterable, simpleLines, false);55+test('"lines: true" works with subprocess.iterable(), stripFinalNewline', testIterable, noNewlinesChunks, true);added:test/stdio/lines-noop.js+84 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {getOutputsGenerator} from '../helpers/generator.js';5+import {foobarObject} from '../helpers/input.js';6+import {7+ simpleFull,8+ simpleFullUint8Array,9+ simpleFullHex,10+ simpleFullUtf16Uint8Array,11+ simpleLines,12+ noNewlinesChunks,13+ getSimpleChunkSubprocess,14+} from '../helpers/lines.js';15+16+setFixtureDir();17+18+const testStreamLinesNoop = async (t, lines, execaMethod) => {19+ const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});20+ t.is(stdout, simpleFull);21+};22+23+test('"lines: false" is a noop', testStreamLinesNoop, false, execa);24+test('"lines: false" is a noop, fd-specific', testStreamLinesNoop, {stderr: true}, execa);25+test('"lines: false" is a noop, fd-specific none', testStreamLinesNoop, {}, execa);26+test('"lines: false" is a noop, sync', testStreamLinesNoop, false, execaSync);27+test('"lines: false" is a noop, fd-specific, sync', testStreamLinesNoop, {stderr: true}, execaSync);28+test('"lines: false" is a noop, fd-specific none, sync', testStreamLinesNoop, {}, execaSync);29+30+const testLinesObjectMode = async (t, lines, execaMethod) => {31+ const {stdout} = await execaMethod('noop.js', {32+ stdout: getOutputsGenerator([foobarObject])(true),33+ lines,34+ });35+ t.deepEqual(stdout, [foobarObject]);36+};37+38+test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, true, execa);39+test('"lines: true" is a noop with objects generators, fd-specific, objectMode', testLinesObjectMode, {stdout: true}, execa);40+test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, true, execaSync);41+test('"lines: true" is a noop with objects generators, fd-specific, objectMode, sync', testLinesObjectMode, {stdout: true}, execaSync);42+43+// eslint-disable-next-line max-params44+const testEncoding = async (t, input, expectedOutput, encoding, lines, stripFinalNewline, execaMethod) => {45+ const {stdout} = await execaMethod('stdin.js', {lines, stripFinalNewline, encoding, input});46+ t.deepEqual(stdout, expectedOutput);47+};48+49+test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execa);50+test('"lines: true" is a noop with "encoding: utf16", fd-specific', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execa);51+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execa);52+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execa);53+test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);54+test('"lines: true" is a noop with "encoding: buffer", fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execa);55+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);56+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execa);57+test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execa);58+test('"lines: true" is a noop with "encoding: hex", fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execa);59+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execa);60+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execa);61+test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execaSync);62+test('"lines: true" is a noop with "encoding: utf16", fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execaSync);63+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execaSync);64+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execaSync);65+test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);66+test('"lines: true" is a noop with "encoding: buffer", fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execaSync);67+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);68+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execaSync);69+test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execaSync);70+test('"lines: true" is a noop with "encoding: hex", fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execaSync);71+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execaSync);72+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execaSync);73+74+const testLinesNoBuffer = async (t, lines, buffer, execaMethod) => {75+ const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer});76+ t.is(stdout, undefined);77+};78+79+test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, false, execa);80+test('"lines: true" is a noop with "buffer: false", fd-specific buffer', testLinesNoBuffer, true, {stdout: false}, execa);81+test('"lines: true" is a noop with "buffer: false", fd-specific lines', testLinesNoBuffer, {stdout: true}, false, execa);82+test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, false, execaSync);83+test('"lines: true" is a noop with "buffer: false", fd-specific buffer, sync', testLinesNoBuffer, true, {stdout: false}, execaSync);84+test('"lines: true" is a noop with "buffer: false", fd-specific lines, sync', testLinesNoBuffer, {stdout: true}, false, execaSync);deleted:test/stdio/lines.js-275 removed
1-import {Writable} from 'node:stream';2-import test from 'ava';3-import {execa, execaSync} from '../../index.js';4-import {setFixtureDir} from '../helpers/fixtures-dir.js';5-import {fullStdio} from '../helpers/stdio.js';6-import {getOutputsGenerator} from '../helpers/generator.js';7-import {foobarString, foobarObject} from '../helpers/input.js';8-import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';9-import {10- simpleFull,11- simpleChunks,12- simpleFullEndChunks,13- simpleFullUint8Array,14- simpleFullHex,15- simpleFullUtf16Uint8Array,16- simpleLines,17- simpleFullEndLines,18- noNewlinesChunks,19-} from '../helpers/lines.js';20-import {assertErrorMessage} from '../helpers/max-buffer.js';21-22-setFixtureDir();23-24-const getSimpleChunkSubprocessAsync = options => getSimpleChunkSubprocess(execa, options);25-const getSimpleChunkSubprocess = (execaMethod, options) => execaMethod('noop-fd.js', ['1', simpleFull], {lines: true, ...options});26-27-// eslint-disable-next-line max-params28-const testStreamLines = async (t, fdNumber, input, expectedOutput, lines, stripFinalNewline, execaMethod) => {29- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {...fullStdio, lines, stripFinalNewline});30- t.deepEqual(stdio[fdNumber], expectedOutput);31-};32-33-test('"lines: true" splits lines, stdout', testStreamLines, 1, simpleFull, simpleLines, true, false, execa);34-test('"lines: true" splits lines, stdout, fd-specific', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execa);35-test('"lines: true" splits lines, stderr', testStreamLines, 2, simpleFull, simpleLines, true, false, execa);36-test('"lines: true" splits lines, stderr, fd-specific', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execa);37-test('"lines: true" splits lines, stdio[*]', testStreamLines, 3, simpleFull, simpleLines, true, false, execa);38-test('"lines: true" splits lines, stdio[*], fd-specific', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execa);39-test('"lines: true" splits lines, stdout, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execa);40-test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execa);41-test('"lines: true" splits lines, stderr, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execa);42-test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execa);43-test('"lines: true" splits lines, stdio[*], stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execa);44-test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execa);45-test('"lines: true" splits lines, stdout, sync', testStreamLines, 1, simpleFull, simpleLines, true, false, execaSync);46-test('"lines: true" splits lines, stdout, fd-specific, sync', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execaSync);47-test('"lines: true" splits lines, stderr, sync', testStreamLines, 2, simpleFull, simpleLines, true, false, execaSync);48-test('"lines: true" splits lines, stderr, fd-specific, sync', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execaSync);49-test('"lines: true" splits lines, stdio[*], sync', testStreamLines, 3, simpleFull, simpleLines, true, false, execaSync);50-test('"lines: true" splits lines, stdio[*], fd-specific, sync', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execaSync);51-test('"lines: true" splits lines, stdout, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execaSync);52-test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execaSync);53-test('"lines: true" splits lines, stderr, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execaSync);54-test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execaSync);55-test('"lines: true" splits lines, stdio[*], stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execaSync);56-test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execaSync);57-58-const testStreamLinesNoop = async (t, lines, execaMethod) => {59- const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});60- t.is(stdout, simpleFull);61-};62-63-test('"lines: false" is a noop', testStreamLinesNoop, false, execa);64-test('"lines: false" is a noop, fd-specific', testStreamLinesNoop, {stderr: true}, execa);65-test('"lines: false" is a noop, fd-specific none', testStreamLinesNoop, {}, execa);66-test('"lines: false" is a noop, sync', testStreamLinesNoop, false, execaSync);67-test('"lines: false" is a noop, fd-specific, sync', testStreamLinesNoop, {stderr: true}, execaSync);68-test('"lines: false" is a noop, fd-specific none, sync', testStreamLinesNoop, {}, execaSync);69-70-const bigArray = Array.from({length: 1e5}).fill('.\n');71-const bigString = bigArray.join('');72-const bigStringNoNewlines = '.'.repeat(1e6);73-const bigStringNoNewlinesEnd = `${bigStringNoNewlines}\n`;74-75-// eslint-disable-next-line max-params76-const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary, stripFinalNewline, execaMethod) => {77- const {stdout} = await execaMethod('noop.js', {78- stdout: getOutputsGenerator(input)(objectMode, binary),79- lines: true,80- stripFinalNewline,81- });82- t.deepEqual(stdout, expectedLines);83-};84-85-test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execa);86-test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execa);87-test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execa);88-test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execa);89-test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execa);90-test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execa);91-test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execa);92-test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execa);93-test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execa);94-test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execa);95-test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execaSync);96-test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execaSync);97-test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execaSync);98-test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execaSync);99-test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execaSync);100-test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execaSync);101-test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execaSync);102-test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execaSync);103-test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execaSync);104-test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync);105-106-const testLinesObjectMode = async (t, lines, execaMethod) => {107- const {stdout} = await execaMethod('noop.js', {108- stdout: getOutputsGenerator([foobarObject])(true),109- lines,110- });111- t.deepEqual(stdout, [foobarObject]);112-};113-114-test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, true, execa);115-test('"lines: true" is a noop with objects generators, fd-specific, objectMode', testLinesObjectMode, {stdout: true}, execa);116-test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, true, execaSync);117-test('"lines: true" is a noop with objects generators, fd-specific, objectMode, sync', testLinesObjectMode, {stdout: true}, execaSync);118-119-// eslint-disable-next-line max-params120-const testEncoding = async (t, input, expectedOutput, encoding, lines, stripFinalNewline, execaMethod) => {121- const {stdout} = await execaMethod('stdin.js', {lines, stripFinalNewline, encoding, input});122- t.deepEqual(stdout, expectedOutput);123-};124-125-test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execa);126-test('"lines: true" is a noop with "encoding: utf16", fd-specific', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execa);127-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execa);128-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execa);129-test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);130-test('"lines: true" is a noop with "encoding: buffer", fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execa);131-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);132-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execa);133-test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execa);134-test('"lines: true" is a noop with "encoding: hex", fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execa);135-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execa);136-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execa);137-test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execaSync);138-test('"lines: true" is a noop with "encoding: utf16", fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execaSync);139-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execaSync);140-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execaSync);141-test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);142-test('"lines: true" is a noop with "encoding: buffer", fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execaSync);143-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);144-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execaSync);145-test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execaSync);146-test('"lines: true" is a noop with "encoding: hex", fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execaSync);147-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execaSync);148-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execaSync);149-150-const testLinesNoBuffer = async (t, lines, buffer, execaMethod) => {151- const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer});152- t.is(stdout, undefined);153-};154-155-test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, false, execa);156-test('"lines: true" is a noop with "buffer: false", fd-specific buffer', testLinesNoBuffer, true, {stdout: false}, execa);157-test('"lines: true" is a noop with "buffer: false", fd-specific lines', testLinesNoBuffer, {stdout: true}, false, execa);158-test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, false, execaSync);159-test('"lines: true" is a noop with "buffer: false", fd-specific buffer, sync', testLinesNoBuffer, true, {stdout: false}, execaSync);160-test('"lines: true" is a noop with "buffer: false", fd-specific lines, sync', testLinesNoBuffer, {stdout: true}, false, execaSync);161-162-const maxBuffer = simpleLines.length - 1;163-164-const testBelowMaxBuffer = async (t, lines) => {165- const {isMaxBuffer, stdout} = await getSimpleChunkSubprocessAsync({lines, maxBuffer: maxBuffer + 1});166- t.false(isMaxBuffer);167- t.deepEqual(stdout, noNewlinesChunks);168-};169-170-test('"lines: true" can be below "maxBuffer"', testBelowMaxBuffer, true);171-test('"lines: true" can be below "maxBuffer", fd-specific', testBelowMaxBuffer, {stdout: true});172-173-const testAboveMaxBuffer = async (t, lines) => {174- const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(getSimpleChunkSubprocessAsync({lines, maxBuffer}));175- t.true(isMaxBuffer);176- assertErrorMessage(t, shortMessage, {length: maxBuffer, unit: 'lines'});177- t.deepEqual(stdout, noNewlinesChunks.slice(0, maxBuffer));178-};179-180-test('"lines: true" can be above "maxBuffer"', testAboveMaxBuffer, true);181-test('"lines: true" can be above "maxBuffer", fd-specific', testAboveMaxBuffer, {stdout: true});182-183-const testMaxBufferUnit = async (t, lines) => {184- const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(execa('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer}));185- t.true(isMaxBuffer);186- assertErrorMessage(t, shortMessage, {length: maxBuffer, unit: 'lines'});187- t.deepEqual(stdout, ['...', '...']);188-};189-190-test('"maxBuffer" is measured in lines with "lines: true"', testMaxBufferUnit, true);191-test('"maxBuffer" is measured in lines with "lines: true", fd-specific', testMaxBufferUnit, {stdout: true});192-193-const testMaxBufferUnitSync = (t, lines) => {194- const {isMaxBuffer, shortMessage, stdout} = t.throws(() => {195- execaSync('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer});196- }, {code: 'ENOBUFS'});197- t.true(isMaxBuffer);198- assertErrorMessage(t, shortMessage, {execaMethod: execaSync, length: maxBuffer});199- t.deepEqual(stdout, ['..']);200-};201-202-test('"maxBuffer" is measured in bytes with "lines: true", sync', testMaxBufferUnitSync, true);203-test('"maxBuffer" is measured in bytes with "lines: true", fd-specific, sync', testMaxBufferUnitSync, {stdout: true});204-205-test('"lines: true" stops on stream error', async t => {206- const cause = new Error(foobarString);207- const error = await t.throwsAsync(getSimpleChunkSubprocessAsync({208- * stdout(line) {209- if (line === noNewlinesChunks[2]) {210- throw cause;211- }212-213- yield line;214- },215- }));216- t.is(error.cause, cause);217- t.deepEqual(error.stdout, noNewlinesChunks.slice(0, 2));218-});219-220-test('"lines: true" stops on stream error event', async t => {221- const cause = new Error(foobarString);222- const subprocess = getSimpleChunkSubprocessAsync();223- subprocess.stdout.emit('error', cause);224- const error = await t.throwsAsync(subprocess);225- t.is(error.cause, cause);226- t.deepEqual(error.stdout, []);227-});228-229-const testAsyncIteration = async (t, expectedLines, stripFinalNewline) => {230- const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});231- t.false(subprocess.stdout.readableObjectMode);232- await assertStreamOutput(t, subprocess.stdout, simpleFull);233- const {stdout} = await subprocess;234- t.deepEqual(stdout, expectedLines);235-};236-237-test('"lines: true" works with stream async iteration', testAsyncIteration, simpleLines, false);238-test('"lines: true" works with stream async iteration, stripFinalNewline', testAsyncIteration, noNewlinesChunks, true);239-240-const testDataEvents = async (t, expectedLines, stripFinalNewline) => {241- const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});242- await assertStreamDataEvents(t, subprocess.stdout, simpleFull);243- const {stdout} = await subprocess;244- t.deepEqual(stdout, expectedLines);245-};246-247-test('"lines: true" works with stream "data" events', testDataEvents, simpleLines, false);248-test('"lines: true" works with stream "data" events, stripFinalNewline', testDataEvents, noNewlinesChunks, true);249-250-const testWritableStream = async (t, expectedLines, stripFinalNewline) => {251- let output = '';252- const writable = new Writable({253- write(line, encoding, done) {254- output += line.toString();255- done();256- },257- decodeStrings: false,258- });259- const {stdout} = await getSimpleChunkSubprocessAsync({stripFinalNewline, stdout: ['pipe', writable]});260- t.deepEqual(output, simpleFull);261- t.deepEqual(stdout, expectedLines);262-};263-264-test('"lines: true" works with writable streams targets', testWritableStream, simpleLines, false);265-test('"lines: true" works with writable streams targets, stripFinalNewline', testWritableStream, noNewlinesChunks, true);266-267-const testIterable = async (t, expectedLines, stripFinalNewline) => {268- const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});269- await assertIterableChunks(t, subprocess, noNewlinesChunks);270- const {stdout} = await subprocess;271- t.deepEqual(stdout, expectedLines);272-};273-274-test('"lines: true" works with subprocess.iterable()', testIterable, simpleLines, false);275-test('"lines: true" works with subprocess.iterable(), stripFinalNewline', testIterable, noNewlinesChunks, true);added:test/stdio/native-fd.js+76 added
1+import {platform} from 'node:process';2+import test from 'ava';3+import {execa, execaSync} from '../../index.js';4+import {getStdio, fullStdio} from '../helpers/stdio.js';5+import {setFixtureDir} from '../helpers/fixtures-dir.js';6+import {foobarString} from '../helpers/input.js';7+import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';8+9+setFixtureDir();10+11+const isLinux = platform === 'linux';12+const isWindows = platform === 'win32';13+14+const testFd3InheritOutput = async (t, stdioOption, execaMethod) => {15+ const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio);16+ t.is(stdio[3], foobarString);17+};18+19+test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);20+test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);21+test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);22+test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);23+24+if (isLinux) {25+ const testOverflowStream = async (t, fdNumber, stdioOption, execaMethod) => {26+ const {stdout} = await execaMethod('empty.js', getStdio(fdNumber, stdioOption), fullStdio);27+ t.is(stdout, '');28+ };29+30+ test('stdin can use 4+', testOverflowStream, 0, 4, parentExecaAsync);31+ test('stdin can use [4+]', testOverflowStream, 0, [4], parentExecaAsync);32+ test('stdout can use 4+', testOverflowStream, 1, 4, parentExecaAsync);33+ test('stdout can use [4+]', testOverflowStream, 1, [4], parentExecaAsync);34+ test('stderr can use 4+', testOverflowStream, 2, 4, parentExecaAsync);35+ test('stderr can use [4+]', testOverflowStream, 2, [4], parentExecaAsync);36+ test('stdio[*] can use 4+', testOverflowStream, 3, 4, parentExecaAsync);37+ test('stdio[*] can use [4+]', testOverflowStream, 3, [4], parentExecaAsync);38+ test('stdin can use 4+, sync', testOverflowStream, 0, 4, parentExecaSync);39+ test('stdin can use [4+], sync', testOverflowStream, 0, [4], parentExecaSync);40+ test('stdout can use 4+, sync', testOverflowStream, 1, 4, parentExecaSync);41+ test('stdout can use [4+], sync', testOverflowStream, 1, [4], parentExecaSync);42+ test('stderr can use 4+, sync', testOverflowStream, 2, 4, parentExecaSync);43+ test('stderr can use [4+], sync', testOverflowStream, 2, [4], parentExecaSync);44+ test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, parentExecaSync);45+ test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], parentExecaSync);46+}47+48+const testOverflowStreamArray = (t, fdNumber, stdioOption) => {49+ t.throws(() => {50+ execa('empty.js', getStdio(fdNumber, stdioOption));51+ }, {message: /no such standard stream/});52+};53+54+test('stdin cannot use 4+ and another value', testOverflowStreamArray, 0, [4, 'pipe']);55+test('stdout cannot use 4+ and another value', testOverflowStreamArray, 1, [4, 'pipe']);56+test('stderr cannot use 4+ and another value', testOverflowStreamArray, 2, [4, 'pipe']);57+test('stdio[*] cannot use 4+ and another value', testOverflowStreamArray, 3, [4, 'pipe']);58+test('stdio[*] cannot use "inherit" and another value', testOverflowStreamArray, 3, ['inherit', 'pipe']);59+60+const getInvalidFdCode = () => {61+ if (isLinux) {62+ return 'EINVAL';63+ }64+65+ return isWindows ? 'EBADF' : 'ENXIO';66+};67+68+const testOverflowStreamArraySync = (t, fdNumber) => {69+ t.throws(() => {70+ execaSync('noop-fd.js', [fdNumber, foobarString], getStdio(fdNumber, [4, 'pipe']));71+ }, {code: getInvalidFdCode()});72+};73+74+test('stdout cannot use 4+ and another value, sync', testOverflowStreamArraySync, 1);75+test('stderr cannot use 4+ and another value, sync', testOverflowStreamArraySync, 2);76+test('stdio[*] cannot use 4+ and another value, sync', testOverflowStreamArraySync, 3);added:test/stdio/native-inherit-pipe.js+97 added
1+import {readFile, rm} from 'node:fs/promises';2+import test from 'ava';3+import tempfile from 'tempfile';4+import {execa} from '../../index.js';5+import {getStdio, fullStdio} from '../helpers/stdio.js';6+import {setFixtureDir} from '../helpers/fixtures-dir.js';7+import {foobarString} from '../helpers/input.js';8+import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';9+10+setFixtureDir();11+12+const testInheritStdin = async (t, stdioOption, isSync) => {13+ const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdioOption), `${isSync}`], {input: foobarString});14+ t.is(stdout, `${foobarString}${foobarString}`);15+};16+17+test('stdin can be ["inherit", "pipe"]', testInheritStdin, ['inherit', 'pipe'], false);18+test('stdin can be [0, "pipe"]', testInheritStdin, [0, 'pipe'], false);19+test('stdin can be [process.stdin, "pipe"]', testInheritStdin, ['stdin', 'pipe'], false);20+test.serial('stdin can be ["inherit", "pipe"], sync', testInheritStdin, ['inherit', 'pipe'], true);21+test.serial('stdin can be [0, "pipe"], sync', testInheritStdin, [0, 'pipe'], true);22+test.serial('stdin can be [process.stdin, "pipe"], sync', testInheritStdin, ['stdin', 'pipe'], true);23+24+// eslint-disable-next-line max-params25+const testInheritStdioOutput = async (t, fdNumber, outerFdNumber, stdioOption, isSync, encoding) => {26+ const {stdio} = await execa('nested-multiple-stdio-output.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${outerFdNumber}`, `${isSync}`, encoding], fullStdio);27+ t.is(stdio[fdNumber], foobarString);28+ t.is(stdio[outerFdNumber], `nested ${foobarString}`);29+};30+31+test('stdout can be ["inherit", "pipe"]', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], false, 'utf8');32+test('stdout can be [1, "pipe"]', testInheritStdioOutput, 1, 2, [1, 'pipe'], false, 'utf8');33+test('stdout can be [process.stdout, "pipe"]', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], false, 'utf8');34+test('stderr can be ["inherit", "pipe"]', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], false, 'utf8');35+test('stderr can be [2, "pipe"]', testInheritStdioOutput, 2, 1, [2, 'pipe'], false, 'utf8');36+test('stderr can be [process.stderr, "pipe"]', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], false, 'utf8');37+test('stdout can be ["inherit", "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], false, 'buffer');38+test('stdout can be [1, "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, [1, 'pipe'], false, 'buffer');39+test('stdout can be [process.stdout, "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], false, 'buffer');40+test('stderr can be ["inherit", "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], false, 'buffer');41+test('stderr can be [2, "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, [2, 'pipe'], false, 'buffer');42+test('stderr can be [process.stderr, "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], false, 'buffer');43+test('stdout can be ["inherit", "pipe"], sync', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], true, 'utf8');44+test('stdout can be [1, "pipe"], sync', testInheritStdioOutput, 1, 2, [1, 'pipe'], true, 'utf8');45+test('stdout can be [process.stdout, "pipe"], sync', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], true, 'utf8');46+test('stderr can be ["inherit", "pipe"], sync', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], true, 'utf8');47+test('stderr can be [2, "pipe"], sync', testInheritStdioOutput, 2, 1, [2, 'pipe'], true, 'utf8');48+test('stderr can be [process.stderr, "pipe"], sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'utf8');49+test('stdio[*] output can be ["inherit", "pipe"], sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'utf8');50+test('stdio[*] output can be [3, "pipe"], sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'utf8');51+test('stdout can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], true, 'buffer');52+test('stdout can be [1, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, [1, 'pipe'], true, 'buffer');53+test('stdout can be [process.stdout, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], true, 'buffer');54+test('stderr can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], true, 'buffer');55+test('stderr can be [2, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, [2, 'pipe'], true, 'buffer');56+test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');57+test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');58+test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');59+60+const testInheritNoBuffer = async (t, stdioOption, execaMethod) => {61+ const filePath = tempfile();62+ await execaMethod('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false}, {input: foobarString});63+ t.is(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);64+ await rm(filePath);65+};66+67+test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaAsync);68+test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], parentExecaAsync);69+test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaSync);70+test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], parentExecaSync);71+72+test('stdin can use ["inherit", "pipe"] in a TTY', async t => {73+ const stdioOption = [['inherit', 'pipe'], 'inherit', 'pipe'];74+ const {stdout} = await execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'false', 'stdin-fd.js', '0'], {input: foobarString});75+ t.is(stdout, foobarString);76+});77+78+const testNoTtyInput = async (t, fdNumber, optionName) => {79+ const stdioOption = ['pipe', 'inherit', 'pipe'];80+ stdioOption[fdNumber] = [[''], 'inherit', 'pipe'];81+ const {message} = await t.throwsAsync(execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'true', 'stdin-fd.js', `${fdNumber}`], fullStdio));82+ t.true(message.includes(`The \`${optionName}: 'inherit'\` option is invalid: it cannot be a TTY`));83+};84+85+test('stdin cannot use ["inherit", "pipe"] in a TTY, sync', testNoTtyInput, 0, 'stdin');86+test('stdio[*] input cannot use ["inherit", "pipe"] in a TTY, sync', testNoTtyInput, 3, 'stdio[3]');87+88+const testTtyOutput = async (t, fdNumber, isSync) => {89+ const {stdio} = await execa('nested-sync-tty.js', [JSON.stringify(getStdio(fdNumber, ['inherit', 'pipe'])), `${isSync}`, 'noop-fd.js', `${fdNumber}`, foobarString], fullStdio);90+ t.is(stdio[fdNumber], foobarString);91+};92+93+test('stdout can use ["inherit", "pipe"] in a TTY', testTtyOutput, 1, false);94+test('stderr can use ["inherit", "pipe"] in a TTY', testTtyOutput, 2, false);95+test('stdout can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 1, true);96+test('stderr can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 2, true);97+test('stdio[*] output can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 3, true);added:test/stdio/native-redirect.js+75 added
1+import test from 'ava';2+import {execa} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString} from '../helpers/input.js';5+6+setFixtureDir();7+8+// eslint-disable-next-line max-params9+const testRedirect = async (t, stdioOption, fdNumber, isInput, isSync) => {10+ const {fixtureName, ...options} = isInput11+ ? {fixtureName: 'stdin-fd.js', input: foobarString}12+ : {fixtureName: 'noop-fd.js'};13+ const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${isSync}`, fixtureName, foobarString], options);14+ const resultFdNumber = isStderrDescriptor(stdioOption) ? 2 : 1;15+ t.is(stdio[resultFdNumber], foobarString);16+};17+18+const isStderrDescriptor = stdioOption => stdioOption === 219+ || stdioOption === 'stderr'20+ || (Array.isArray(stdioOption) && isStderrDescriptor(stdioOption[0]));21+22+test.serial('stdio[*] can be 0', testRedirect, 0, 3, true, false);23+test.serial('stdio[*] can be [0]', testRedirect, [0], 3, true, false);24+test.serial('stdio[*] can be [0, "pipe"]', testRedirect, [0, 'pipe'], 3, true, false);25+test.serial('stdio[*] can be process.stdin', testRedirect, 'stdin', 3, true, false);26+test.serial('stdio[*] can be [process.stdin]', testRedirect, ['stdin'], 3, true, false);27+test.serial('stdio[*] can be [process.stdin, "pipe"]', testRedirect, ['stdin', 'pipe'], 3, true, false);28+test('stdout can be 2', testRedirect, 2, 1, false, false);29+test('stdout can be [2]', testRedirect, [2], 1, false, false);30+test('stdout can be [2, "pipe"]', testRedirect, [2, 'pipe'], 1, false, false);31+test('stdout can be process.stderr', testRedirect, 'stderr', 1, false, false);32+test('stdout can be [process.stderr]', testRedirect, ['stderr'], 1, false, false);33+test('stdout can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 1, false, false);34+test('stderr can be 1', testRedirect, 1, 2, false, false);35+test('stderr can be [1]', testRedirect, [1], 2, false, false);36+test('stderr can be [1, "pipe"]', testRedirect, [1, 'pipe'], 2, false, false);37+test('stderr can be process.stdout', testRedirect, 'stdout', 2, false, false);38+test('stderr can be [process.stdout]', testRedirect, ['stdout'], 2, false, false);39+test('stderr can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 2, false, false);40+test('stdio[*] can be 1', testRedirect, 1, 3, false, false);41+test('stdio[*] can be [1]', testRedirect, [1], 3, false, false);42+test('stdio[*] can be [1, "pipe"]', testRedirect, [1, 'pipe'], 3, false, false);43+test('stdio[*] can be 2', testRedirect, 2, 3, false, false);44+test('stdio[*] can be [2]', testRedirect, [2], 3, false, false);45+test('stdio[*] can be [2, "pipe"]', testRedirect, [2, 'pipe'], 3, false, false);46+test('stdio[*] can be process.stdout', testRedirect, 'stdout', 3, false, false);47+test('stdio[*] can be [process.stdout]', testRedirect, ['stdout'], 3, false, false);48+test('stdio[*] can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 3, false, false);49+test('stdio[*] can be process.stderr', testRedirect, 'stderr', 3, false, false);50+test('stdio[*] can be [process.stderr]', testRedirect, ['stderr'], 3, false, false);51+test('stdio[*] can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 3, false, false);52+test('stdout can be 2, sync', testRedirect, 2, 1, false, true);53+test('stdout can be [2], sync', testRedirect, [2], 1, false, true);54+test('stdout can be [2, "pipe"], sync', testRedirect, [2, 'pipe'], 1, false, true);55+test('stdout can be process.stderr, sync', testRedirect, 'stderr', 1, false, true);56+test('stdout can be [process.stderr], sync', testRedirect, ['stderr'], 1, false, true);57+test('stdout can be [process.stderr, "pipe"], sync', testRedirect, ['stderr', 'pipe'], 1, false, true);58+test('stderr can be 1, sync', testRedirect, 1, 2, false, true);59+test('stderr can be [1], sync', testRedirect, [1], 2, false, true);60+test('stderr can be [1, "pipe"], sync', testRedirect, [1, 'pipe'], 2, false, true);61+test('stderr can be process.stdout, sync', testRedirect, 'stdout', 2, false, true);62+test('stderr can be [process.stdout], sync', testRedirect, ['stdout'], 2, false, true);63+test('stderr can be [process.stdout, "pipe"], sync', testRedirect, ['stdout', 'pipe'], 2, false, true);64+test('stdio[*] can be 1, sync', testRedirect, 1, 3, false, true);65+test('stdio[*] can be [1], sync', testRedirect, [1], 3, false, true);66+test('stdio[*] can be [1, "pipe"], sync', testRedirect, [1, 'pipe'], 3, false, true);67+test('stdio[*] can be 2, sync', testRedirect, 2, 3, false, true);68+test('stdio[*] can be [2], sync', testRedirect, [2], 3, false, true);69+test('stdio[*] can be [2, "pipe"], sync', testRedirect, [2, 'pipe'], 3, false, true);70+test('stdio[*] can be process.stdout, sync', testRedirect, 'stdout', 3, false, true);71+test('stdio[*] can be [process.stdout], sync', testRedirect, ['stdout'], 3, false, true);72+test('stdio[*] can be [process.stdout, "pipe"], sync', testRedirect, ['stdout', 'pipe'], 3, false, true);73+test('stdio[*] can be process.stderr, sync', testRedirect, 'stderr', 3, false, true);74+test('stdio[*] can be [process.stderr], sync', testRedirect, ['stderr'], 3, false, true);75+test('stdio[*] can be [process.stderr, "pipe"], sync', testRedirect, ['stderr', 'pipe'], 3, false, true);deleted:test/stdio/native.js-234 removed
1-import {readFile, rm} from 'node:fs/promises';2-import {platform} from 'node:process';3-import test from 'ava';4-import tempfile from 'tempfile';5-import {execa, execaSync} from '../../index.js';6-import {getStdio, fullStdio} from '../helpers/stdio.js';7-import {setFixtureDir} from '../helpers/fixtures-dir.js';8-import {foobarString} from '../helpers/input.js';9-import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';10-11-setFixtureDir();12-13-const isLinux = platform === 'linux';14-const isWindows = platform === 'win32';15-16-// eslint-disable-next-line max-params17-const testRedirect = async (t, stdioOption, fdNumber, isInput, isSync) => {18- const {fixtureName, ...options} = isInput19- ? {fixtureName: 'stdin-fd.js', input: foobarString}20- : {fixtureName: 'noop-fd.js'};21- const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${isSync}`, fixtureName, foobarString], options);22- const resultFdNumber = isStderrDescriptor(stdioOption) ? 2 : 1;23- t.is(stdio[resultFdNumber], foobarString);24-};25-26-const isStderrDescriptor = stdioOption => stdioOption === 227- || stdioOption === 'stderr'28- || (Array.isArray(stdioOption) && isStderrDescriptor(stdioOption[0]));29-30-test.serial('stdio[*] can be 0', testRedirect, 0, 3, true, false);31-test.serial('stdio[*] can be [0]', testRedirect, [0], 3, true, false);32-test.serial('stdio[*] can be [0, "pipe"]', testRedirect, [0, 'pipe'], 3, true, false);33-test.serial('stdio[*] can be process.stdin', testRedirect, 'stdin', 3, true, false);34-test.serial('stdio[*] can be [process.stdin]', testRedirect, ['stdin'], 3, true, false);35-test.serial('stdio[*] can be [process.stdin, "pipe"]', testRedirect, ['stdin', 'pipe'], 3, true, false);36-test('stdout can be 2', testRedirect, 2, 1, false, false);37-test('stdout can be [2]', testRedirect, [2], 1, false, false);38-test('stdout can be [2, "pipe"]', testRedirect, [2, 'pipe'], 1, false, false);39-test('stdout can be process.stderr', testRedirect, 'stderr', 1, false, false);40-test('stdout can be [process.stderr]', testRedirect, ['stderr'], 1, false, false);41-test('stdout can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 1, false, false);42-test('stderr can be 1', testRedirect, 1, 2, false, false);43-test('stderr can be [1]', testRedirect, [1], 2, false, false);44-test('stderr can be [1, "pipe"]', testRedirect, [1, 'pipe'], 2, false, false);45-test('stderr can be process.stdout', testRedirect, 'stdout', 2, false, false);46-test('stderr can be [process.stdout]', testRedirect, ['stdout'], 2, false, false);47-test('stderr can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 2, false, false);48-test('stdio[*] can be 1', testRedirect, 1, 3, false, false);49-test('stdio[*] can be [1]', testRedirect, [1], 3, false, false);50-test('stdio[*] can be [1, "pipe"]', testRedirect, [1, 'pipe'], 3, false, false);51-test('stdio[*] can be 2', testRedirect, 2, 3, false, false);52-test('stdio[*] can be [2]', testRedirect, [2], 3, false, false);53-test('stdio[*] can be [2, "pipe"]', testRedirect, [2, 'pipe'], 3, false, false);54-test('stdio[*] can be process.stdout', testRedirect, 'stdout', 3, false, false);55-test('stdio[*] can be [process.stdout]', testRedirect, ['stdout'], 3, false, false);56-test('stdio[*] can be [process.stdout, "pipe"]', testRedirect, ['stdout', 'pipe'], 3, false, false);57-test('stdio[*] can be process.stderr', testRedirect, 'stderr', 3, false, false);58-test('stdio[*] can be [process.stderr]', testRedirect, ['stderr'], 3, false, false);59-test('stdio[*] can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 3, false, false);60-test('stdout can be 2, sync', testRedirect, 2, 1, false, true);61-test('stdout can be [2], sync', testRedirect, [2], 1, false, true);62-test('stdout can be [2, "pipe"], sync', testRedirect, [2, 'pipe'], 1, false, true);63-test('stdout can be process.stderr, sync', testRedirect, 'stderr', 1, false, true);64-test('stdout can be [process.stderr], sync', testRedirect, ['stderr'], 1, false, true);65-test('stdout can be [process.stderr, "pipe"], sync', testRedirect, ['stderr', 'pipe'], 1, false, true);66-test('stderr can be 1, sync', testRedirect, 1, 2, false, true);67-test('stderr can be [1], sync', testRedirect, [1], 2, false, true);68-test('stderr can be [1, "pipe"], sync', testRedirect, [1, 'pipe'], 2, false, true);69-test('stderr can be process.stdout, sync', testRedirect, 'stdout', 2, false, true);70-test('stderr can be [process.stdout], sync', testRedirect, ['stdout'], 2, false, true);71-test('stderr can be [process.stdout, "pipe"], sync', testRedirect, ['stdout', 'pipe'], 2, false, true);72-test('stdio[*] can be 1, sync', testRedirect, 1, 3, false, true);73-test('stdio[*] can be [1], sync', testRedirect, [1], 3, false, true);74-test('stdio[*] can be [1, "pipe"], sync', testRedirect, [1, 'pipe'], 3, false, true);75-test('stdio[*] can be 2, sync', testRedirect, 2, 3, false, true);76-test('stdio[*] can be [2], sync', testRedirect, [2], 3, false, true);77-test('stdio[*] can be [2, "pipe"], sync', testRedirect, [2, 'pipe'], 3, false, true);78-test('stdio[*] can be process.stdout, sync', testRedirect, 'stdout', 3, false, true);79-test('stdio[*] can be [process.stdout], sync', testRedirect, ['stdout'], 3, false, true);80-test('stdio[*] can be [process.stdout, "pipe"], sync', testRedirect, ['stdout', 'pipe'], 3, false, true);81-test('stdio[*] can be process.stderr, sync', testRedirect, 'stderr', 3, false, true);82-test('stdio[*] can be [process.stderr], sync', testRedirect, ['stderr'], 3, false, true);83-test('stdio[*] can be [process.stderr, "pipe"], sync', testRedirect, ['stderr', 'pipe'], 3, false, true);84-85-const testInheritStdin = async (t, stdioOption, isSync) => {86- const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdioOption), `${isSync}`], {input: foobarString});87- t.is(stdout, `${foobarString}${foobarString}`);88-};89-90-test('stdin can be ["inherit", "pipe"]', testInheritStdin, ['inherit', 'pipe'], false);91-test('stdin can be [0, "pipe"]', testInheritStdin, [0, 'pipe'], false);92-test('stdin can be [process.stdin, "pipe"]', testInheritStdin, ['stdin', 'pipe'], false);93-test.serial('stdin can be ["inherit", "pipe"], sync', testInheritStdin, ['inherit', 'pipe'], true);94-test.serial('stdin can be [0, "pipe"], sync', testInheritStdin, [0, 'pipe'], true);95-test.serial('stdin can be [process.stdin, "pipe"], sync', testInheritStdin, ['stdin', 'pipe'], true);96-97-// eslint-disable-next-line max-params98-const testInheritStdioOutput = async (t, fdNumber, outerFdNumber, stdioOption, isSync, encoding) => {99- const {stdio} = await execa('nested-multiple-stdio-output.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${outerFdNumber}`, `${isSync}`, encoding], fullStdio);100- t.is(stdio[fdNumber], foobarString);101- t.is(stdio[outerFdNumber], `nested ${foobarString}`);102-};103-104-test('stdout can be ["inherit", "pipe"]', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], false, 'utf8');105-test('stdout can be [1, "pipe"]', testInheritStdioOutput, 1, 2, [1, 'pipe'], false, 'utf8');106-test('stdout can be [process.stdout, "pipe"]', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], false, 'utf8');107-test('stderr can be ["inherit", "pipe"]', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], false, 'utf8');108-test('stderr can be [2, "pipe"]', testInheritStdioOutput, 2, 1, [2, 'pipe'], false, 'utf8');109-test('stderr can be [process.stderr, "pipe"]', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], false, 'utf8');110-test('stdout can be ["inherit", "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], false, 'buffer');111-test('stdout can be [1, "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, [1, 'pipe'], false, 'buffer');112-test('stdout can be [process.stdout, "pipe"], encoding "buffer"', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], false, 'buffer');113-test('stderr can be ["inherit", "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], false, 'buffer');114-test('stderr can be [2, "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, [2, 'pipe'], false, 'buffer');115-test('stderr can be [process.stderr, "pipe"], encoding "buffer"', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], false, 'buffer');116-test('stdout can be ["inherit", "pipe"], sync', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], true, 'utf8');117-test('stdout can be [1, "pipe"], sync', testInheritStdioOutput, 1, 2, [1, 'pipe'], true, 'utf8');118-test('stdout can be [process.stdout, "pipe"], sync', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], true, 'utf8');119-test('stderr can be ["inherit", "pipe"], sync', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], true, 'utf8');120-test('stderr can be [2, "pipe"], sync', testInheritStdioOutput, 2, 1, [2, 'pipe'], true, 'utf8');121-test('stderr can be [process.stderr, "pipe"], sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'utf8');122-test('stdio[*] output can be ["inherit", "pipe"], sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'utf8');123-test('stdio[*] output can be [3, "pipe"], sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'utf8');124-test('stdout can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, ['inherit', 'pipe'], true, 'buffer');125-test('stdout can be [1, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, [1, 'pipe'], true, 'buffer');126-test('stdout can be [process.stdout, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 1, 2, ['stdout', 'pipe'], true, 'buffer');127-test('stderr can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['inherit', 'pipe'], true, 'buffer');128-test('stderr can be [2, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, [2, 'pipe'], true, 'buffer');129-test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');130-test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');131-test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');132-133-const testFd3InheritOutput = async (t, stdioOption, execaMethod) => {134- const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio);135- t.is(stdio[3], foobarString);136-};137-138-test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);139-test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);140-test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);141-test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);142-143-const testInheritNoBuffer = async (t, stdioOption, execaMethod) => {144- const filePath = tempfile();145- await execaMethod('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false}, {input: foobarString});146- t.is(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);147- await rm(filePath);148-};149-150-test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaAsync);151-test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], parentExecaAsync);152-test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaSync);153-test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], parentExecaSync);154-155-if (isLinux) {156- const testOverflowStream = async (t, fdNumber, stdioOption, execaMethod) => {157- const {stdout} = await execaMethod('empty.js', getStdio(fdNumber, stdioOption), fullStdio);158- t.is(stdout, '');159- };160-161- test('stdin can use 4+', testOverflowStream, 0, 4, parentExecaAsync);162- test('stdin can use [4+]', testOverflowStream, 0, [4], parentExecaAsync);163- test('stdout can use 4+', testOverflowStream, 1, 4, parentExecaAsync);164- test('stdout can use [4+]', testOverflowStream, 1, [4], parentExecaAsync);165- test('stderr can use 4+', testOverflowStream, 2, 4, parentExecaAsync);166- test('stderr can use [4+]', testOverflowStream, 2, [4], parentExecaAsync);167- test('stdio[*] can use 4+', testOverflowStream, 3, 4, parentExecaAsync);168- test('stdio[*] can use [4+]', testOverflowStream, 3, [4], parentExecaAsync);169- test('stdin can use 4+, sync', testOverflowStream, 0, 4, parentExecaSync);170- test('stdin can use [4+], sync', testOverflowStream, 0, [4], parentExecaSync);171- test('stdout can use 4+, sync', testOverflowStream, 1, 4, parentExecaSync);172- test('stdout can use [4+], sync', testOverflowStream, 1, [4], parentExecaSync);173- test('stderr can use 4+, sync', testOverflowStream, 2, 4, parentExecaSync);174- test('stderr can use [4+], sync', testOverflowStream, 2, [4], parentExecaSync);175- test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, parentExecaSync);176- test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], parentExecaSync);177-}178-179-const testOverflowStreamArray = (t, fdNumber, stdioOption) => {180- t.throws(() => {181- execa('empty.js', getStdio(fdNumber, stdioOption));182- }, {message: /no such standard stream/});183-};184-185-test('stdin cannot use 4+ and another value', testOverflowStreamArray, 0, [4, 'pipe']);186-test('stdout cannot use 4+ and another value', testOverflowStreamArray, 1, [4, 'pipe']);187-test('stderr cannot use 4+ and another value', testOverflowStreamArray, 2, [4, 'pipe']);188-test('stdio[*] cannot use 4+ and another value', testOverflowStreamArray, 3, [4, 'pipe']);189-test('stdio[*] cannot use "inherit" and another value', testOverflowStreamArray, 3, ['inherit', 'pipe']);190-191-const getInvalidFdCode = () => {192- if (isLinux) {193- return 'EINVAL';194- }195-196- return isWindows ? 'EBADF' : 'ENXIO';197-};198-199-const testOverflowStreamArraySync = (t, fdNumber) => {200- t.throws(() => {201- execaSync('noop-fd.js', [fdNumber, foobarString], getStdio(fdNumber, [4, 'pipe']));202- }, {code: getInvalidFdCode()});203-};204-205-test('stdout cannot use 4+ and another value, sync', testOverflowStreamArraySync, 1);206-test('stderr cannot use 4+ and another value, sync', testOverflowStreamArraySync, 2);207-test('stdio[*] cannot use 4+ and another value, sync', testOverflowStreamArraySync, 3);208-209-test('stdin can use ["inherit", "pipe"] in a TTY', async t => {210- const stdioOption = [['inherit', 'pipe'], 'inherit', 'pipe'];211- const {stdout} = await execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'false', 'stdin-fd.js', '0'], {input: foobarString});212- t.is(stdout, foobarString);213-});214-215-const testNoTtyInput = async (t, fdNumber, optionName) => {216- const stdioOption = ['pipe', 'inherit', 'pipe'];217- stdioOption[fdNumber] = [[''], 'inherit', 'pipe'];218- const {message} = await t.throwsAsync(execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'true', 'stdin-fd.js', `${fdNumber}`], fullStdio));219- t.true(message.includes(`The \`${optionName}: 'inherit'\` option is invalid: it cannot be a TTY`));220-};221-222-test('stdin cannot use ["inherit", "pipe"] in a TTY, sync', testNoTtyInput, 0, 'stdin');223-test('stdio[*] input cannot use ["inherit", "pipe"] in a TTY, sync', testNoTtyInput, 3, 'stdio[3]');224-225-const testTtyOutput = async (t, fdNumber, isSync) => {226- const {stdio} = await execa('nested-sync-tty.js', [JSON.stringify(getStdio(fdNumber, ['inherit', 'pipe'])), `${isSync}`, 'noop-fd.js', `${fdNumber}`, foobarString], fullStdio);227- t.is(stdio[fdNumber], foobarString);228-};229-230-test('stdout can use ["inherit", "pipe"] in a TTY', testTtyOutput, 1, false);231-test('stderr can use ["inherit", "pipe"] in a TTY', testTtyOutput, 2, false);232-test('stdout can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 1, true);233-test('stderr can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 2, true);234-test('stdio[*] output can use ["inherit", "pipe"] in a TTY, sync', testTtyOutput, 3, true);added:test/stdio/node-stream-custom.js+158 added
1+import {createReadStream, createWriteStream} from 'node:fs';2+import {readFile, writeFile, rm} from 'node:fs/promises';3+import {Writable, PassThrough} from 'node:stream';4+import {text} from 'node:stream/consumers';5+import {setImmediate} from 'node:timers/promises';6+import {callbackify} from 'node:util';7+import test from 'ava';8+import tempfile from 'tempfile';9+import {execa, execaSync} from '../../index.js';10+import {setFixtureDir} from '../helpers/fixtures-dir.js';11+import {getStdio} from '../helpers/stdio.js';12+import {foobarString} from '../helpers/input.js';13+import {noopReadable, noopWritable} from '../helpers/stream.js';14+15+setFixtureDir();16+17+const testLazyFileReadable = async (t, fdNumber) => {18+ const filePath = tempfile();19+ await writeFile(filePath, 'foobar');20+ const stream = createReadStream(filePath);21+22+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe']));23+ t.is(stdout, 'foobar');24+25+ await rm(filePath);26+};27+28+test('stdin can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 0);29+test('stdio[*] can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 3);30+31+const testLazyFileReadableSync = (t, fdNumber) => {32+ t.throws(() => {33+ execaSync('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [noopReadable(), 'pipe']));34+ }, {message: /cannot both be an array and include a stream/});35+};36+37+test('stdin cannot be [Readable, "pipe"] without a file descriptor, sync', testLazyFileReadableSync, 0);38+test('stdio[*] cannot be [Readable, "pipe"] without a file descriptor, sync', testLazyFileReadableSync, 3);39+40+const testLazyFileWritable = async (t, fdNumber) => {41+ const filePath = tempfile();42+ const stream = createWriteStream(filePath);43+44+ await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, [stream, 'pipe']));45+ t.is(await readFile(filePath, 'utf8'), 'foobar');46+47+ await rm(filePath);48+};49+50+test('stdout can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 1);51+test('stderr can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 2);52+test('stdio[*] can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 3);53+54+const testLazyFileWritableSync = (t, fdNumber) => {55+ t.throws(() => {56+ execaSync('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [noopWritable(), 'pipe']));57+ }, {message: /cannot both be an array and include a stream/});58+};59+60+test('stdout cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 1);61+test('stderr cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 2);62+test('stdio[*] cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 3);63+64+test('Waits for custom streams destroy on subprocess errors', async t => {65+ let waitedForDestroy = false;66+ const stream = new Writable({67+ destroy: callbackify(async error => {68+ await setImmediate();69+ waitedForDestroy = true;70+ return error;71+ }),72+ });73+ const {timedOut} = await t.throwsAsync(execa('forever.js', {stdout: [stream, 'pipe'], timeout: 1}));74+ t.true(timedOut);75+ t.true(waitedForDestroy);76+});77+78+test('Handles custom streams destroy errors on subprocess success', async t => {79+ const cause = new Error('test');80+ const stream = new Writable({81+ destroy(destroyError, done) {82+ done(destroyError ?? cause);83+ },84+ });85+ const error = await t.throwsAsync(execa('empty.js', {stdout: [stream, 'pipe']}));86+ t.is(error.cause, cause);87+});88+89+const testStreamEarlyExit = async (t, stream, streamName) => {90+ await t.throwsAsync(execa('noop.js', {[streamName]: [stream, 'pipe'], uid: -1}));91+ t.true(stream.destroyed);92+};93+94+test('Input streams are canceled on early subprocess exit', testStreamEarlyExit, noopReadable(), 'stdin');95+test('Output streams are canceled on early subprocess exit', testStreamEarlyExit, noopWritable(), 'stdout');96+97+const testInputDuplexStream = async (t, fdNumber) => {98+ const stream = new PassThrough();99+ stream.end(foobarString);100+ const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));101+ t.is(stdout, foobarString);102+};103+104+test('Can pass Duplex streams to stdin', testInputDuplexStream, 0);105+test('Can pass Duplex streams to input stdio[*]', testInputDuplexStream, 3);106+107+const testOutputDuplexStream = async (t, fdNumber) => {108+ const stream = new PassThrough();109+ const [output] = await Promise.all([110+ text(stream),111+ execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe'])),112+ ]);113+ t.is(output, foobarString);114+};115+116+test('Can pass Duplex streams to stdout', testOutputDuplexStream, 1);117+test('Can pass Duplex streams to stderr', testOutputDuplexStream, 2);118+test('Can pass Duplex streams to output stdio[*]', testOutputDuplexStream, 3);119+120+const testInputStreamAbort = async (t, fdNumber) => {121+ const stream = new PassThrough();122+ stream.destroy();123+124+ const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));125+ await subprocess;126+ t.true(subprocess.stdio[fdNumber].writableEnded);127+};128+129+test('subprocess.stdin is ended when an input stream aborts', testInputStreamAbort, 0);130+test('subprocess.stdio[*] is ended when an input stream aborts', testInputStreamAbort, 3);131+132+const testInputStreamError = async (t, fdNumber) => {133+ const stream = new PassThrough();134+ const cause = new Error(foobarString);135+ stream.destroy(cause);136+137+ const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));138+ t.like(await t.throwsAsync(subprocess), {cause});139+ t.true(subprocess.stdio[fdNumber].writableEnded);140+};141+142+test('subprocess.stdin is ended when an input stream errors', testInputStreamError, 0);143+test('subprocess.stdio[*] is ended when an input stream errors', testInputStreamError, 3);144+145+const testOutputStreamError = async (t, fdNumber) => {146+ const stream = new PassThrough();147+ const cause = new Error(foobarString);148+ stream.destroy(cause);149+150+ const subprocess = execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe']));151+ t.like(await t.throwsAsync(subprocess), {cause});152+ t.true(subprocess.stdio[fdNumber].readableAborted);153+ t.is(subprocess.stdio[fdNumber].errored, null);154+};155+156+test('subprocess.stdout is aborted when an output stream errors', testOutputStreamError, 1);157+test('subprocess.stderr is aborted when an output stream errors', testOutputStreamError, 2);158+test('subprocess.stdio[*] is aborted when an output stream errors', testOutputStreamError, 3);added:test/stdio/node-stream-native.js+180 added
1+import {once} from 'node:events';2+import {createReadStream, createWriteStream} from 'node:fs';3+import {readFile, writeFile, rm} from 'node:fs/promises';4+import test from 'ava';5+import tempfile from 'tempfile';6+import {execa, execaSync} from '../../index.js';7+import {setFixtureDir} from '../helpers/fixtures-dir.js';8+import {getStdio} from '../helpers/stdio.js';9+import {foobarString} from '../helpers/input.js';10+import {noopReadable, noopWritable, noopDuplex, simpleReadable} from '../helpers/stream.js';11+12+setFixtureDir();13+14+const testNoFileStreamSync = async (t, fdNumber, stream) => {15+ t.throws(() => {16+ execaSync('empty.js', getStdio(fdNumber, stream));17+ }, {code: 'ERR_INVALID_ARG_VALUE'});18+};19+20+test('stdin cannot be a Node.js Readable without a file descriptor - sync', testNoFileStreamSync, 0, noopReadable());21+test('stdin cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 0, noopDuplex());22+test('stdout cannot be a Node.js Writable without a file descriptor - sync', testNoFileStreamSync, 1, noopWritable());23+test('stdout cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 1, noopDuplex());24+test('stderr cannot be a Node.js Writable without a file descriptor - sync', testNoFileStreamSync, 2, noopWritable());25+test('stderr cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 2, noopDuplex());26+test('stdio[*] cannot be a Node.js Readable without a file descriptor - sync', testNoFileStreamSync, 3, noopReadable());27+test('stdio[*] cannot be a Node.js Writable without a file descriptor - sync', testNoFileStreamSync, 3, noopWritable());28+test('stdio[*] cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 3, noopDuplex());29+30+test('input can be a Node.js Readable without a file descriptor', async t => {31+ const {stdout} = await execa('stdin.js', {input: simpleReadable()});32+ t.is(stdout, foobarString);33+});34+35+test('input cannot be a Node.js Readable without a file descriptor - sync', t => {36+ t.throws(() => {37+ execaSync('empty.js', {input: simpleReadable()});38+ }, {message: 'The `input` option cannot be a Node.js stream with synchronous methods.'});39+});40+41+const testNoFileStream = async (t, fdNumber, stream) => {42+ await t.throwsAsync(execa('empty.js', getStdio(fdNumber, stream)), {code: 'ERR_INVALID_ARG_VALUE'});43+};44+45+test('stdin cannot be a Node.js Readable without a file descriptor', testNoFileStream, 0, noopReadable());46+test('stdin cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 0, noopDuplex());47+test('stdout cannot be a Node.js Writable without a file descriptor', testNoFileStream, 1, noopWritable());48+test('stdout cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 1, noopDuplex());49+test('stderr cannot be a Node.js Writable without a file descriptor', testNoFileStream, 2, noopWritable());50+test('stderr cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 2, noopDuplex());51+test('stdio[*] cannot be a Node.js Readable without a file descriptor', testNoFileStream, 3, noopReadable());52+test('stdio[*] cannot be a Node.js Writable without a file descriptor', testNoFileStream, 3, noopWritable());53+test('stdio[*] cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 3, noopDuplex());54+55+const createFileReadStream = async () => {56+ const filePath = tempfile();57+ await writeFile(filePath, 'foobar');58+ const stream = createReadStream(filePath);59+ await once(stream, 'open');60+ return {stream, filePath};61+};62+63+const createFileWriteStream = async () => {64+ const filePath = tempfile();65+ const stream = createWriteStream(filePath);66+ await once(stream, 'open');67+ return {stream, filePath};68+};69+70+const assertFileStreamError = async (t, subprocess, stream, filePath) => {71+ const cause = new Error('test');72+ stream.destroy(cause);73+74+ const error = await t.throwsAsync(subprocess);75+ t.is(error.cause, cause);76+ t.is(error.exitCode, 0);77+ t.is(error.signal, undefined);78+79+ await rm(filePath);80+};81+82+const testFileReadable = async (t, fdNumber, execaMethod) => {83+ const {stream, filePath} = await createFileReadStream();84+85+ const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;86+ const {stdout} = await execaMethod('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));87+ t.is(stdout, 'foobar');88+89+ await rm(filePath);90+};91+92+test('input can be a Node.js Readable with a file descriptor', testFileReadable, 'input', execa);93+test('stdin can be a Node.js Readable with a file descriptor', testFileReadable, 0, execa);94+test('stdio[*] can be a Node.js Readable with a file descriptor', testFileReadable, 3, execa);95+test('stdin can be a Node.js Readable with a file descriptor - sync', testFileReadable, 0, execaSync);96+test('stdio[*] can be a Node.js Readable with a file descriptor - sync', testFileReadable, 3, execaSync);97+98+const testFileReadableError = async (t, fdNumber) => {99+ const {stream, filePath} = await createFileReadStream();100+101+ const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;102+ const subprocess = execa('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));103+104+ await assertFileStreamError(t, subprocess, stream, filePath);105+};106+107+test.serial('input handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 'input');108+test.serial('stdin handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 0);109+test.serial('stdio[*] handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 3);110+111+const testFileReadableOpen = async (t, fdNumber, useSingle, execaMethod) => {112+ const {stream, filePath} = await createFileReadStream();113+ t.deepEqual(stream.eventNames(), []);114+115+ const stdioOption = useSingle ? stream : [stream, 'pipe'];116+ await execaMethod('empty.js', getStdio(fdNumber, stdioOption));117+118+ t.is(stream.readable, useSingle && fdNumber !== 'input');119+ t.deepEqual(stream.eventNames(), []);120+121+ await rm(filePath);122+};123+124+test('input closes a Node.js Readable with a file descriptor', testFileReadableOpen, 'input', true, execa);125+test('stdin leaves open a single Node.js Readable with a file descriptor', testFileReadableOpen, 0, true, execa);126+test('stdin closes a combined Node.js Readable with a file descriptor', testFileReadableOpen, 0, false, execa);127+test('stdio[*] leaves open a single Node.js Readable with a file descriptor', testFileReadableOpen, 3, true, execa);128+test('stdin leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 0, true, execaSync);129+test('stdio[*] leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 3, true, execaSync);130+131+const testFileWritable = async (t, fdNumber, execaMethod) => {132+ const {stream, filePath} = await createFileWriteStream();133+134+ await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, stream));135+ t.is(await readFile(filePath, 'utf8'), 'foobar');136+137+ await rm(filePath);138+};139+140+test('stdout can be a Node.js Writable with a file descriptor', testFileWritable, 1, execa);141+test('stderr can be a Node.js Writable with a file descriptor', testFileWritable, 2, execa);142+test('stdio[*] can be a Node.js Writable with a file descriptor', testFileWritable, 3, execa);143+test('stdout can be a Node.js Writable with a file descriptor - sync', testFileWritable, 1, execaSync);144+test('stderr can be a Node.js Writable with a file descriptor - sync', testFileWritable, 2, execaSync);145+test('stdio[*] can be a Node.js Writable with a file descriptor - sync', testFileWritable, 3, execaSync);146+147+const testFileWritableError = async (t, fdNumber) => {148+ const {stream, filePath} = await createFileWriteStream();149+150+ const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, stream));151+152+ await assertFileStreamError(t, subprocess, stream, filePath);153+};154+155+test.serial('stdout handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 1);156+test.serial('stderr handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 2);157+test.serial('stdio[*] handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 3);158+159+const testFileWritableOpen = async (t, fdNumber, useSingle, execaMethod) => {160+ const {stream, filePath} = await createFileWriteStream();161+ t.deepEqual(stream.eventNames(), []);162+163+ const stdioOption = useSingle ? stream : [stream, 'pipe'];164+ await execaMethod('empty.js', getStdio(fdNumber, stdioOption));165+166+ t.is(stream.writable, useSingle);167+ t.deepEqual(stream.eventNames(), []);168+169+ await rm(filePath);170+};171+172+test('stdout leaves open a single Node.js Writable with a file descriptor', testFileWritableOpen, 1, true, execa);173+test('stdout closes a combined Node.js Writable with a file descriptor', testFileWritableOpen, 1, false, execa);174+test('stderr leaves open a single Node.js Writable with a file descriptor', testFileWritableOpen, 2, true, execa);175+test('stderr closes a combined Node.js Writable with a file descriptor', testFileWritableOpen, 2, false, execa);176+test('stdio[*] leaves open a single Node.js Writable with a file descriptor', testFileWritableOpen, 3, true, execa);177+test('stdio[*] closes a combined Node.js Writable with a file descriptor', testFileWritableOpen, 3, false, execa);178+test('stdout leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 1, true, execaSync);179+test('stderr leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 2, true, execaSync);180+test('stdio[*] leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 3, true, execaSync);deleted:test/stdio/node-stream.js-327 removed
1-import {once} from 'node:events';2-import {createReadStream, createWriteStream} from 'node:fs';3-import {readFile, writeFile, rm} from 'node:fs/promises';4-import {Writable, PassThrough} from 'node:stream';5-import {text} from 'node:stream/consumers';6-import {setImmediate} from 'node:timers/promises';7-import {callbackify} from 'node:util';8-import test from 'ava';9-import tempfile from 'tempfile';10-import {execa, execaSync} from '../../index.js';11-import {setFixtureDir} from '../helpers/fixtures-dir.js';12-import {getStdio} from '../helpers/stdio.js';13-import {foobarString} from '../helpers/input.js';14-import {noopReadable, noopWritable, noopDuplex, simpleReadable} from '../helpers/stream.js';15-16-setFixtureDir();17-18-const testNoFileStreamSync = async (t, fdNumber, stream) => {19- t.throws(() => {20- execaSync('empty.js', getStdio(fdNumber, stream));21- }, {code: 'ERR_INVALID_ARG_VALUE'});22-};23-24-test('stdin cannot be a Node.js Readable without a file descriptor - sync', testNoFileStreamSync, 0, noopReadable());25-test('stdin cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 0, noopDuplex());26-test('stdout cannot be a Node.js Writable without a file descriptor - sync', testNoFileStreamSync, 1, noopWritable());27-test('stdout cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 1, noopDuplex());28-test('stderr cannot be a Node.js Writable without a file descriptor - sync', testNoFileStreamSync, 2, noopWritable());29-test('stderr cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 2, noopDuplex());30-test('stdio[*] cannot be a Node.js Readable without a file descriptor - sync', testNoFileStreamSync, 3, noopReadable());31-test('stdio[*] cannot be a Node.js Writable without a file descriptor - sync', testNoFileStreamSync, 3, noopWritable());32-test('stdio[*] cannot be a Node.js Duplex without a file descriptor - sync', testNoFileStreamSync, 3, noopDuplex());33-34-test('input can be a Node.js Readable without a file descriptor', async t => {35- const {stdout} = await execa('stdin.js', {input: simpleReadable()});36- t.is(stdout, foobarString);37-});38-39-test('input cannot be a Node.js Readable without a file descriptor - sync', t => {40- t.throws(() => {41- execaSync('empty.js', {input: simpleReadable()});42- }, {message: 'The `input` option cannot be a Node.js stream with synchronous methods.'});43-});44-45-const testNoFileStream = async (t, fdNumber, stream) => {46- await t.throwsAsync(execa('empty.js', getStdio(fdNumber, stream)), {code: 'ERR_INVALID_ARG_VALUE'});47-};48-49-test('stdin cannot be a Node.js Readable without a file descriptor', testNoFileStream, 0, noopReadable());50-test('stdin cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 0, noopDuplex());51-test('stdout cannot be a Node.js Writable without a file descriptor', testNoFileStream, 1, noopWritable());52-test('stdout cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 1, noopDuplex());53-test('stderr cannot be a Node.js Writable without a file descriptor', testNoFileStream, 2, noopWritable());54-test('stderr cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 2, noopDuplex());55-test('stdio[*] cannot be a Node.js Readable without a file descriptor', testNoFileStream, 3, noopReadable());56-test('stdio[*] cannot be a Node.js Writable without a file descriptor', testNoFileStream, 3, noopWritable());57-test('stdio[*] cannot be a Node.js Duplex without a file descriptor', testNoFileStream, 3, noopDuplex());58-59-const createFileReadStream = async () => {60- const filePath = tempfile();61- await writeFile(filePath, 'foobar');62- const stream = createReadStream(filePath);63- await once(stream, 'open');64- return {stream, filePath};65-};66-67-const createFileWriteStream = async () => {68- const filePath = tempfile();69- const stream = createWriteStream(filePath);70- await once(stream, 'open');71- return {stream, filePath};72-};73-74-const assertFileStreamError = async (t, subprocess, stream, filePath) => {75- const cause = new Error('test');76- stream.destroy(cause);77-78- const error = await t.throwsAsync(subprocess);79- t.is(error.cause, cause);80- t.is(error.exitCode, 0);81- t.is(error.signal, undefined);82-83- await rm(filePath);84-};85-86-const testFileReadable = async (t, fdNumber, execaMethod) => {87- const {stream, filePath} = await createFileReadStream();88-89- const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;90- const {stdout} = await execaMethod('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));91- t.is(stdout, 'foobar');92-93- await rm(filePath);94-};95-96-test('input can be a Node.js Readable with a file descriptor', testFileReadable, 'input', execa);97-test('stdin can be a Node.js Readable with a file descriptor', testFileReadable, 0, execa);98-test('stdio[*] can be a Node.js Readable with a file descriptor', testFileReadable, 3, execa);99-test('stdin can be a Node.js Readable with a file descriptor - sync', testFileReadable, 0, execaSync);100-test('stdio[*] can be a Node.js Readable with a file descriptor - sync', testFileReadable, 3, execaSync);101-102-const testFileReadableError = async (t, fdNumber) => {103- const {stream, filePath} = await createFileReadStream();104-105- const fdNumberString = fdNumber === 'input' ? '0' : `${fdNumber}`;106- const subprocess = execa('stdin-fd.js', [fdNumberString], getStdio(fdNumber, stream));107-108- await assertFileStreamError(t, subprocess, stream, filePath);109-};110-111-test.serial('input handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 'input');112-test.serial('stdin handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 0);113-test.serial('stdio[*] handles errors from a Node.js Readable with a file descriptor', testFileReadableError, 3);114-115-const testFileReadableOpen = async (t, fdNumber, useSingle, execaMethod) => {116- const {stream, filePath} = await createFileReadStream();117- t.deepEqual(stream.eventNames(), []);118-119- const stdioOption = useSingle ? stream : [stream, 'pipe'];120- await execaMethod('empty.js', getStdio(fdNumber, stdioOption));121-122- t.is(stream.readable, useSingle && fdNumber !== 'input');123- t.deepEqual(stream.eventNames(), []);124-125- await rm(filePath);126-};127-128-test('input closes a Node.js Readable with a file descriptor', testFileReadableOpen, 'input', true, execa);129-test('stdin leaves open a single Node.js Readable with a file descriptor', testFileReadableOpen, 0, true, execa);130-test('stdin closes a combined Node.js Readable with a file descriptor', testFileReadableOpen, 0, false, execa);131-test('stdio[*] leaves open a single Node.js Readable with a file descriptor', testFileReadableOpen, 3, true, execa);132-test('stdin leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 0, true, execaSync);133-test('stdio[*] leaves open a single Node.js Readable with a file descriptor - sync', testFileReadableOpen, 3, true, execaSync);134-135-const testFileWritable = async (t, fdNumber, execaMethod) => {136- const {stream, filePath} = await createFileWriteStream();137-138- await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, stream));139- t.is(await readFile(filePath, 'utf8'), 'foobar');140-141- await rm(filePath);142-};143-144-test('stdout can be a Node.js Writable with a file descriptor', testFileWritable, 1, execa);145-test('stderr can be a Node.js Writable with a file descriptor', testFileWritable, 2, execa);146-test('stdio[*] can be a Node.js Writable with a file descriptor', testFileWritable, 3, execa);147-test('stdout can be a Node.js Writable with a file descriptor - sync', testFileWritable, 1, execaSync);148-test('stderr can be a Node.js Writable with a file descriptor - sync', testFileWritable, 2, execaSync);149-test('stdio[*] can be a Node.js Writable with a file descriptor - sync', testFileWritable, 3, execaSync);150-151-const testFileWritableError = async (t, fdNumber) => {152- const {stream, filePath} = await createFileWriteStream();153-154- const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, stream));155-156- await assertFileStreamError(t, subprocess, stream, filePath);157-};158-159-test.serial('stdout handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 1);160-test.serial('stderr handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 2);161-test.serial('stdio[*] handles errors from a Node.js Writable with a file descriptor', testFileWritableError, 3);162-163-const testFileWritableOpen = async (t, fdNumber, useSingle, execaMethod) => {164- const {stream, filePath} = await createFileWriteStream();165- t.deepEqual(stream.eventNames(), []);166-167- const stdioOption = useSingle ? stream : [stream, 'pipe'];168- await execaMethod('empty.js', getStdio(fdNumber, stdioOption));169-170- t.is(stream.writable, useSingle);171- t.deepEqual(stream.eventNames(), []);172-173- await rm(filePath);174-};175-176-test('stdout leaves open a single Node.js Writable with a file descriptor', testFileWritableOpen, 1, true, execa);177-test('stdout closes a combined Node.js Writable with a file descriptor', testFileWritableOpen, 1, false, execa);178-test('stderr leaves open a single Node.js Writable with a file descriptor', testFileWritableOpen, 2, true, execa);179-test('stderr closes a combined Node.js Writable with a file descriptor', testFileWritableOpen, 2, false, execa);180-test('stdio[*] leaves open a single Node.js Writable with a file descriptor', testFileWritableOpen, 3, true, execa);181-test('stdio[*] closes a combined Node.js Writable with a file descriptor', testFileWritableOpen, 3, false, execa);182-test('stdout leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 1, true, execaSync);183-test('stderr leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 2, true, execaSync);184-test('stdio[*] leaves open a single Node.js Writable with a file descriptor - sync', testFileWritableOpen, 3, true, execaSync);185-186-const testLazyFileReadable = async (t, fdNumber) => {187- const filePath = tempfile();188- await writeFile(filePath, 'foobar');189- const stream = createReadStream(filePath);190-191- const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe']));192- t.is(stdout, 'foobar');193-194- await rm(filePath);195-};196-197-test('stdin can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 0);198-test('stdio[*] can be [Readable, "pipe"] without a file descriptor', testLazyFileReadable, 3);199-200-const testLazyFileReadableSync = (t, fdNumber) => {201- t.throws(() => {202- execaSync('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [noopReadable(), 'pipe']));203- }, {message: /cannot both be an array and include a stream/});204-};205-206-test('stdin cannot be [Readable, "pipe"] without a file descriptor, sync', testLazyFileReadableSync, 0);207-test('stdio[*] cannot be [Readable, "pipe"] without a file descriptor, sync', testLazyFileReadableSync, 3);208-209-const testLazyFileWritable = async (t, fdNumber) => {210- const filePath = tempfile();211- const stream = createWriteStream(filePath);212-213- await execa('noop-fd.js', [`${fdNumber}`, 'foobar'], getStdio(fdNumber, [stream, 'pipe']));214- t.is(await readFile(filePath, 'utf8'), 'foobar');215-216- await rm(filePath);217-};218-219-test('stdout can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 1);220-test('stderr can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 2);221-test('stdio[*] can be [Writable, "pipe"] without a file descriptor', testLazyFileWritable, 3);222-223-const testLazyFileWritableSync = (t, fdNumber) => {224- t.throws(() => {225- execaSync('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [noopWritable(), 'pipe']));226- }, {message: /cannot both be an array and include a stream/});227-};228-229-test('stdout cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 1);230-test('stderr cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 2);231-test('stdio[*] cannot be [Writable, "pipe"] without a file descriptor, sync', testLazyFileWritableSync, 3);232-233-test('Waits for custom streams destroy on subprocess errors', async t => {234- let waitedForDestroy = false;235- const stream = new Writable({236- destroy: callbackify(async error => {237- await setImmediate();238- waitedForDestroy = true;239- return error;240- }),241- });242- const {timedOut} = await t.throwsAsync(execa('forever.js', {stdout: [stream, 'pipe'], timeout: 1}));243- t.true(timedOut);244- t.true(waitedForDestroy);245-});246-247-test('Handles custom streams destroy errors on subprocess success', async t => {248- const cause = new Error('test');249- const stream = new Writable({250- destroy(destroyError, done) {251- done(destroyError ?? cause);252- },253- });254- const error = await t.throwsAsync(execa('empty.js', {stdout: [stream, 'pipe']}));255- t.is(error.cause, cause);256-});257-258-const testStreamEarlyExit = async (t, stream, streamName) => {259- await t.throwsAsync(execa('noop.js', {[streamName]: [stream, 'pipe'], uid: -1}));260- t.true(stream.destroyed);261-};262-263-test('Input streams are canceled on early subprocess exit', testStreamEarlyExit, noopReadable(), 'stdin');264-test('Output streams are canceled on early subprocess exit', testStreamEarlyExit, noopWritable(), 'stdout');265-266-const testInputDuplexStream = async (t, fdNumber) => {267- const stream = new PassThrough();268- stream.end(foobarString);269- const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));270- t.is(stdout, foobarString);271-};272-273-test('Can pass Duplex streams to stdin', testInputDuplexStream, 0);274-test('Can pass Duplex streams to input stdio[*]', testInputDuplexStream, 3);275-276-const testOutputDuplexStream = async (t, fdNumber) => {277- const stream = new PassThrough();278- const [output] = await Promise.all([279- text(stream),280- execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe'])),281- ]);282- t.is(output, foobarString);283-};284-285-test('Can pass Duplex streams to stdout', testOutputDuplexStream, 1);286-test('Can pass Duplex streams to stderr', testOutputDuplexStream, 2);287-test('Can pass Duplex streams to output stdio[*]', testOutputDuplexStream, 3);288-289-const testInputStreamAbort = async (t, fdNumber) => {290- const stream = new PassThrough();291- stream.destroy();292-293- const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));294- await subprocess;295- t.true(subprocess.stdio[fdNumber].writableEnded);296-};297-298-test('subprocess.stdin is ended when an input stream aborts', testInputStreamAbort, 0);299-test('subprocess.stdio[*] is ended when an input stream aborts', testInputStreamAbort, 3);300-301-const testInputStreamError = async (t, fdNumber) => {302- const stream = new PassThrough();303- const cause = new Error(foobarString);304- stream.destroy(cause);305-306- const subprocess = execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, new Uint8Array()]));307- t.like(await t.throwsAsync(subprocess), {cause});308- t.true(subprocess.stdio[fdNumber].writableEnded);309-};310-311-test('subprocess.stdin is ended when an input stream errors', testInputStreamError, 0);312-test('subprocess.stdio[*] is ended when an input stream errors', testInputStreamError, 3);313-314-const testOutputStreamError = async (t, fdNumber) => {315- const stream = new PassThrough();316- const cause = new Error(foobarString);317- stream.destroy(cause);318-319- const subprocess = execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, [stream, 'pipe']));320- t.like(await t.throwsAsync(subprocess), {cause});321- t.true(subprocess.stdio[fdNumber].readableAborted);322- t.is(subprocess.stdio[fdNumber].errored, null);323-};324-325-test('subprocess.stdout is aborted when an output stream errors', testOutputStreamError, 1);326-test('subprocess.stderr is aborted when an output stream errors', testOutputStreamError, 2);327-test('subprocess.stdio[*] is aborted when an output stream errors', testOutputStreamError, 3);added:test/stdio/normalize-transform.js+55 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString, foobarUppercase, foobarUint8Array} from '../helpers/input.js';5+import {casedSuffix} from '../helpers/generator.js';6+import {generatorsMap} from '../helpers/map.js';7+8+setFixtureDir();9+10+const testAppendInput = async (t, reversed, type, execaMethod) => {11+ const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];12+ const reversedStdin = reversed ? stdin.reverse() : stdin;13+ const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: reversedStdin});14+ const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;15+ t.is(stdout, `${foobarUppercase}${reversedSuffix}`);16+};17+18+test('Can use multiple generators as input', testAppendInput, false, 'generator', execa);19+test('Can use multiple generators as input, reversed', testAppendInput, true, 'generator', execa);20+test('Can use multiple generators as input, sync', testAppendInput, false, 'generator', execaSync);21+test('Can use multiple generators as input, reversed, sync', testAppendInput, true, 'generator', execaSync);22+test('Can use multiple duplexes as input', testAppendInput, false, 'duplex', execa);23+test('Can use multiple duplexes as input, reversed', testAppendInput, true, 'duplex', execa);24+test('Can use multiple webTransforms as input', testAppendInput, false, 'webTransform', execa);25+test('Can use multiple webTransforms as input, reversed', testAppendInput, true, 'webTransform', execa);26+27+const testAppendOutput = async (t, reversed, type, execaMethod) => {28+ const stdoutOption = [generatorsMap[type].uppercase(), generatorsMap[type].append()];29+ const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;30+ const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: reversedStdoutOption});31+ const reversedSuffix = reversed ? casedSuffix.toUpperCase() : casedSuffix;32+ t.is(stdout, `${foobarUppercase}${reversedSuffix}`);33+};34+35+test('Can use multiple generators as output', testAppendOutput, false, 'generator', execa);36+test('Can use multiple generators as output, reversed', testAppendOutput, true, 'generator', execa);37+test('Can use multiple generators as output, sync', testAppendOutput, false, 'generator', execaSync);38+test('Can use multiple generators as output, reversed, sync', testAppendOutput, true, 'generator', execaSync);39+test('Can use multiple duplexes as output', testAppendOutput, false, 'duplex', execa);40+test('Can use multiple duplexes as output, reversed', testAppendOutput, true, 'duplex', execa);41+test('Can use multiple webTransforms as output', testAppendOutput, false, 'webTransform', execa);42+test('Can use multiple webTransforms as output, reversed', testAppendOutput, true, 'webTransform', execa);43+44+const testGeneratorSyntax = async (t, type, usePlainObject, execaMethod) => {45+ const transform = generatorsMap[type].uppercase();46+ const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: usePlainObject ? transform : transform.transform});47+ t.is(stdout, foobarUppercase);48+};49+50+test('Can pass generators with an options plain object', testGeneratorSyntax, 'generator', false, execa);51+test('Can pass generators without an options plain object', testGeneratorSyntax, 'generator', true, execa);52+test('Can pass generators with an options plain object, sync', testGeneratorSyntax, 'generator', false, execaSync);53+test('Can pass generators without an options plain object, sync', testGeneratorSyntax, 'generator', true, execaSync);54+test('Can pass webTransforms with an options plain object', testGeneratorSyntax, 'webTransform', true, execa);55+test('Can pass webTransforms without an options plain object', testGeneratorSyntax, 'webTransform', false, execa);added:test/stdio/output-async.js+84 added
1+import {once, defaultMaxListeners} from 'node:events';2+import process from 'node:process';3+import {setImmediate} from 'node:timers/promises';4+import test from 'ava';5+import {execa} from '../../index.js';6+import {STANDARD_STREAMS} from '../helpers/stdio.js';7+import {foobarString} from '../helpers/input.js';8+import {setFixtureDir} from '../helpers/fixtures-dir.js';9+import {assertMaxListeners} from '../helpers/listeners.js';10+11+setFixtureDir();12+13+const getStandardStreamListeners = stream => Object.fromEntries(stream.eventNames().map(eventName => [eventName, stream.listeners(eventName)]));14+const getStandardStreamsListeners = () => STANDARD_STREAMS.map(stream => getStandardStreamListeners(stream));15+16+const getComplexStdio = isMultiple => ({17+ stdin: ['pipe', 'inherit', ...(isMultiple ? [0, process.stdin] : [])],18+ stdout: ['pipe', 'inherit', ...(isMultiple ? [1, process.stdout] : [])],19+ stderr: ['pipe', 'inherit', ...(isMultiple ? [2, process.stderr] : [])],20+});21+22+const onStdinRemoveListener = () => once(process.stdin, 'removeListener');23+24+const testListenersCleanup = async (t, isMultiple) => {25+ const streamsPreviousListeners = getStandardStreamsListeners();26+ const subprocess = execa('empty.js', getComplexStdio(isMultiple));27+ t.notDeepEqual(getStandardStreamsListeners(), streamsPreviousListeners);28+ await Promise.all([subprocess, onStdinRemoveListener()]);29+ if (isMultiple) {30+ await onStdinRemoveListener();31+ }32+33+ for (const [fdNumber, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {34+ const defaultListeners = Object.fromEntries(Reflect.ownKeys(streamNewListeners).map(eventName => [eventName, []]));35+ t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[fdNumber]});36+ }37+};38+39+test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);40+test.serial('process.std* listeners are cleaned up on success with multiple inputs', testListenersCleanup, true);41+42+const subprocessesCount = 100;43+44+test.serial('Can spawn many subprocesses in parallel', async t => {45+ const results = await Promise.all(46+ Array.from({length: subprocessesCount}, () => execa('noop.js', [foobarString])),47+ );48+ t.true(results.every(({stdout}) => stdout === foobarString));49+});50+51+const testMaxListeners = async (t, isMultiple, maxListenersCount) => {52+ const checkMaxListeners = assertMaxListeners(t);53+54+ for (const standardStream of STANDARD_STREAMS) {55+ standardStream.setMaxListeners(maxListenersCount);56+ }57+58+ try {59+ const results = await Promise.all(60+ Array.from({length: subprocessesCount}, () => execa('empty.js', getComplexStdio(isMultiple))),61+ );62+ t.true(results.every(({exitCode}) => exitCode === 0));63+ } finally {64+ await setImmediate();65+ await setImmediate();66+ checkMaxListeners();67+68+ for (const standardStream of STANDARD_STREAMS) {69+ t.is(standardStream.getMaxListeners(), maxListenersCount);70+ standardStream.setMaxListeners(defaultMaxListeners);71+ }72+ }73+};74+75+test.serial('No warning with maxListeners 1 and ["pipe", "inherit"]', testMaxListeners, false, 1);76+test.serial('No warning with maxListeners default and ["pipe", "inherit"]', testMaxListeners, false, defaultMaxListeners);77+test.serial('No warning with maxListeners 100 and ["pipe", "inherit"]', testMaxListeners, false, 100);78+test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"]', testMaxListeners, false, Number.POSITIVE_INFINITY);79+test.serial('No warning with maxListeners 0 and ["pipe", "inherit"]', testMaxListeners, false, 0);80+test.serial('No warning with maxListeners 1 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 1);81+test.serial('No warning with maxListeners default and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, defaultMaxListeners);82+test.serial('No warning with maxListeners 100 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 100);83+test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, Number.POSITIVE_INFINITY);84+test.serial('No warning with maxListeners 0 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 0);added:test/stdio/split-binary.js+95 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';5+import {6+ simpleFull,7+ simpleChunks,8+ simpleFullUint8Array,9+ simpleFullUtf16Inverted,10+ simpleFullUtf16Uint8Array,11+ simpleChunksUint8Array,12+ simpleFullEnd,13+ simpleFullEndUtf16Inverted,14+ simpleFullHex,15+ simpleLines,16+ noNewlinesChunks,17+} from '../helpers/lines.js';18+19+setFixtureDir();20+21+// eslint-disable-next-line max-params22+const testBinaryOption = async (t, binary, input, expectedLines, expectedOutput, objectMode, preserveNewlines, encoding, execaMethod) => {23+ const lines = [];24+ const {stdout} = await execaMethod('noop.js', {25+ stdout: [26+ getOutputsGenerator(input)(false, true),27+ resultGenerator(lines)(objectMode, binary, preserveNewlines),28+ ],29+ stripFinalNewline: false,30+ encoding,31+ });32+ t.deepEqual(lines, expectedLines);33+ t.deepEqual(stdout, expectedOutput);34+};35+36+test('Does not split lines when "binary" is true', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true, 'utf8', execa);37+test('Splits lines when "binary" is false', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execa);38+test('Splits lines when "binary" is undefined', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execa);39+test('Does not split lines when "binary" is true, encoding "utf16le"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, true, 'utf16le', execa);40+test('Splits lines when "binary" is false, encoding "utf16le"', testBinaryOption, false, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execa);41+test('Splits lines when "binary" is undefined, encoding "utf16le"', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execa);42+test('Does not split lines when "binary" is true, encoding "buffer"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);43+test('Does not split lines when "binary" is undefined, encoding "buffer"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);44+test('Does not split lines when "binary" is false, encoding "buffer"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);45+test('Does not split lines when "binary" is true, encoding "hex"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);46+test('Does not split lines when "binary" is undefined, encoding "hex"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);47+test('Does not split lines when "binary" is false, encoding "hex"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);48+test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true, 'utf8', execa);49+test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execa);50+test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execa);51+test('Does not split lines when "binary" is true, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false, 'utf8', execa);52+test('Splits lines when "binary" is false, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execa);53+test('Splits lines when "binary" is undefined, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execa);54+test('Does not split lines when "binary" is true, preserveNewlines, encoding "utf16le"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, false, 'utf16le', execa);55+test('Splits lines when "binary" is false, preserveNewlines, encoding "utf16le"', testBinaryOption, false, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execa);56+test('Splits lines when "binary" is undefined, preserveNewlines, encoding "utf16le"', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execa);57+test('Does not split lines when "binary" is true, encoding "buffer", preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);58+test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);59+test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);60+test('Does not split lines when "binary" is true, objectMode, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false, 'utf8', execa);61+test('Does not split lines when "binary" is true, encoding "hex", preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);62+test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);63+test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);64+test('Splits lines when "binary" is false, objectMode, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execa);65+test('Splits lines when "binary" is undefined, objectMode, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execa);66+test('Does not split lines when "binary" is true, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true, 'utf8', execaSync);67+test('Splits lines when "binary" is false, sync', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execaSync);68+test('Splits lines when "binary" is undefined, sync', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execaSync);69+test('Does not split lines when "binary" is true, encoding "utf16le", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, true, 'utf16le', execaSync);70+test('Splits lines when "binary" is false, encoding "utf16le", sync', testBinaryOption, false, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execaSync);71+test('Splits lines when "binary" is undefined, encoding "utf16le", sync', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execaSync);72+test('Does not split lines when "binary" is true, encoding "buffer", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);73+test('Does not split lines when "binary" is undefined, encoding "buffer", sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);74+test('Does not split lines when "binary" is false, encoding "buffer", sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);75+test('Does not split lines when "binary" is true, encoding "hex", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);76+test('Does not split lines when "binary" is undefined, encoding "hex", sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);77+test('Does not split lines when "binary" is false, encoding "hex", sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);78+test('Does not split lines when "binary" is true, objectMode, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true, 'utf8', execaSync);79+test('Splits lines when "binary" is false, objectMode, sync', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execaSync);80+test('Splits lines when "binary" is undefined, objectMode, sync', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execaSync);81+test('Does not split lines when "binary" is true, preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false, 'utf8', execaSync);82+test('Splits lines when "binary" is false, preserveNewlines, sync', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execaSync);83+test('Splits lines when "binary" is undefined, preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execaSync);84+test('Does not split lines when "binary" is true, preserveNewlines, encoding "utf16le", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, false, 'utf16le', execaSync);85+test('Splits lines when "binary" is false, preserveNewlines, encoding "utf16le", sync', testBinaryOption, false, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execaSync);86+test('Splits lines when "binary" is undefined, preserveNewlines, encoding "utf16le", sync', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execaSync);87+test('Does not split lines when "binary" is true, encoding "buffer", preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);88+test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);89+test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines, sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);90+test('Does not split lines when "binary" is true, objectMode, preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false, 'utf8', execaSync);91+test('Does not split lines when "binary" is true, encoding "hex", preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);92+test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);93+test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines, sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);94+test('Splits lines when "binary" is false, objectMode, preserveNewlines, sync', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execaSync);95+test('Splits lines when "binary" is undefined, objectMode, preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execaSync);added:test/stdio/split-lines.js+174 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {getStdio} from '../helpers/stdio.js';5+import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';6+import {7+ singleFull,8+ singleFullEnd,9+ simpleFull,10+ simpleChunks,11+ simpleFullEnd,12+ simpleFullEndChunks,13+ simpleLines,14+ simpleFullEndLines,15+ noNewlinesFull,16+ noNewlinesChunks,17+} from '../helpers/lines.js';18+19+setFixtureDir();20+21+const windowsFull = 'aaa\r\nbbb\r\nccc';22+const windowsFullEnd = `${windowsFull}\r\n`;23+const windowsChunks = [windowsFull];24+const windowsLines = ['aaa\r\n', 'bbb\r\n', 'ccc'];25+const noNewlinesFullEnd = `${noNewlinesFull}\n`;26+const noNewlinesLines = ['aaabbbccc'];27+const singleChunks = [singleFull];28+const noLines = [];29+const emptyFull = '';30+const emptyChunks = [emptyFull];31+const manyEmptyChunks = [emptyFull, emptyFull, emptyFull];32+const newlineFull = '\n';33+const newlineChunks = [newlineFull];34+const newlinesFull = '\n\n\n';35+const newlinesChunks = [newlinesFull];36+const newlinesLines = ['\n', '\n', '\n'];37+const windowsNewlinesFull = '\r\n\r\n\r\n';38+const windowsNewlinesChunks = [windowsNewlinesFull];39+const windowsNewlinesLines = ['\r\n', '\r\n', '\r\n'];40+const runOverChunks = ['aaa\nb', 'b', 'b\nccc'];41+const bigFull = '.'.repeat(1e5);42+const bigFullEnd = `${bigFull}\n`;43+const bigChunks = [bigFull];44+const manyChunks = Array.from({length: 1e3}).fill('.');45+const manyFull = manyChunks.join('');46+const manyFullEnd = `${manyFull}\n`;47+const manyLines = [manyFull];48+49+// eslint-disable-next-line max-params50+const testLines = async (t, fdNumber, input, expectedLines, expectedOutput, objectMode, preserveNewlines, execaMethod) => {51+ const lines = [];52+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`], {53+ ...getStdio(fdNumber, [54+ getOutputsGenerator(input)(false, true),55+ resultGenerator(lines)(objectMode, false, preserveNewlines),56+ ]),57+ stripFinalNewline: false,58+ });59+ t.deepEqual(lines, expectedLines);60+ t.deepEqual(stdio[fdNumber], expectedOutput);61+};62+63+test('Split stdout - n newlines, 1 chunk', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true, execa);64+test('Split stderr - n newlines, 1 chunk', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true, execa);65+test('Split stdio[*] - n newlines, 1 chunk', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true, execa);66+test('Split stdout - preserveNewlines, n chunks', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true, execa);67+test('Split stdout - 0 newlines, 1 chunk', testLines, 1, singleChunks, singleChunks, singleFull, false, true, execa);68+test('Split stdout - empty, 1 chunk', testLines, 1, emptyChunks, noLines, emptyFull, false, true, execa);69+test('Split stdout - Windows newlines', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true, execa);70+test('Split stdout - chunk ends with newline', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true, execa);71+test('Split stdout - single newline', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true, execa);72+test('Split stdout - only newlines', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true, execa);73+test('Split stdout - only Windows newlines', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true, execa);74+test('Split stdout - line split over multiple chunks', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true, execa);75+test('Split stdout - 0 newlines, big line', testLines, 1, bigChunks, bigChunks, bigFull, false, true, execa);76+test('Split stdout - 0 newlines, many chunks', testLines, 1, manyChunks, manyLines, manyFull, false, true, execa);77+test('Split stdout - n newlines, 1 chunk, objectMode', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true, execa);78+test('Split stderr - n newlines, 1 chunk, objectMode', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true, execa);79+test('Split stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true, execa);80+test('Split stdout - preserveNewlines, n chunks, objectMode', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true, execa);81+test('Split stdout - empty, 1 chunk, objectMode', testLines, 1, emptyChunks, noLines, noLines, true, true, execa);82+test('Split stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, singleChunks, singleChunks, singleChunks, true, true, execa);83+test('Split stdout - Windows newlines, objectMode', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true, execa);84+test('Split stdout - chunk ends with newline, objectMode', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true, execa);85+test('Split stdout - single newline, objectMode', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true, execa);86+test('Split stdout - only newlines, objectMode', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true, execa);87+test('Split stdout - only Windows newlines, objectMode', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true, execa);88+test('Split stdout - line split over multiple chunks, objectMode', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true, execa);89+test('Split stdout - 0 newlines, big line, objectMode', testLines, 1, bigChunks, bigChunks, bigChunks, true, true, execa);90+test('Split stdout - 0 newlines, many chunks, objectMode', testLines, 1, manyChunks, manyLines, manyLines, true, true, execa);91+test('Split stdout - n newlines, 1 chunk, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);92+test('Split stderr - n newlines, 1 chunk, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);93+test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);94+test('Split stdout - preserveNewlines, n chunks, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false, execa);95+test('Split stdout - empty, 1 chunk, preserveNewlines', testLines, 1, emptyChunks, noLines, emptyFull, false, false, execa);96+test('Split stdout - 0 newlines, 1 chunk, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false, execa);97+test('Split stdout - Windows newlines, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false, execa);98+test('Split stdout - chunk ends with newline, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);99+test('Split stdout - single newline, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false, execa);100+test('Split stdout - only newlines, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false, execa);101+test('Split stdout - only Windows newlines, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false, execa);102+test('Split stdout - line split over multiple chunks, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);103+test('Split stdout - 0 newlines, big line, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false, execa);104+test('Split stdout - 0 newlines, many chunks, preserveNewlines', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false, execa);105+test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);106+test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);107+test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);108+test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false, execa);109+test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines', testLines, 1, emptyChunks, noLines, noLines, true, false, execa);110+test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleChunks, true, false, execa);111+test('Split stdout - Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);112+test('Split stdout - chunk ends with newline, objectMode, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);113+test('Split stdout - single newline, objectMode, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false, execa);114+test('Split stdout - only newlines, objectMode, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execa);115+test('Split stdout - only Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execa);116+test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);117+test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigChunks, true, false, execa);118+test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines', testLines, 1, manyChunks, manyLines, manyLines, true, false, execa);119+test('Split stdout - n newlines, 1 chunk, sync', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true, execaSync);120+test('Split stderr - n newlines, 1 chunk, sync', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true, execaSync);121+test('Split stdio[*] - n newlines, 1 chunk, sync', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true, execaSync);122+test('Split stdout - preserveNewlines, n chunks, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true, execaSync);123+test('Split stdout - 0 newlines, 1 chunk, sync', testLines, 1, singleChunks, singleChunks, singleFull, false, true, execaSync);124+test('Split stdout - empty, 1 chunk, sync', testLines, 1, emptyChunks, noLines, emptyFull, false, true, execaSync);125+test('Split stdout - Windows newlines, sync', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true, execaSync);126+test('Split stdout - chunk ends with newline, sync', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true, execaSync);127+test('Split stdout - single newline, sync', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true, execaSync);128+test('Split stdout - only newlines, sync', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true, execaSync);129+test('Split stdout - only Windows newlines, sync', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true, execaSync);130+test('Split stdout - line split over multiple chunks, sync', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true, execaSync);131+test('Split stdout - 0 newlines, big line, sync', testLines, 1, bigChunks, bigChunks, bigFull, false, true, execaSync);132+test('Split stdout - 0 newlines, many chunks, sync', testLines, 1, manyChunks, manyLines, manyFull, false, true, execaSync);133+test('Split stdout - n newlines, 1 chunk, objectMode, sync', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true, execaSync);134+test('Split stderr - n newlines, 1 chunk, objectMode, sync', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true, execaSync);135+test('Split stdio[*] - n newlines, 1 chunk, objectMode, sync', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true, execaSync);136+test('Split stdout - preserveNewlines, n chunks, objectMode, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true, execaSync);137+test('Split stdout - empty, 1 chunk, objectMode, sync', testLines, 1, emptyChunks, noLines, noLines, true, true, execaSync);138+test('Split stdout - 0 newlines, 1 chunk, objectMode, sync', testLines, 1, singleChunks, singleChunks, singleChunks, true, true, execaSync);139+test('Split stdout - Windows newlines, objectMode, sync', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true, execaSync);140+test('Split stdout - chunk ends with newline, objectMode, sync', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true, execaSync);141+test('Split stdout - single newline, objectMode, sync', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true, execaSync);142+test('Split stdout - only newlines, objectMode, sync', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true, execaSync);143+test('Split stdout - only Windows newlines, objectMode, sync', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true, execaSync);144+test('Split stdout - line split over multiple chunks, objectMode, sync', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true, execaSync);145+test('Split stdout - 0 newlines, big line, objectMode, sync', testLines, 1, bigChunks, bigChunks, bigChunks, true, true, execaSync);146+test('Split stdout - 0 newlines, many chunks, objectMode, sync', testLines, 1, manyChunks, manyLines, manyLines, true, true, execaSync);147+test('Split stdout - n newlines, 1 chunk, preserveNewlines, sync', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);148+test('Split stderr - n newlines, 1 chunk, preserveNewlines, sync', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);149+test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines, sync', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);150+test('Split stdout - preserveNewlines, n chunks, preserveNewlines, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false, execaSync);151+test('Split stdout - empty, 1 chunk, preserveNewlines, sync', testLines, 1, emptyChunks, noLines, emptyFull, false, false, execaSync);152+test('Split stdout - 0 newlines, 1 chunk, preserveNewlines, sync', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false, execaSync);153+test('Split stdout - Windows newlines, preserveNewlines, sync', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false, execaSync);154+test('Split stdout - chunk ends with newline, preserveNewlines, sync', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);155+test('Split stdout - single newline, preserveNewlines, sync', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false, execaSync);156+test('Split stdout - only newlines, preserveNewlines, sync', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false, execaSync);157+test('Split stdout - only Windows newlines, preserveNewlines, sync', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false, execaSync);158+test('Split stdout - line split over multiple chunks, preserveNewlines, sync', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);159+test('Split stdout - 0 newlines, big line, preserveNewlines, sync', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false, execaSync);160+test('Split stdout - 0 newlines, many chunks, preserveNewlines, sync', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false, execaSync);161+test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);162+test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);163+test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);164+test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false, execaSync);165+test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, emptyChunks, noLines, noLines, true, false, execaSync);166+test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, singleChunks, singleChunks, singleChunks, true, false, execaSync);167+test('Split stdout - Windows newlines, objectMode, preserveNewlines, sync', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);168+test('Split stdout - chunk ends with newline, objectMode, preserveNewlines, sync', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);169+test('Split stdout - single newline, objectMode, preserveNewlines, sync', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false, execaSync);170+test('Split stdout - only newlines, objectMode, preserveNewlines, sync', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execaSync);171+test('Split stdout - only Windows newlines, objectMode, preserveNewlines, sync', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execaSync);172+test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines, sync', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);173+test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines, sync', testLines, 1, bigChunks, bigChunks, bigChunks, true, false, execaSync);174+test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines, sync', testLines, 1, manyChunks, manyLines, manyLines, true, false, execaSync);added:test/stdio/split-newline.js+37 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {getOutputsGenerator, noopGenerator, noopAsyncGenerator} from '../helpers/generator.js';5+import {singleFull, singleFullEnd} from '../helpers/lines.js';6+7+setFixtureDir();8+9+const singleFullEndWindows = `${singleFull}\r\n`;10+const mixedNewlines = '.\n.\r\n.\n.\r\n.\n';11+12+const testStripNewline = async (t, input, expectedOutput, execaMethod) => {13+ const {stdout} = await execaMethod('noop.js', {14+ stdout: getOutputsGenerator([input])(),15+ stripFinalNewline: false,16+ });17+ t.is(stdout, expectedOutput);18+};19+20+test('Strips newline when user do not mistakenly yield one at the end', testStripNewline, singleFull, singleFullEnd, execa);21+test('Strips newline when user mistakenly yielded one at the end', testStripNewline, singleFullEnd, singleFullEnd, execa);22+test('Strips newline when user mistakenly yielded one at the end, Windows newline', testStripNewline, singleFullEndWindows, singleFullEndWindows, execa);23+test('Strips newline when user do not mistakenly yield one at the end, sync', testStripNewline, singleFull, singleFullEnd, execaSync);24+test('Strips newline when user mistakenly yielded one at the end, sync', testStripNewline, singleFullEnd, singleFullEnd, execaSync);25+test('Strips newline when user mistakenly yielded one at the end, Windows newline, sync', testStripNewline, singleFullEndWindows, singleFullEndWindows, execaSync);26+27+const testMixNewlines = async (t, generator, execaMethod) => {28+ const {stdout} = await execaMethod('noop-fd.js', ['1', mixedNewlines], {29+ stdout: generator(),30+ stripFinalNewline: false,31+ });32+ t.is(stdout, mixedNewlines);33+};34+35+test('Can mix Unix and Windows newlines', testMixNewlines, noopGenerator, execa);36+test('Can mix Unix and Windows newlines, sync', testMixNewlines, noopGenerator, execaSync);37+test('Can mix Unix and Windows newlines, async', testMixNewlines, noopAsyncGenerator, execa);added:test/stdio/split-transform.js+78 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';5+import {foobarString, foobarUint8Array, foobarObject, foobarObjectString} from '../helpers/input.js';6+7+setFixtureDir();8+9+const resultUint8ArrayGenerator = function * (lines, chunk) {10+ lines.push(chunk);11+ yield new TextEncoder().encode(chunk);12+};13+14+// eslint-disable-next-line max-params15+const testStringToUint8Array = async (t, expectedOutput, objectMode, preserveNewlines, execaMethod) => {16+ const lines = [];17+ const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {18+ stdout: {19+ transform: resultUint8ArrayGenerator.bind(undefined, lines),20+ objectMode,21+ preserveNewlines,22+ },23+ lines: true,24+ });25+ t.deepEqual(lines, [foobarString]);26+ t.deepEqual(stdout, expectedOutput);27+};28+29+test('Line splitting when converting from string to Uint8Array', testStringToUint8Array, [foobarString], false, true, execa);30+test('Line splitting when converting from string to Uint8Array, objectMode', testStringToUint8Array, [foobarUint8Array], true, true, execa);31+test('Line splitting when converting from string to Uint8Array, preserveNewlines', testStringToUint8Array, [foobarString], false, false, execa);32+test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines', testStringToUint8Array, [foobarUint8Array], true, false, execa);33+test('Line splitting when converting from string to Uint8Array, sync', testStringToUint8Array, [foobarString], false, true, execaSync);34+test('Line splitting when converting from string to Uint8Array, objectMode, sync', testStringToUint8Array, [foobarUint8Array], true, true, execaSync);35+test('Line splitting when converting from string to Uint8Array, preserveNewlines, sync', testStringToUint8Array, [foobarString], false, false, execaSync);36+test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines, sync', testStringToUint8Array, [foobarUint8Array], true, false, execaSync);37+38+const serializeResultGenerator = function * (lines, chunk) {39+ lines.push(chunk);40+ yield JSON.stringify(chunk);41+};42+43+const testUnsetObjectMode = async (t, expectedOutput, preserveNewlines, execaMethod) => {44+ const lines = [];45+ const {stdout} = await execaMethod('noop.js', {46+ stdout: [47+ getOutputsGenerator([foobarObject])(true),48+ {transform: serializeResultGenerator.bind(undefined, lines), preserveNewlines, objectMode: false},49+ ],50+ stripFinalNewline: false,51+ });52+ t.deepEqual(lines, [foobarObject]);53+ t.is(stdout, expectedOutput);54+};55+56+test('Can switch from objectMode to non-objectMode', testUnsetObjectMode, `${foobarObjectString}\n`, false, execa);57+test('Can switch from objectMode to non-objectMode, preserveNewlines', testUnsetObjectMode, foobarObjectString, true, execa);58+test('Can switch from objectMode to non-objectMode, sync', testUnsetObjectMode, `${foobarObjectString}\n`, false, execaSync);59+test('Can switch from objectMode to non-objectMode, preserveNewlines, sync', testUnsetObjectMode, foobarObjectString, true, execaSync);60+61+// eslint-disable-next-line max-params62+const testYieldArray = async (t, input, expectedLines, expectedOutput, execaMethod) => {63+ const lines = [];64+ const {stdout} = await execaMethod('noop.js', {65+ stdout: [66+ getOutputsGenerator(input)(),67+ resultGenerator(lines)(),68+ ],69+ stripFinalNewline: false,70+ });71+ t.deepEqual(lines, expectedLines);72+ t.deepEqual(stdout, expectedOutput);73+};74+75+test('Can use "yield* array" to produce multiple lines', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execa);76+test('Can use "yield* array" to produce empty lines', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execa);77+test('Can use "yield* array" to produce multiple lines, sync', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execaSync);78+test('Can use "yield* array" to produce empty lines, sync', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execaSync);deleted:test/stdio/split.js-362 removed
1-import test from 'ava';2-import {execa, execaSync} from '../../index.js';3-import {setFixtureDir} from '../helpers/fixtures-dir.js';4-import {getStdio} from '../helpers/stdio.js';5-import {6- getOutputsGenerator,7- noopGenerator,8- noopAsyncGenerator,9- resultGenerator,10-} from '../helpers/generator.js';11-import {foobarString, foobarUint8Array, foobarObject, foobarObjectString} from '../helpers/input.js';12-import {13- simpleFull,14- simpleChunks,15- simpleFullUint8Array,16- simpleFullUtf16Inverted,17- simpleFullUtf16Uint8Array,18- simpleChunksUint8Array,19- simpleFullEnd,20- simpleFullEndChunks,21- simpleFullEndUtf16Inverted,22- simpleFullHex,23- simpleLines,24- simpleFullEndLines,25- noNewlinesFull,26- noNewlinesChunks,27-} from '../helpers/lines.js';28-29-setFixtureDir();30-31-const windowsFull = 'aaa\r\nbbb\r\nccc';32-const windowsFullEnd = `${windowsFull}\r\n`;33-const windowsChunks = [windowsFull];34-const windowsLines = ['aaa\r\n', 'bbb\r\n', 'ccc'];35-const noNewlinesFullEnd = `${noNewlinesFull}\n`;36-const noNewlinesLines = ['aaabbbccc'];37-const singleFull = 'aaa';38-const singleFullEnd = `${singleFull}\n`;39-const singleFullEndWindows = `${singleFull}\r\n`;40-const singleChunks = [singleFull];41-const noLines = [];42-const emptyFull = '';43-const emptyChunks = [emptyFull];44-const manyEmptyChunks = [emptyFull, emptyFull, emptyFull];45-const newlineFull = '\n';46-const newlineChunks = [newlineFull];47-const newlinesFull = '\n\n\n';48-const newlinesChunks = [newlinesFull];49-const newlinesLines = ['\n', '\n', '\n'];50-const windowsNewlinesFull = '\r\n\r\n\r\n';51-const windowsNewlinesChunks = [windowsNewlinesFull];52-const windowsNewlinesLines = ['\r\n', '\r\n', '\r\n'];53-const runOverChunks = ['aaa\nb', 'b', 'b\nccc'];54-const bigFull = '.'.repeat(1e5);55-const bigFullEnd = `${bigFull}\n`;56-const bigChunks = [bigFull];57-const manyChunks = Array.from({length: 1e3}).fill('.');58-const manyFull = manyChunks.join('');59-const manyFullEnd = `${manyFull}\n`;60-const manyLines = [manyFull];61-const mixedNewlines = '.\n.\r\n.\n.\r\n.\n';62-63-// eslint-disable-next-line max-params64-const testLines = async (t, fdNumber, input, expectedLines, expectedOutput, objectMode, preserveNewlines, execaMethod) => {65- const lines = [];66- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`], {67- ...getStdio(fdNumber, [68- getOutputsGenerator(input)(false, true),69- resultGenerator(lines)(objectMode, false, preserveNewlines),70- ]),71- stripFinalNewline: false,72- });73- t.deepEqual(lines, expectedLines);74- t.deepEqual(stdio[fdNumber], expectedOutput);75-};76-77-test('Split stdout - n newlines, 1 chunk', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true, execa);78-test('Split stderr - n newlines, 1 chunk', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true, execa);79-test('Split stdio[*] - n newlines, 1 chunk', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true, execa);80-test('Split stdout - preserveNewlines, n chunks', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true, execa);81-test('Split stdout - 0 newlines, 1 chunk', testLines, 1, singleChunks, singleChunks, singleFull, false, true, execa);82-test('Split stdout - empty, 1 chunk', testLines, 1, emptyChunks, noLines, emptyFull, false, true, execa);83-test('Split stdout - Windows newlines', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true, execa);84-test('Split stdout - chunk ends with newline', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true, execa);85-test('Split stdout - single newline', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true, execa);86-test('Split stdout - only newlines', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true, execa);87-test('Split stdout - only Windows newlines', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true, execa);88-test('Split stdout - line split over multiple chunks', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true, execa);89-test('Split stdout - 0 newlines, big line', testLines, 1, bigChunks, bigChunks, bigFull, false, true, execa);90-test('Split stdout - 0 newlines, many chunks', testLines, 1, manyChunks, manyLines, manyFull, false, true, execa);91-test('Split stdout - n newlines, 1 chunk, objectMode', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true, execa);92-test('Split stderr - n newlines, 1 chunk, objectMode', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true, execa);93-test('Split stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true, execa);94-test('Split stdout - preserveNewlines, n chunks, objectMode', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true, execa);95-test('Split stdout - empty, 1 chunk, objectMode', testLines, 1, emptyChunks, noLines, noLines, true, true, execa);96-test('Split stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, singleChunks, singleChunks, singleChunks, true, true, execa);97-test('Split stdout - Windows newlines, objectMode', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true, execa);98-test('Split stdout - chunk ends with newline, objectMode', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true, execa);99-test('Split stdout - single newline, objectMode', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true, execa);100-test('Split stdout - only newlines, objectMode', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true, execa);101-test('Split stdout - only Windows newlines, objectMode', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true, execa);102-test('Split stdout - line split over multiple chunks, objectMode', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true, execa);103-test('Split stdout - 0 newlines, big line, objectMode', testLines, 1, bigChunks, bigChunks, bigChunks, true, true, execa);104-test('Split stdout - 0 newlines, many chunks, objectMode', testLines, 1, manyChunks, manyLines, manyLines, true, true, execa);105-test('Split stdout - n newlines, 1 chunk, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);106-test('Split stderr - n newlines, 1 chunk, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);107-test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);108-test('Split stdout - preserveNewlines, n chunks, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false, execa);109-test('Split stdout - empty, 1 chunk, preserveNewlines', testLines, 1, emptyChunks, noLines, emptyFull, false, false, execa);110-test('Split stdout - 0 newlines, 1 chunk, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false, execa);111-test('Split stdout - Windows newlines, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false, execa);112-test('Split stdout - chunk ends with newline, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);113-test('Split stdout - single newline, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false, execa);114-test('Split stdout - only newlines, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false, execa);115-test('Split stdout - only Windows newlines, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false, execa);116-test('Split stdout - line split over multiple chunks, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false, execa);117-test('Split stdout - 0 newlines, big line, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false, execa);118-test('Split stdout - 0 newlines, many chunks, preserveNewlines', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false, execa);119-test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);120-test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);121-test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);122-test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false, execa);123-test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines', testLines, 1, emptyChunks, noLines, noLines, true, false, execa);124-test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines', testLines, 1, singleChunks, singleChunks, singleChunks, true, false, execa);125-test('Split stdout - Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);126-test('Split stdout - chunk ends with newline, objectMode, preserveNewlines', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);127-test('Split stdout - single newline, objectMode, preserveNewlines', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false, execa);128-test('Split stdout - only newlines, objectMode, preserveNewlines', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execa);129-test('Split stdout - only Windows newlines, objectMode, preserveNewlines', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execa);130-test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false, execa);131-test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines', testLines, 1, bigChunks, bigChunks, bigChunks, true, false, execa);132-test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines', testLines, 1, manyChunks, manyLines, manyLines, true, false, execa);133-test('Split stdout - n newlines, 1 chunk, sync', testLines, 1, simpleChunks, simpleLines, simpleFull, false, true, execaSync);134-test('Split stderr - n newlines, 1 chunk, sync', testLines, 2, simpleChunks, simpleLines, simpleFull, false, true, execaSync);135-test('Split stdio[*] - n newlines, 1 chunk, sync', testLines, 3, simpleChunks, simpleLines, simpleFull, false, true, execaSync);136-test('Split stdout - preserveNewlines, n chunks, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFull, false, true, execaSync);137-test('Split stdout - 0 newlines, 1 chunk, sync', testLines, 1, singleChunks, singleChunks, singleFull, false, true, execaSync);138-test('Split stdout - empty, 1 chunk, sync', testLines, 1, emptyChunks, noLines, emptyFull, false, true, execaSync);139-test('Split stdout - Windows newlines, sync', testLines, 1, windowsChunks, windowsLines, windowsFull, false, true, execaSync);140-test('Split stdout - chunk ends with newline, sync', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEnd, false, true, execaSync);141-test('Split stdout - single newline, sync', testLines, 1, newlineChunks, newlineChunks, newlineFull, false, true, execaSync);142-test('Split stdout - only newlines, sync', testLines, 1, newlinesChunks, newlinesLines, newlinesFull, false, true, execaSync);143-test('Split stdout - only Windows newlines, sync', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesFull, false, true, execaSync);144-test('Split stdout - line split over multiple chunks, sync', testLines, 1, runOverChunks, simpleLines, simpleFull, false, true, execaSync);145-test('Split stdout - 0 newlines, big line, sync', testLines, 1, bigChunks, bigChunks, bigFull, false, true, execaSync);146-test('Split stdout - 0 newlines, many chunks, sync', testLines, 1, manyChunks, manyLines, manyFull, false, true, execaSync);147-test('Split stdout - n newlines, 1 chunk, objectMode, sync', testLines, 1, simpleChunks, simpleLines, simpleLines, true, true, execaSync);148-test('Split stderr - n newlines, 1 chunk, objectMode, sync', testLines, 2, simpleChunks, simpleLines, simpleLines, true, true, execaSync);149-test('Split stdio[*] - n newlines, 1 chunk, objectMode, sync', testLines, 3, simpleChunks, simpleLines, simpleLines, true, true, execaSync);150-test('Split stdout - preserveNewlines, n chunks, objectMode, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, true, execaSync);151-test('Split stdout - empty, 1 chunk, objectMode, sync', testLines, 1, emptyChunks, noLines, noLines, true, true, execaSync);152-test('Split stdout - 0 newlines, 1 chunk, objectMode, sync', testLines, 1, singleChunks, singleChunks, singleChunks, true, true, execaSync);153-test('Split stdout - Windows newlines, objectMode, sync', testLines, 1, windowsChunks, windowsLines, windowsLines, true, true, execaSync);154-test('Split stdout - chunk ends with newline, objectMode, sync', testLines, 1, simpleFullEndChunks, simpleFullEndLines, simpleFullEndLines, true, true, execaSync);155-test('Split stdout - single newline, objectMode, sync', testLines, 1, newlineChunks, newlineChunks, newlineChunks, true, true, execaSync);156-test('Split stdout - only newlines, objectMode, sync', testLines, 1, newlinesChunks, newlinesLines, newlinesLines, true, true, execaSync);157-test('Split stdout - only Windows newlines, objectMode, sync', testLines, 1, windowsNewlinesChunks, windowsNewlinesLines, windowsNewlinesLines, true, true, execaSync);158-test('Split stdout - line split over multiple chunks, objectMode, sync', testLines, 1, runOverChunks, simpleLines, simpleLines, true, true, execaSync);159-test('Split stdout - 0 newlines, big line, objectMode, sync', testLines, 1, bigChunks, bigChunks, bigChunks, true, true, execaSync);160-test('Split stdout - 0 newlines, many chunks, objectMode, sync', testLines, 1, manyChunks, manyLines, manyLines, true, true, execaSync);161-test('Split stdout - n newlines, 1 chunk, preserveNewlines, sync', testLines, 1, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);162-test('Split stderr - n newlines, 1 chunk, preserveNewlines, sync', testLines, 2, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);163-test('Split stdio[*] - n newlines, 1 chunk, preserveNewlines, sync', testLines, 3, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);164-test('Split stdout - preserveNewlines, n chunks, preserveNewlines, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesFullEnd, false, false, execaSync);165-test('Split stdout - empty, 1 chunk, preserveNewlines, sync', testLines, 1, emptyChunks, noLines, emptyFull, false, false, execaSync);166-test('Split stdout - 0 newlines, 1 chunk, preserveNewlines, sync', testLines, 1, singleChunks, singleChunks, singleFullEnd, false, false, execaSync);167-test('Split stdout - Windows newlines, preserveNewlines, sync', testLines, 1, windowsChunks, noNewlinesChunks, windowsFullEnd, false, false, execaSync);168-test('Split stdout - chunk ends with newline, preserveNewlines, sync', testLines, 1, simpleFullEndChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);169-test('Split stdout - single newline, preserveNewlines, sync', testLines, 1, newlineChunks, emptyChunks, newlineFull, false, false, execaSync);170-test('Split stdout - only newlines, preserveNewlines, sync', testLines, 1, newlinesChunks, manyEmptyChunks, newlinesFull, false, false, execaSync);171-test('Split stdout - only Windows newlines, preserveNewlines, sync', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, windowsNewlinesFull, false, false, execaSync);172-test('Split stdout - line split over multiple chunks, preserveNewlines, sync', testLines, 1, runOverChunks, noNewlinesChunks, simpleFullEnd, false, false, execaSync);173-test('Split stdout - 0 newlines, big line, preserveNewlines, sync', testLines, 1, bigChunks, bigChunks, bigFullEnd, false, false, execaSync);174-test('Split stdout - 0 newlines, many chunks, preserveNewlines, sync', testLines, 1, manyChunks, manyLines, manyFullEnd, false, false, execaSync);175-test('Split stdout - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);176-test('Split stderr - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 2, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);177-test('Split stdio[*] - n newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 3, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);178-test('Split stdout - preserveNewlines, n chunks, objectMode, preserveNewlines, sync', testLines, 1, noNewlinesChunks, noNewlinesLines, noNewlinesLines, true, false, execaSync);179-test('Split stdout - empty, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, emptyChunks, noLines, noLines, true, false, execaSync);180-test('Split stdout - 0 newlines, 1 chunk, objectMode, preserveNewlines, sync', testLines, 1, singleChunks, singleChunks, singleChunks, true, false, execaSync);181-test('Split stdout - Windows newlines, objectMode, preserveNewlines, sync', testLines, 1, windowsChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);182-test('Split stdout - chunk ends with newline, objectMode, preserveNewlines, sync', testLines, 1, simpleFullEndChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);183-test('Split stdout - single newline, objectMode, preserveNewlines, sync', testLines, 1, newlineChunks, emptyChunks, emptyChunks, true, false, execaSync);184-test('Split stdout - only newlines, objectMode, preserveNewlines, sync', testLines, 1, newlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execaSync);185-test('Split stdout - only Windows newlines, objectMode, preserveNewlines, sync', testLines, 1, windowsNewlinesChunks, manyEmptyChunks, manyEmptyChunks, true, false, execaSync);186-test('Split stdout - line split over multiple chunks, objectMode, preserveNewlines, sync', testLines, 1, runOverChunks, noNewlinesChunks, noNewlinesChunks, true, false, execaSync);187-test('Split stdout - 0 newlines, big line, objectMode, preserveNewlines, sync', testLines, 1, bigChunks, bigChunks, bigChunks, true, false, execaSync);188-test('Split stdout - 0 newlines, many chunks, objectMode, preserveNewlines, sync', testLines, 1, manyChunks, manyLines, manyLines, true, false, execaSync);189-190-// eslint-disable-next-line max-params191-const testBinaryOption = async (t, binary, input, expectedLines, expectedOutput, objectMode, preserveNewlines, encoding, execaMethod) => {192- const lines = [];193- const {stdout} = await execaMethod('noop.js', {194- stdout: [195- getOutputsGenerator(input)(false, true),196- resultGenerator(lines)(objectMode, binary, preserveNewlines),197- ],198- stripFinalNewline: false,199- encoding,200- });201- t.deepEqual(lines, expectedLines);202- t.deepEqual(stdout, expectedOutput);203-};204-205-test('Does not split lines when "binary" is true', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true, 'utf8', execa);206-test('Splits lines when "binary" is false', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execa);207-test('Splits lines when "binary" is undefined', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execa);208-test('Does not split lines when "binary" is true, encoding "utf16le"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, true, 'utf16le', execa);209-test('Splits lines when "binary" is false, encoding "utf16le"', testBinaryOption, false, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execa);210-test('Splits lines when "binary" is undefined, encoding "utf16le"', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execa);211-test('Does not split lines when "binary" is true, encoding "buffer"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);212-test('Does not split lines when "binary" is undefined, encoding "buffer"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);213-test('Does not split lines when "binary" is false, encoding "buffer"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execa);214-test('Does not split lines when "binary" is true, encoding "hex"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);215-test('Does not split lines when "binary" is undefined, encoding "hex"', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);216-test('Does not split lines when "binary" is false, encoding "hex"', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execa);217-test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true, 'utf8', execa);218-test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execa);219-test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execa);220-test('Does not split lines when "binary" is true, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false, 'utf8', execa);221-test('Splits lines when "binary" is false, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execa);222-test('Splits lines when "binary" is undefined, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execa);223-test('Does not split lines when "binary" is true, preserveNewlines, encoding "utf16le"', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, false, 'utf16le', execa);224-test('Splits lines when "binary" is false, preserveNewlines, encoding "utf16le"', testBinaryOption, false, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execa);225-test('Splits lines when "binary" is undefined, preserveNewlines, encoding "utf16le"', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execa);226-test('Does not split lines when "binary" is true, encoding "buffer", preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);227-test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);228-test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execa);229-test('Does not split lines when "binary" is true, objectMode, preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false, 'utf8', execa);230-test('Does not split lines when "binary" is true, encoding "hex", preserveNewlines', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);231-test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);232-test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execa);233-test('Splits lines when "binary" is false, objectMode, preserveNewlines', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execa);234-test('Splits lines when "binary" is undefined, objectMode, preserveNewlines', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execa);235-test('Does not split lines when "binary" is true, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, true, 'utf8', execaSync);236-test('Splits lines when "binary" is false, sync', testBinaryOption, false, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execaSync);237-test('Splits lines when "binary" is undefined, sync', testBinaryOption, undefined, simpleChunks, simpleLines, simpleFull, false, true, 'utf8', execaSync);238-test('Does not split lines when "binary" is true, encoding "utf16le", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, true, 'utf16le', execaSync);239-test('Splits lines when "binary" is false, encoding "utf16le", sync', testBinaryOption, false, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execaSync);240-test('Splits lines when "binary" is undefined, encoding "utf16le", sync', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], simpleLines, simpleFullUtf16Inverted, false, true, 'utf16le', execaSync);241-test('Does not split lines when "binary" is true, encoding "buffer", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);242-test('Does not split lines when "binary" is undefined, encoding "buffer", sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);243-test('Does not split lines when "binary" is false, encoding "buffer", sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, true, 'buffer', execaSync);244-test('Does not split lines when "binary" is true, encoding "hex", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);245-test('Does not split lines when "binary" is undefined, encoding "hex", sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);246-test('Does not split lines when "binary" is false, encoding "hex", sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, true, 'hex', execaSync);247-test('Does not split lines when "binary" is true, objectMode, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, true, 'utf8', execaSync);248-test('Splits lines when "binary" is false, objectMode, sync', testBinaryOption, false, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execaSync);249-test('Splits lines when "binary" is undefined, objectMode, sync', testBinaryOption, undefined, simpleChunks, simpleLines, simpleLines, true, true, 'utf8', execaSync);250-test('Does not split lines when "binary" is true, preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFull, false, false, 'utf8', execaSync);251-test('Splits lines when "binary" is false, preserveNewlines, sync', testBinaryOption, false, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execaSync);252-test('Splits lines when "binary" is undefined, preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, simpleFullEnd, false, false, 'utf8', execaSync);253-test('Does not split lines when "binary" is true, preserveNewlines, encoding "utf16le", sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUtf16Inverted, false, false, 'utf16le', execaSync);254-test('Splits lines when "binary" is false, preserveNewlines, encoding "utf16le", sync', testBinaryOption, false, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execaSync);255-test('Splits lines when "binary" is undefined, preserveNewlines, encoding "utf16le", sync', testBinaryOption, undefined, [simpleFullUtf16Uint8Array], noNewlinesChunks, simpleFullEndUtf16Inverted, false, false, 'utf16le', execaSync);256-test('Does not split lines when "binary" is true, encoding "buffer", preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);257-test('Does not split lines when "binary" is undefined, encoding "buffer", preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);258-test('Does not split lines when "binary" is false, encoding "buffer", preserveNewlines, sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullUint8Array, false, false, 'buffer', execaSync);259-test('Does not split lines when "binary" is true, objectMode, preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleChunksUint8Array, true, false, 'utf8', execaSync);260-test('Does not split lines when "binary" is true, encoding "hex", preserveNewlines, sync', testBinaryOption, true, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);261-test('Does not split lines when "binary" is undefined, encoding "hex", preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);262-test('Does not split lines when "binary" is false, encoding "hex", preserveNewlines, sync', testBinaryOption, false, simpleChunks, simpleChunksUint8Array, simpleFullHex, false, false, 'hex', execaSync);263-test('Splits lines when "binary" is false, objectMode, preserveNewlines, sync', testBinaryOption, false, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execaSync);264-test('Splits lines when "binary" is undefined, objectMode, preserveNewlines, sync', testBinaryOption, undefined, simpleChunks, noNewlinesChunks, noNewlinesChunks, true, false, 'utf8', execaSync);265-266-const resultUint8ArrayGenerator = function * (lines, chunk) {267- lines.push(chunk);268- yield new TextEncoder().encode(chunk);269-};270-271-// eslint-disable-next-line max-params272-const testStringToUint8Array = async (t, expectedOutput, objectMode, preserveNewlines, execaMethod) => {273- const lines = [];274- const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {275- stdout: {276- transform: resultUint8ArrayGenerator.bind(undefined, lines),277- objectMode,278- preserveNewlines,279- },280- lines: true,281- });282- t.deepEqual(lines, [foobarString]);283- t.deepEqual(stdout, expectedOutput);284-};285-286-test('Line splitting when converting from string to Uint8Array', testStringToUint8Array, [foobarString], false, true, execa);287-test('Line splitting when converting from string to Uint8Array, objectMode', testStringToUint8Array, [foobarUint8Array], true, true, execa);288-test('Line splitting when converting from string to Uint8Array, preserveNewlines', testStringToUint8Array, [foobarString], false, false, execa);289-test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines', testStringToUint8Array, [foobarUint8Array], true, false, execa);290-test('Line splitting when converting from string to Uint8Array, sync', testStringToUint8Array, [foobarString], false, true, execaSync);291-test('Line splitting when converting from string to Uint8Array, objectMode, sync', testStringToUint8Array, [foobarUint8Array], true, true, execaSync);292-test('Line splitting when converting from string to Uint8Array, preserveNewlines, sync', testStringToUint8Array, [foobarString], false, false, execaSync);293-test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines, sync', testStringToUint8Array, [foobarUint8Array], true, false, execaSync);294-295-const testStripNewline = async (t, input, expectedOutput, execaMethod) => {296- const {stdout} = await execaMethod('noop.js', {297- stdout: getOutputsGenerator([input])(),298- stripFinalNewline: false,299- });300- t.is(stdout, expectedOutput);301-};302-303-test('Strips newline when user do not mistakenly yield one at the end', testStripNewline, singleFull, singleFullEnd, execa);304-test('Strips newline when user mistakenly yielded one at the end', testStripNewline, singleFullEnd, singleFullEnd, execa);305-test('Strips newline when user mistakenly yielded one at the end, Windows newline', testStripNewline, singleFullEndWindows, singleFullEndWindows, execa);306-test('Strips newline when user do not mistakenly yield one at the end, sync', testStripNewline, singleFull, singleFullEnd, execaSync);307-test('Strips newline when user mistakenly yielded one at the end, sync', testStripNewline, singleFullEnd, singleFullEnd, execaSync);308-test('Strips newline when user mistakenly yielded one at the end, Windows newline, sync', testStripNewline, singleFullEndWindows, singleFullEndWindows, execaSync);309-310-const testMixNewlines = async (t, generator, execaMethod) => {311- const {stdout} = await execaMethod('noop-fd.js', ['1', mixedNewlines], {312- stdout: generator(),313- stripFinalNewline: false,314- });315- t.is(stdout, mixedNewlines);316-};317-318-test('Can mix Unix and Windows newlines', testMixNewlines, noopGenerator, execa);319-test('Can mix Unix and Windows newlines, sync', testMixNewlines, noopGenerator, execaSync);320-test('Can mix Unix and Windows newlines, async', testMixNewlines, noopAsyncGenerator, execa);321-322-const serializeResultGenerator = function * (lines, chunk) {323- lines.push(chunk);324- yield JSON.stringify(chunk);325-};326-327-const testUnsetObjectMode = async (t, expectedOutput, preserveNewlines, execaMethod) => {328- const lines = [];329- const {stdout} = await execaMethod('noop.js', {330- stdout: [331- getOutputsGenerator([foobarObject])(true),332- {transform: serializeResultGenerator.bind(undefined, lines), preserveNewlines, objectMode: false},333- ],334- stripFinalNewline: false,335- });336- t.deepEqual(lines, [foobarObject]);337- t.is(stdout, expectedOutput);338-};339-340-test('Can switch from objectMode to non-objectMode', testUnsetObjectMode, `${foobarObjectString}\n`, false, execa);341-test('Can switch from objectMode to non-objectMode, preserveNewlines', testUnsetObjectMode, foobarObjectString, true, execa);342-test('Can switch from objectMode to non-objectMode, sync', testUnsetObjectMode, `${foobarObjectString}\n`, false, execaSync);343-test('Can switch from objectMode to non-objectMode, preserveNewlines, sync', testUnsetObjectMode, foobarObjectString, true, execaSync);344-345-// eslint-disable-next-line max-params346-const testYieldArray = async (t, input, expectedLines, expectedOutput, execaMethod) => {347- const lines = [];348- const {stdout} = await execaMethod('noop.js', {349- stdout: [350- getOutputsGenerator(input)(),351- resultGenerator(lines)(),352- ],353- stripFinalNewline: false,354- });355- t.deepEqual(lines, expectedLines);356- t.deepEqual(stdout, expectedOutput);357-};358-359-test('Can use "yield* array" to produce multiple lines', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execa);360-test('Can use "yield* array" to produce empty lines', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execa);361-test('Can use "yield* array" to produce multiple lines, sync', testYieldArray, [foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execaSync);362-test('Can use "yield* array" to produce empty lines, sync', testYieldArray, [foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execaSync);added:test/stdio/transform-all.js+224 added
1+import {Buffer} from 'node:buffer';2+import test from 'ava';3+import {execa, execaSync} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {foobarObject} from '../helpers/input.js';6+import {7+ outputObjectGenerator,8+ uppercaseGenerator,9+ uppercaseBufferGenerator,10+} from '../helpers/generator.js';11+12+setFixtureDir();13+14+const textEncoder = new TextEncoder();15+16+const getAllStdioOption = (stdioOption, encoding, objectMode) => {17+ if (stdioOption) {18+ return 'pipe';19+ }20+21+ if (objectMode) {22+ return outputObjectGenerator();23+ }24+25+ return encoding === 'utf8' ? uppercaseGenerator() : uppercaseBufferGenerator();26+};27+28+const getStdoutStderrOutput = ({output, stdioOption, encoding, objectMode, lines}) => {29+ if (objectMode && !stdioOption) {30+ return encoding === 'utf8' ? [foobarObject, foobarObject] : [foobarObject];31+ }32+33+ const stdioOutput = stdioOption ? output : output.toUpperCase();34+35+ if (encoding === 'hex') {36+ return Buffer.from(stdioOutput).toString('hex');37+ }38+39+ if (encoding === 'buffer') {40+ return textEncoder.encode(stdioOutput);41+ }42+43+ return lines ? stdioOutput.trim().split('\n').map(string => `${string}\n`) : stdioOutput;44+};45+46+const getAllOutput = ({stdoutOutput, stderrOutput, encoding, objectMode, lines}) => {47+ if (objectMode || (lines && encoding === 'utf8')) {48+ return [stdoutOutput, stderrOutput].flat();49+ }50+51+ return encoding === 'buffer'52+ ? new Uint8Array([...stdoutOutput, ...stderrOutput])53+ : `${stdoutOutput}${stderrOutput}`;54+};55+56+// eslint-disable-next-line max-params57+const testGeneratorAll = async (t, reject, encoding, objectMode, stdoutOption, stderrOption, lines, execaMethod) => {58+ const fixtureName = reject ? 'all.js' : 'all-fail.js';59+ const {stdout, stderr, all} = await execaMethod(fixtureName, {60+ all: true,61+ reject,62+ stdout: getAllStdioOption(stdoutOption, encoding, objectMode),63+ stderr: getAllStdioOption(stderrOption, encoding, objectMode),64+ encoding,65+ lines,66+ stripFinalNewline: false,67+ });68+69+ const stdoutOutput = getStdoutStderrOutput({output: 'std\nout\n', stdioOption: stdoutOption, encoding, objectMode, lines});70+ t.deepEqual(stdout, stdoutOutput);71+ const stderrOutput = getStdoutStderrOutput({output: 'std\nerr\n', stdioOption: stderrOption, encoding, objectMode, lines});72+ t.deepEqual(stderr, stderrOutput);73+ const allOutput = getAllOutput({stdoutOutput, stderrOutput, encoding, objectMode, lines});74+ if (Array.isArray(all) && Array.isArray(allOutput)) {75+ t.deepEqual([...all].sort(), [...allOutput].sort());76+ } else {77+ t.deepEqual(all, allOutput);78+ }79+};80+81+test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false, false, execa);82+test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false, false, execa);83+test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false, false, execa);84+test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false, false, execa);85+test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false, false, execa);86+test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false, false, execa);87+test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true, false, execa);88+test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true, false, execa);89+test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true, false, execa);90+test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true, false, execa);91+test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true, false, execa);92+test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true, false, execa);93+test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false, false, execa);94+test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false, false, execa);95+test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false, false, execa);96+test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false, false, execa);97+test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false, false, execa);98+test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false, false, execa);99+test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false, false, execa);100+test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false, false, execa);101+test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false, false, execa);102+test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false, false, execa);103+test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false, false, execa);104+test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false, false, execa);105+test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true, false, execa);106+test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true, false, execa);107+test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true, false, execa);108+test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true, false, execa);109+test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true, false, execa);110+test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true, false, execa);111+test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false, false, execa);112+test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false, false, execa);113+test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false, false, execa);114+test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false, false, execa);115+test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false, false, execa);116+test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false, false, execa);117+test('Can use generators with result.all = transform + transform, sync', testGeneratorAll, true, 'utf8', false, false, false, false, execaSync);118+test('Can use generators with error.all = transform + transform, sync', testGeneratorAll, false, 'utf8', false, false, false, false, execaSync);119+test('Can use generators with result.all = transform + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, false, false, execaSync);120+test('Can use generators with error.all = transform + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, false, false, execaSync);121+test('Can use generators with result.all = transform + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, false, false, execaSync);122+test('Can use generators with error.all = transform + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, false, false, execaSync);123+test('Can use generators with result.all = transform + pipe, sync', testGeneratorAll, true, 'utf8', false, false, true, false, execaSync);124+test('Can use generators with error.all = transform + pipe, sync', testGeneratorAll, false, 'utf8', false, false, true, false, execaSync);125+test('Can use generators with result.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, true, false, execaSync);126+test('Can use generators with error.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, true, false, execaSync);127+test('Can use generators with result.all = transform + pipe, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, true, false, execaSync);128+test('Can use generators with error.all = transform + pipe, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, true, false, execaSync);129+test('Can use generators with result.all = pipe + transform, sync', testGeneratorAll, true, 'utf8', false, true, false, false, execaSync);130+test('Can use generators with error.all = pipe + transform, sync', testGeneratorAll, false, 'utf8', false, true, false, false, execaSync);131+test('Can use generators with result.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, true, false, false, execaSync);132+test('Can use generators with error.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, true, false, false, execaSync);133+test('Can use generators with result.all = pipe + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, true, false, false, execaSync);134+test('Can use generators with error.all = pipe + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, true, false, false, execaSync);135+test('Can use generators with result.all = transform + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, false, false, execaSync);136+test('Can use generators with error.all = transform + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, false, false, execaSync);137+test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, false, false, execaSync);138+test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, false, false, execaSync);139+test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, false, false, execaSync);140+test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, false, false, execaSync);141+test('Can use generators with result.all = transform + pipe, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, true, false, execaSync);142+test('Can use generators with error.all = transform + pipe, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, true, false, execaSync);143+test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, true, false, execaSync);144+test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, true, false, execaSync);145+test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, true, false, execaSync);146+test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, true, false, execaSync);147+test('Can use generators with result.all = pipe + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, true, false, false, execaSync);148+test('Can use generators with error.all = pipe + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, true, false, false, execaSync);149+test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, true, false, false, execaSync);150+test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, true, false, false, execaSync);151+test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, true, false, false, execaSync);152+test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, true, false, false, execaSync);153+test('Can use generators with result.all = transform + transform, lines', testGeneratorAll, true, 'utf8', false, false, false, true, execa);154+test('Can use generators with error.all = transform + transform, lines', testGeneratorAll, false, 'utf8', false, false, false, true, execa);155+test('Can use generators with result.all = transform + transform, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, false, false, true, execa);156+test('Can use generators with error.all = transform + transform, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, false, false, true, execa);157+test('Can use generators with result.all = transform + transform, encoding "hex", lines', testGeneratorAll, true, 'hex', false, false, false, true, execa);158+test('Can use generators with error.all = transform + transform, encoding "hex", lines', testGeneratorAll, false, 'hex', false, false, false, true, execa);159+test('Can use generators with result.all = transform + pipe, lines', testGeneratorAll, true, 'utf8', false, false, true, true, execa);160+test('Can use generators with error.all = transform + pipe, lines', testGeneratorAll, false, 'utf8', false, false, true, true, execa);161+test('Can use generators with result.all = transform + pipe, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, false, true, true, execa);162+test('Can use generators with error.all = transform + pipe, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, false, true, true, execa);163+test('Can use generators with result.all = transform + pipe, encoding "hex", lines', testGeneratorAll, true, 'hex', false, false, true, true, execa);164+test('Can use generators with error.all = transform + pipe, encoding "hex", lines', testGeneratorAll, false, 'hex', false, false, true, true, execa);165+test('Can use generators with result.all = pipe + transform, lines', testGeneratorAll, true, 'utf8', false, true, false, true, execa);166+test('Can use generators with error.all = pipe + transform, lines', testGeneratorAll, false, 'utf8', false, true, false, true, execa);167+test('Can use generators with result.all = pipe + transform, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, true, false, true, execa);168+test('Can use generators with error.all = pipe + transform, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, true, false, true, execa);169+test('Can use generators with result.all = pipe + transform, encoding "hex", lines', testGeneratorAll, true, 'hex', false, true, false, true, execa);170+test('Can use generators with error.all = pipe + transform, encoding "hex", lines', testGeneratorAll, false, 'hex', false, true, false, true, execa);171+test('Can use generators with result.all = transform + transform, objectMode, lines', testGeneratorAll, true, 'utf8', true, false, false, true, execa);172+test('Can use generators with error.all = transform + transform, objectMode, lines', testGeneratorAll, false, 'utf8', true, false, false, true, execa);173+test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, false, false, true, execa);174+test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, false, false, true, execa);175+test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, false, false, true, execa);176+test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, false, false, true, execa);177+test('Can use generators with result.all = transform + pipe, objectMode, lines', testGeneratorAll, true, 'utf8', true, false, true, true, execa);178+test('Can use generators with error.all = transform + pipe, objectMode, lines', testGeneratorAll, false, 'utf8', true, false, true, true, execa);179+test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, false, true, true, execa);180+test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, false, true, true, execa);181+test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, false, true, true, execa);182+test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, false, true, true, execa);183+test('Can use generators with result.all = pipe + transform, objectMode, lines', testGeneratorAll, true, 'utf8', true, true, false, true, execa);184+test('Can use generators with error.all = pipe + transform, objectMode, lines', testGeneratorAll, false, 'utf8', true, true, false, true, execa);185+test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, true, false, true, execa);186+test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, true, false, true, execa);187+test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, true, false, true, execa);188+test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, true, false, true, execa);189+test('Can use generators with result.all = transform + transform, sync, lines', testGeneratorAll, true, 'utf8', false, false, false, true, execaSync);190+test('Can use generators with error.all = transform + transform, sync, lines', testGeneratorAll, false, 'utf8', false, false, false, true, execaSync);191+test('Can use generators with result.all = transform + transform, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, false, false, true, execaSync);192+test('Can use generators with error.all = transform + transform, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, false, false, true, execaSync);193+test('Can use generators with result.all = transform + transform, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, false, false, true, execaSync);194+test('Can use generators with error.all = transform + transform, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, false, false, true, execaSync);195+test('Can use generators with result.all = transform + pipe, sync, lines', testGeneratorAll, true, 'utf8', false, false, true, true, execaSync);196+test('Can use generators with error.all = transform + pipe, sync, lines', testGeneratorAll, false, 'utf8', false, false, true, true, execaSync);197+test('Can use generators with result.all = transform + pipe, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, false, true, true, execaSync);198+test('Can use generators with error.all = transform + pipe, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, false, true, true, execaSync);199+test('Can use generators with result.all = transform + pipe, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, false, true, true, execaSync);200+test('Can use generators with error.all = transform + pipe, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, false, true, true, execaSync);201+test('Can use generators with result.all = pipe + transform, sync, lines', testGeneratorAll, true, 'utf8', false, true, false, true, execaSync);202+test('Can use generators with error.all = pipe + transform, sync, lines', testGeneratorAll, false, 'utf8', false, true, false, true, execaSync);203+test('Can use generators with result.all = pipe + transform, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, true, false, true, execaSync);204+test('Can use generators with error.all = pipe + transform, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, true, false, true, execaSync);205+test('Can use generators with result.all = pipe + transform, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, true, false, true, execaSync);206+test('Can use generators with error.all = pipe + transform, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, true, false, true, execaSync);207+test('Can use generators with result.all = transform + transform, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, false, false, true, execaSync);208+test('Can use generators with error.all = transform + transform, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, false, false, true, execaSync);209+test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, false, false, true, execaSync);210+test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, false, false, true, execaSync);211+test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, false, false, true, execaSync);212+test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, false, false, true, execaSync);213+test('Can use generators with result.all = transform + pipe, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, false, true, true, execaSync);214+test('Can use generators with error.all = transform + pipe, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, false, true, true, execaSync);215+test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, false, true, true, execaSync);216+test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, false, true, true, execaSync);217+test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, false, true, true, execaSync);218+test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, false, true, true, execaSync);219+test('Can use generators with result.all = pipe + transform, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, true, false, true, execaSync);220+test('Can use generators with error.all = pipe + transform, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, true, false, true, execaSync);221+test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, true, false, true, execaSync);222+test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, true, false, true, execaSync);223+test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, true, false, true, execaSync);224+test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, true, false, true, execaSync);added:test/stdio/transform-error.js+89 added
1+import {once} from 'node:events';2+import test from 'ava';3+import {execa, execaSync} from '../../index.js';4+import {foobarString} from '../helpers/input.js';5+import {noopGenerator, infiniteGenerator, convertTransformToFinal} from '../helpers/generator.js';6+import {generatorsMap} from '../helpers/map.js';7+import {setFixtureDir} from '../helpers/fixtures-dir.js';8+9+setFixtureDir();10+11+const assertProcessError = async (t, type, execaMethod, getSubprocess) => {12+ const cause = new Error(foobarString);13+ const transform = generatorsMap[type].throwing(cause)();14+ const error = execaMethod === execa15+ ? await t.throwsAsync(getSubprocess(transform))16+ : t.throws(() => {17+ getSubprocess(transform);18+ });19+ t.is(error.cause, cause);20+};21+22+const testThrowingGenerator = async (t, type, final, execaMethod) => {23+ await assertProcessError(t, type, execaMethod, transform => execaMethod('noop.js', {24+ stdout: convertTransformToFinal(transform, final),25+ }));26+};27+28+test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false, execa);29+test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true, execa);30+test('Generators "transform" errors make subprocess fail, sync', testThrowingGenerator, 'generator', false, execaSync);31+test('Generators "final" errors make subprocess fail, sync', testThrowingGenerator, 'generator', true, execaSync);32+test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false, execa);33+test('WebTransform "transform" errors make subprocess fail', testThrowingGenerator, 'webTransform', false, execa);34+35+const testSingleErrorOutput = async (t, type, execaMethod) => {36+ await assertProcessError(t, type, execaMethod, transform => execaMethod('noop.js', {37+ stdout: [38+ generatorsMap[type].noop(false),39+ transform,40+ generatorsMap[type].noop(false),41+ ],42+ }));43+};44+45+test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator', execa);46+test('Generators errors make subprocess fail even when other output generators do not throw, sync', testSingleErrorOutput, 'generator', execaSync);47+test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex', execa);48+test('WebTransform errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'webTransform', execa);49+50+const testSingleErrorInput = async (t, type, execaMethod) => {51+ await assertProcessError(t, type, execaMethod, transform => execaMethod('stdin.js', {52+ stdin: [53+ ['foobar\n'],54+ generatorsMap[type].noop(false),55+ transform,56+ generatorsMap[type].noop(false),57+ ],58+ }));59+};60+61+test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator', execa);62+test('Generators errors make subprocess fail even when other input generators do not throw, sync', testSingleErrorInput, 'generator', execaSync);63+test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex', execa);64+test('WebTransform errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'webTransform', execa);65+66+const testGeneratorCancel = async (t, error) => {67+ const subprocess = execa('noop.js', {stdout: infiniteGenerator()});68+ await once(subprocess.stdout, 'data');69+ subprocess.stdout.destroy(error);70+ await (error === undefined ? t.notThrowsAsync(subprocess) : t.throwsAsync(subprocess));71+};72+73+test('Running generators are canceled on subprocess abort', testGeneratorCancel, undefined);74+test('Running generators are canceled on subprocess error', testGeneratorCancel, new Error('test'));75+76+const testGeneratorDestroy = async (t, transform) => {77+ const subprocess = execa('forever.js', {stdout: transform});78+ const cause = new Error('test');79+ subprocess.stdout.destroy(cause);80+ subprocess.kill();81+ t.like(await t.throwsAsync(subprocess), {cause});82+};83+84+test('Generators are destroyed on subprocess error, sync', testGeneratorDestroy, noopGenerator(false));85+test('Generators are destroyed on subprocess error, async', testGeneratorDestroy, infiniteGenerator());86+87+test('Generators are destroyed on early subprocess exit', async t => {88+ await t.throwsAsync(execa('noop.js', {stdout: infiniteGenerator(), uid: -1}));89+});added:test/stdio/transform-final.js+35 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {foobarString} from '../helpers/input.js';4+import {getOutputAsyncGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';5+import {setFixtureDir} from '../helpers/fixtures-dir.js';6+7+setFixtureDir();8+9+const testGeneratorFinal = async (t, fixtureName, execaMethod) => {10+ const {stdout} = await execaMethod(fixtureName, {stdout: convertTransformToFinal(getOutputGenerator(foobarString)(), true)});11+ t.is(stdout, foobarString);12+};13+14+test('Generators "final" can be used', testGeneratorFinal, 'noop.js', execa);15+test('Generators "final" is used even on empty streams', testGeneratorFinal, 'empty.js', execa);16+test('Generators "final" can be used, sync', testGeneratorFinal, 'noop.js', execaSync);17+test('Generators "final" is used even on empty streams, sync', testGeneratorFinal, 'empty.js', execaSync);18+19+const testFinalAlone = async (t, final, execaMethod) => {20+ const {stdout} = await execaMethod('noop-fd.js', ['1', '.'], {stdout: {final: final(foobarString)().transform, binary: true}});21+ t.is(stdout, `.${foobarString}`);22+};23+24+test('Generators "final" can be used without "transform"', testFinalAlone, getOutputGenerator, execa);25+test('Generators "final" can be used without "transform", sync', testFinalAlone, getOutputGenerator, execaSync);26+test('Generators "final" can be used without "transform", async', testFinalAlone, getOutputAsyncGenerator, execa);27+28+const testFinalNoOutput = async (t, final, execaMethod) => {29+ const {stdout} = await execaMethod('empty.js', {stdout: {final: final(foobarString)().transform}});30+ t.is(stdout, foobarString);31+};32+33+test('Generators "final" can be used without "transform" nor output', testFinalNoOutput, getOutputGenerator, execa);34+test('Generators "final" can be used without "transform" nor output, sync', testFinalNoOutput, getOutputGenerator, execaSync);35+test('Generators "final" can be used without "transform" nor output, async', testFinalNoOutput, getOutputAsyncGenerator, execa);added:test/stdio/transform-input.js+158 added
1+import {Buffer} from 'node:buffer';2+import test from 'ava';3+import {execa, execaSync} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {getStdio} from '../helpers/stdio.js';6+import {7+ foobarString,8+ foobarUppercase,9+ foobarHex,10+ foobarUint8Array,11+ foobarBuffer,12+ foobarObject,13+ foobarObjectString,14+} from '../helpers/input.js';15+import {generatorsMap} from '../helpers/map.js';16+17+setFixtureDir();18+19+const getInputObjectMode = (objectMode, addNoopTransform, type) => objectMode20+ ? {21+ input: [foobarObject],22+ generators: generatorsMap[type].addNoop(generatorsMap[type].serialize(objectMode), addNoopTransform, objectMode),23+ output: foobarObjectString,24+ }25+ : {26+ input: foobarUint8Array,27+ generators: generatorsMap[type].addNoop(generatorsMap[type].uppercase(objectMode), addNoopTransform, objectMode),28+ output: foobarUppercase,29+ };30+31+// eslint-disable-next-line max-params32+const testGeneratorInput = async (t, fdNumber, objectMode, addNoopTransform, type, execaMethod) => {33+ const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);34+ const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, [input, ...generators]));35+ t.is(stdout, output);36+};37+38+test('Can use generators with result.stdin', testGeneratorInput, 0, false, false, 'generator', execa);39+test('Can use generators with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'generator', execa);40+test('Can use generators with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'generator', execa);41+test('Can use generators with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'generator', execa);42+test('Can use generators with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'generator', execa);43+test('Can use generators with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'generator', execa);44+test('Can use generators with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'generator', execa);45+test('Can use generators with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'generator', execa);46+test('Can use generators with result.stdin, sync', testGeneratorInput, 0, false, false, 'generator', execaSync);47+test('Can use generators with result.stdin, objectMode, sync', testGeneratorInput, 0, true, false, 'generator', execaSync);48+test('Can use generators with result.stdin, noop transform, sync', testGeneratorInput, 0, false, true, 'generator', execaSync);49+test('Can use generators with result.stdin, objectMode, noop transform, sync', testGeneratorInput, 0, true, true, 'generator', execaSync);50+test('Can use duplexes with result.stdin', testGeneratorInput, 0, false, false, 'duplex', execa);51+test('Can use duplexes with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'duplex', execa);52+test('Can use duplexes with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'duplex', execa);53+test('Can use duplexes with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'duplex', execa);54+test('Can use duplexes with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'duplex', execa);55+test('Can use duplexes with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'duplex', execa);56+test('Can use duplexes with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'duplex', execa);57+test('Can use duplexes with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'duplex', execa);58+test('Can use webTransforms with result.stdin', testGeneratorInput, 0, false, false, 'webTransform', execa);59+test('Can use webTransforms with result.stdio[*] as input', testGeneratorInput, 3, false, false, 'webTransform', execa);60+test('Can use webTransforms with result.stdin, objectMode', testGeneratorInput, 0, true, false, 'webTransform', execa);61+test('Can use webTransforms with result.stdio[*] as input, objectMode', testGeneratorInput, 3, true, false, 'webTransform', execa);62+test('Can use webTransforms with result.stdin, noop transform', testGeneratorInput, 0, false, true, 'webTransform', execa);63+test('Can use webTransforms with result.stdio[*] as input, noop transform', testGeneratorInput, 3, false, true, 'webTransform', execa);64+test('Can use webTransforms with result.stdin, objectMode, noop transform', testGeneratorInput, 0, true, true, 'webTransform', execa);65+test('Can use webTransforms with result.stdio[*] as input, objectMode, noop transform', testGeneratorInput, 3, true, true, 'webTransform', execa);66+67+// eslint-disable-next-line max-params68+const testGeneratorInputPipe = async (t, useShortcutProperty, objectMode, addNoopTransform, type, input) => {69+ const {generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);70+ const subprocess = execa('stdin-fd.js', ['0'], getStdio(0, generators));71+ const stream = useShortcutProperty ? subprocess.stdin : subprocess.stdio[0];72+ stream.end(...input);73+ const {stdout} = await subprocess;74+ const expectedOutput = input[1] === 'utf16le' ? Buffer.from(output, input[1]).toString() : output;75+ t.is(stdout, expectedOutput);76+};77+78+test('Can use generators with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'generator', [foobarString, 'utf8']);79+test('Can use generators with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'generator', [foobarString, 'utf8']);80+test('Can use generators with subprocess.stdio[0] and encoding "utf16le"', testGeneratorInputPipe, false, false, false, 'generator', [foobarString, 'utf16le']);81+test('Can use generators with subprocess.stdin and encoding "utf16le"', testGeneratorInputPipe, true, false, false, 'generator', [foobarString, 'utf16le']);82+test('Can use generators with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'generator', [foobarBuffer, 'buffer']);83+test('Can use generators with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'generator', [foobarBuffer, 'buffer']);84+test('Can use generators with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'generator', [foobarHex, 'hex']);85+test('Can use generators with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'generator', [foobarHex, 'hex']);86+test('Can use generators with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'generator', [foobarObject]);87+test('Can use generators with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'generator', [foobarObject]);88+test('Can use generators with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarString, 'utf8']);89+test('Can use generators with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarString, 'utf8']);90+test('Can use generators with subprocess.stdio[0] and encoding "utf16le", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarString, 'utf16le']);91+test('Can use generators with subprocess.stdin and encoding "utf16le", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarString, 'utf16le']);92+test('Can use generators with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarBuffer, 'buffer']);93+test('Can use generators with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarBuffer, 'buffer']);94+test('Can use generators with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'generator', [foobarHex, 'hex']);95+test('Can use generators with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'generator', [foobarHex, 'hex']);96+test('Can use generators with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'generator', [foobarObject]);97+test('Can use generators with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'generator', [foobarObject]);98+test('Can use duplexes with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'duplex', [foobarString, 'utf8']);99+test('Can use duplexes with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'duplex', [foobarString, 'utf8']);100+test('Can use duplexes with subprocess.stdio[0] and encoding "utf16le"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarString, 'utf16le']);101+test('Can use duplexes with subprocess.stdin and encoding "utf16le"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarString, 'utf16le']);102+test('Can use duplexes with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarBuffer, 'buffer']);103+test('Can use duplexes with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarBuffer, 'buffer']);104+test('Can use duplexes with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'duplex', [foobarHex, 'hex']);105+test('Can use duplexes with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'duplex', [foobarHex, 'hex']);106+test('Can use duplexes with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'duplex', [foobarObject]);107+test('Can use duplexes with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'duplex', [foobarObject]);108+test('Can use duplexes with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarString, 'utf8']);109+test('Can use duplexes with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarString, 'utf8']);110+test('Can use duplexes with subprocess.stdio[0] and encoding "utf16le", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarString, 'utf16le']);111+test('Can use duplexes with subprocess.stdin and encoding "utf16le", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarString, 'utf16le']);112+test('Can use duplexes with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarBuffer, 'buffer']);113+test('Can use duplexes with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarBuffer, 'buffer']);114+test('Can use duplexes with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'duplex', [foobarHex, 'hex']);115+test('Can use duplexes with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'duplex', [foobarHex, 'hex']);116+test('Can use duplexes with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'duplex', [foobarObject]);117+test('Can use duplexes with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'duplex', [foobarObject]);118+test('Can use webTransforms with subprocess.stdio[0] and default encoding', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarString, 'utf8']);119+test('Can use webTransforms with subprocess.stdin and default encoding', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarString, 'utf8']);120+test('Can use webTransforms with subprocess.stdio[0] and encoding "utf16le"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarString, 'utf16le']);121+test('Can use webTransforms with subprocess.stdin and encoding "utf16le"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarString, 'utf16le']);122+test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarBuffer, 'buffer']);123+test('Can use webTransforms with subprocess.stdin and encoding "buffer"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarBuffer, 'buffer']);124+test('Can use webTransforms with subprocess.stdio[0] and encoding "hex"', testGeneratorInputPipe, false, false, false, 'webTransform', [foobarHex, 'hex']);125+test('Can use webTransforms with subprocess.stdin and encoding "hex"', testGeneratorInputPipe, true, false, false, 'webTransform', [foobarHex, 'hex']);126+test('Can use webTransforms with subprocess.stdio[0], objectMode', testGeneratorInputPipe, false, true, false, 'webTransform', [foobarObject]);127+test('Can use webTransforms with subprocess.stdin, objectMode', testGeneratorInputPipe, true, true, false, 'webTransform', [foobarObject]);128+test('Can use webTransforms with subprocess.stdio[0] and default encoding, noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarString, 'utf8']);129+test('Can use webTransforms with subprocess.stdin and default encoding, noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarString, 'utf8']);130+test('Can use webTransforms with subprocess.stdio[0] and encoding "utf16le", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarString, 'utf16le']);131+test('Can use webTransforms with subprocess.stdin and encoding "utf16le", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarString, 'utf16le']);132+test('Can use webTransforms with subprocess.stdio[0] and encoding "buffer", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarBuffer, 'buffer']);133+test('Can use webTransforms with subprocess.stdin and encoding "buffer", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarBuffer, 'buffer']);134+test('Can use webTransforms with subprocess.stdio[0] and encoding "hex", noop transform', testGeneratorInputPipe, false, false, true, 'webTransform', [foobarHex, 'hex']);135+test('Can use webTransforms with subprocess.stdin and encoding "hex", noop transform', testGeneratorInputPipe, true, false, true, 'webTransform', [foobarHex, 'hex']);136+test('Can use webTransforms with subprocess.stdio[0], objectMode, noop transform', testGeneratorInputPipe, false, true, true, 'webTransform', [foobarObject]);137+test('Can use webTransforms with subprocess.stdin, objectMode, noop transform', testGeneratorInputPipe, true, true, true, 'webTransform', [foobarObject]);138+139+const testGeneratorStdioInputPipe = async (t, objectMode, addNoopTransform, type) => {140+ const {input, generators, output} = getInputObjectMode(objectMode, addNoopTransform, type);141+ const subprocess = execa('stdin-fd.js', ['3'], getStdio(3, [[], ...generators]));142+ subprocess.stdio[3].write(Array.isArray(input) ? input[0] : input);143+ const {stdout} = await subprocess;144+ t.is(stdout, output);145+};146+147+test('Can use generators with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'generator');148+test('Can use generators with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'generator');149+test('Can use generators with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'generator');150+test('Can use generators with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'generator');151+test('Can use duplexes with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'duplex');152+test('Can use duplexes with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'duplex');153+test('Can use duplexes with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'duplex');154+test('Can use duplexes with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'duplex');155+test('Can use webTransforms with subprocess.stdio[*] as input', testGeneratorStdioInputPipe, false, false, 'webTransform');156+test('Can use webTransforms with subprocess.stdio[*] as input, objectMode', testGeneratorStdioInputPipe, true, false, 'webTransform');157+test('Can use webTransforms with subprocess.stdio[*] as input, noop transform', testGeneratorStdioInputPipe, false, true, 'webTransform');158+test('Can use webTransforms with subprocess.stdio[*] as input, objectMode, noop transform', testGeneratorStdioInputPipe, true, true, 'webTransform');added:test/stdio/transform-mixed.js+104 added
1+import {readFile, writeFile, rm} from 'node:fs/promises';2+import {PassThrough} from 'node:stream';3+import test from 'ava';4+import getStream from 'get-stream';5+import tempfile from 'tempfile';6+import {execa, execaSync} from '../../index.js';7+import {setFixtureDir} from '../helpers/fixtures-dir.js';8+import {foobarString, foobarUppercase, foobarUint8Array} from '../helpers/input.js';9+import {uppercaseGenerator} from '../helpers/generator.js';10+import {uppercaseBufferDuplex} from '../helpers/duplex.js';11+import {uppercaseBufferWebTransform} from '../helpers/web-transform.js';12+import {generatorsMap} from '../helpers/map.js';13+14+setFixtureDir();15+16+const testInputOption = async (t, type, execaMethod) => {17+ const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});18+ t.is(stdout, foobarUppercase);19+};20+21+test('Can use generators with input option', testInputOption, 'generator', execa);22+test('Can use generators with input option, sync', testInputOption, 'generator', execaSync);23+test('Can use duplexes with input option', testInputOption, 'duplex', execa);24+test('Can use webTransforms with input option', testInputOption, 'webTransform', execa);25+26+// eslint-disable-next-line max-params27+const testInputFile = async (t, stdinOption, useInputFile, reversed, execaMethod) => {28+ const filePath = tempfile();29+ await writeFile(filePath, foobarString);30+ const options = useInputFile31+ ? {inputFile: filePath, stdin: stdinOption}32+ : {stdin: [{file: filePath}, stdinOption]};33+ options.stdin = reversed ? options.stdin.reverse() : options.stdin;34+ const {stdout} = await execaMethod('stdin-fd.js', ['0'], options);35+ t.is(stdout, foobarUppercase);36+ await rm(filePath);37+};38+39+test('Can use generators with a file as input', testInputFile, uppercaseGenerator(), false, false, execa);40+test('Can use generators with a file as input, reversed', testInputFile, uppercaseGenerator(), false, true, execa);41+test('Can use generators with inputFile option', testInputFile, uppercaseGenerator(), true, false, execa);42+test('Can use generators with a file as input, sync', testInputFile, uppercaseGenerator(), false, false, execaSync);43+test('Can use generators with a file as input, reversed, sync', testInputFile, uppercaseGenerator(), false, true, execaSync);44+test('Can use generators with inputFile option, sync', testInputFile, uppercaseGenerator(), true, false, execaSync);45+test('Can use duplexes with a file as input', testInputFile, uppercaseBufferDuplex(), false, false, execa);46+test('Can use duplexes with a file as input, reversed', testInputFile, uppercaseBufferDuplex(), false, true, execa);47+test('Can use duplexes with inputFile option', testInputFile, uppercaseBufferDuplex(), true, false, execa);48+test('Can use webTransforms with a file as input', testInputFile, uppercaseBufferWebTransform(), false, false, execa);49+test('Can use webTransforms with a file as input, reversed', testInputFile, uppercaseBufferWebTransform(), false, true, execa);50+test('Can use webTransforms with inputFile option', testInputFile, uppercaseBufferWebTransform(), true, false, execa);51+52+const testOutputFile = async (t, reversed, type, execaMethod) => {53+ const filePath = tempfile();54+ const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];55+ const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;56+ const {stdout} = await execaMethod('noop-fd.js', ['1'], {stdout: reversedStdoutOption});57+ t.is(stdout, foobarUppercase);58+ t.is(await readFile(filePath, 'utf8'), foobarUppercase);59+ await rm(filePath);60+};61+62+test('Can use generators with a file as output', testOutputFile, false, 'generator', execa);63+test('Can use generators with a file as output, reversed', testOutputFile, true, 'generator', execa);64+test('Can use generators with a file as output, sync', testOutputFile, false, 'generator', execaSync);65+test('Can use generators with a file as output, reversed, sync', testOutputFile, true, 'generator', execaSync);66+test('Can use duplexes with a file as output', testOutputFile, false, 'duplex', execa);67+test('Can use duplexes with a file as output, reversed', testOutputFile, true, 'duplex', execa);68+test('Can use webTransforms with a file as output', testOutputFile, false, 'webTransform', execa);69+test('Can use webTransforms with a file as output, reversed', testOutputFile, true, 'webTransform', execa);70+71+const testWritableDestination = async (t, type) => {72+ const passThrough = new PassThrough();73+ const [{stdout}, streamOutput] = await Promise.all([74+ execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].uppercaseBuffer(false, true), passThrough]}),75+ getStream(passThrough),76+ ]);77+ t.is(stdout, foobarUppercase);78+ t.is(streamOutput, foobarUppercase);79+};80+81+test('Can use generators to a Writable stream', testWritableDestination, 'generator');82+test('Can use duplexes to a Writable stream', testWritableDestination, 'duplex');83+test('Can use webTransforms to a Writable stream', testWritableDestination, 'webTransform');84+85+const testReadableSource = async (t, type) => {86+ const passThrough = new PassThrough();87+ const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});88+ passThrough.end(foobarString);89+ const {stdout} = await subprocess;90+ t.is(stdout, foobarUppercase);91+};92+93+test('Can use generators from a Readable stream', testReadableSource, 'generator');94+test('Can use duplexes from a Readable stream', testReadableSource, 'duplex');95+test('Can use webTransforms from a Readable stream', testReadableSource, 'webTransform');96+97+const testInherit = async (t, type) => {98+ const {stdout} = await execa('nested-inherit.js', [type]);99+ t.is(stdout, foobarUppercase);100+};101+102+test('Can use generators with "inherit"', testInherit, 'generator');103+test('Can use duplexes with "inherit"', testInherit, 'duplex');104+test('Can use webTransforms with "inherit"', testInherit, 'webTransform');added:test/stdio/transform-output.js+261 added
1+import test from 'ava';2+import getStream, {getStreamAsArray} from 'get-stream';3+import {execa, execaSync} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {getStdio} from '../helpers/stdio.js';6+import {foobarString, foobarUppercase, foobarObject} from '../helpers/input.js';7+import {generatorsMap} from '../helpers/map.js';8+9+setFixtureDir();10+11+const getOutputObjectMode = (objectMode, addNoopTransform, type, binary) => objectMode12+ ? {13+ generators: generatorsMap[type].addNoop(generatorsMap[type].outputObject(), addNoopTransform, objectMode, binary),14+ output: [foobarObject],15+ getStreamMethod: getStreamAsArray,16+ }17+ : {18+ generators: generatorsMap[type].addNoop(generatorsMap[type].uppercaseBuffer(objectMode, true), addNoopTransform, objectMode, binary),19+ output: foobarUppercase,20+ getStreamMethod: getStream,21+ };22+23+// eslint-disable-next-line max-params24+const testGeneratorOutput = async (t, fdNumber, reject, useShortcutProperty, objectMode, addNoopTransform, type, execaMethod) => {25+ const {generators, output} = getOutputObjectMode(objectMode, addNoopTransform, type);26+ const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';27+ const {stdout, stderr, stdio} = await execaMethod(fixtureName, [`${fdNumber}`, foobarString], {...getStdio(fdNumber, generators), reject});28+ const result = useShortcutProperty ? [stdout, stderr][fdNumber - 1] : stdio[fdNumber];29+ t.deepEqual(result, output);30+};31+32+test('Can use generators with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'generator', execa);33+test('Can use generators with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'generator', execa);34+test('Can use generators with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'generator', execa);35+test('Can use generators with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'generator', execa);36+test('Can use generators with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'generator', execa);37+test('Can use generators with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'generator', execa);38+test('Can use generators with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'generator', execa);39+test('Can use generators with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'generator', execa);40+test('Can use generators with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'generator', execa);41+test('Can use generators with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'generator', execa);42+test('Can use generators with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'generator', execa);43+test('Can use generators with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'generator', execa);44+test('Can use generators with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'generator', execa);45+test('Can use generators with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'generator', execa);46+test('Can use generators with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'generator', execa);47+test('Can use generators with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'generator', execa);48+test('Can use generators with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'generator', execa);49+test('Can use generators with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'generator', execa);50+test('Can use generators with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'generator', execa);51+test('Can use generators with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'generator', execa);52+test('Can use generators with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'generator', execa);53+test('Can use generators with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'generator', execa);54+test('Can use generators with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'generator', execa);55+test('Can use generators with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'generator', execa);56+test('Can use generators with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'generator', execa);57+test('Can use generators with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'generator', execa);58+test('Can use generators with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'generator', execa);59+test('Can use generators with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'generator', execa);60+test('Can use generators with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'generator', execa);61+test('Can use generators with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'generator', execa);62+test('Can use generators with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'generator', execa);63+test('Can use generators with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'generator', execa);64+test('Can use generators with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'generator', execa);65+test('Can use generators with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'generator', execa);66+test('Can use generators with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'generator', execa);67+test('Can use generators with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'generator', execa);68+test('Can use generators with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'generator', execa);69+test('Can use generators with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'generator', execa);70+test('Can use generators with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'generator', execa);71+test('Can use generators with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'generator', execa);72+test('Can use generators with result.stdio[1], sync', testGeneratorOutput, 1, true, false, false, false, 'generator', execaSync);73+test('Can use generators with result.stdout, sync', testGeneratorOutput, 1, true, true, false, false, 'generator', execaSync);74+test('Can use generators with result.stdio[2], sync', testGeneratorOutput, 2, true, false, false, false, 'generator', execaSync);75+test('Can use generators with result.stderr, sync', testGeneratorOutput, 2, true, true, false, false, 'generator', execaSync);76+test('Can use generators with result.stdio[*] as output, sync', testGeneratorOutput, 3, true, false, false, false, 'generator', execaSync);77+test('Can use generators with error.stdio[1], sync', testGeneratorOutput, 1, false, false, false, false, 'generator', execaSync);78+test('Can use generators with error.stdout, sync', testGeneratorOutput, 1, false, true, false, false, 'generator', execaSync);79+test('Can use generators with error.stdio[2], sync', testGeneratorOutput, 2, false, false, false, false, 'generator', execaSync);80+test('Can use generators with error.stderr, sync', testGeneratorOutput, 2, false, true, false, false, 'generator', execaSync);81+test('Can use generators with error.stdio[*] as output, sync', testGeneratorOutput, 3, false, false, false, false, 'generator', execaSync);82+test('Can use generators with result.stdio[1], objectMode, sync', testGeneratorOutput, 1, true, false, true, false, 'generator', execaSync);83+test('Can use generators with result.stdout, objectMode, sync', testGeneratorOutput, 1, true, true, true, false, 'generator', execaSync);84+test('Can use generators with result.stdio[2], objectMode, sync', testGeneratorOutput, 2, true, false, true, false, 'generator', execaSync);85+test('Can use generators with result.stderr, objectMode, sync', testGeneratorOutput, 2, true, true, true, false, 'generator', execaSync);86+test('Can use generators with result.stdio[*] as output, objectMode, sync', testGeneratorOutput, 3, true, false, true, false, 'generator', execaSync);87+test('Can use generators with error.stdio[1], objectMode, sync', testGeneratorOutput, 1, false, false, true, false, 'generator', execaSync);88+test('Can use generators with error.stdout, objectMode, sync', testGeneratorOutput, 1, false, true, true, false, 'generator', execaSync);89+test('Can use generators with error.stdio[2], objectMode, sync', testGeneratorOutput, 2, false, false, true, false, 'generator', execaSync);90+test('Can use generators with error.stderr, objectMode, sync', testGeneratorOutput, 2, false, true, true, false, 'generator', execaSync);91+test('Can use generators with error.stdio[*] as output, objectMode, sync', testGeneratorOutput, 3, false, false, true, false, 'generator', execaSync);92+test('Can use generators with result.stdio[1], noop transform, sync', testGeneratorOutput, 1, true, false, false, true, 'generator', execaSync);93+test('Can use generators with result.stdout, noop transform, sync', testGeneratorOutput, 1, true, true, false, true, 'generator', execaSync);94+test('Can use generators with result.stdio[2], noop transform, sync', testGeneratorOutput, 2, true, false, false, true, 'generator', execaSync);95+test('Can use generators with result.stderr, noop transform, sync', testGeneratorOutput, 2, true, true, false, true, 'generator', execaSync);96+test('Can use generators with result.stdio[*] as output, noop transform, sync', testGeneratorOutput, 3, true, false, false, true, 'generator', execaSync);97+test('Can use generators with error.stdio[1], noop transform, sync', testGeneratorOutput, 1, false, false, false, true, 'generator', execaSync);98+test('Can use generators with error.stdout, noop transform, sync', testGeneratorOutput, 1, false, true, false, true, 'generator', execaSync);99+test('Can use generators with error.stdio[2], noop transform, sync', testGeneratorOutput, 2, false, false, false, true, 'generator', execaSync);100+test('Can use generators with error.stderr, noop transform, sync', testGeneratorOutput, 2, false, true, false, true, 'generator', execaSync);101+test('Can use generators with error.stdio[*] as output, noop transform, sync', testGeneratorOutput, 3, false, false, false, true, 'generator', execaSync);102+test('Can use generators with result.stdio[1], objectMode, noop transform, sync', testGeneratorOutput, 1, true, false, true, true, 'generator', execaSync);103+test('Can use generators with result.stdout, objectMode, noop transform, sync', testGeneratorOutput, 1, true, true, true, true, 'generator', execaSync);104+test('Can use generators with result.stdio[2], objectMode, noop transform, sync', testGeneratorOutput, 2, true, false, true, true, 'generator', execaSync);105+test('Can use generators with result.stderr, objectMode, noop transform, sync', testGeneratorOutput, 2, true, true, true, true, 'generator', execaSync);106+test('Can use generators with result.stdio[*] as output, objectMode, noop transform, sync', testGeneratorOutput, 3, true, false, true, true, 'generator', execaSync);107+test('Can use generators with error.stdio[1], objectMode, noop transform, sync', testGeneratorOutput, 1, false, false, true, true, 'generator', execaSync);108+test('Can use generators with error.stdout, objectMode, noop transform, sync', testGeneratorOutput, 1, false, true, true, true, 'generator', execaSync);109+test('Can use generators with error.stdio[2], objectMode, noop transform, sync', testGeneratorOutput, 2, false, false, true, true, 'generator', execaSync);110+test('Can use generators with error.stderr, objectMode, noop transform, sync', testGeneratorOutput, 2, false, true, true, true, 'generator', execaSync);111+test('Can use generators with error.stdio[*] as output, objectMode, noop transform, sync', testGeneratorOutput, 3, false, false, true, true, 'generator', execaSync);112+test('Can use duplexes with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'duplex', execa);113+test('Can use duplexes with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'duplex', execa);114+test('Can use duplexes with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'duplex', execa);115+test('Can use duplexes with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'duplex', execa);116+test('Can use duplexes with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'duplex', execa);117+test('Can use duplexes with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'duplex', execa);118+test('Can use duplexes with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'duplex', execa);119+test('Can use duplexes with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'duplex', execa);120+test('Can use duplexes with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'duplex', execa);121+test('Can use duplexes with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'duplex', execa);122+test('Can use duplexes with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'duplex', execa);123+test('Can use duplexes with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'duplex', execa);124+test('Can use duplexes with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'duplex', execa);125+test('Can use duplexes with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'duplex', execa);126+test('Can use duplexes with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'duplex', execa);127+test('Can use duplexes with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'duplex', execa);128+test('Can use duplexes with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'duplex', execa);129+test('Can use duplexes with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'duplex', execa);130+test('Can use duplexes with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'duplex', execa);131+test('Can use duplexes with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'duplex', execa);132+test('Can use duplexes with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'duplex', execa);133+test('Can use duplexes with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'duplex', execa);134+test('Can use duplexes with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'duplex', execa);135+test('Can use duplexes with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'duplex', execa);136+test('Can use duplexes with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'duplex', execa);137+test('Can use duplexes with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'duplex', execa);138+test('Can use duplexes with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'duplex', execa);139+test('Can use duplexes with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'duplex', execa);140+test('Can use duplexes with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'duplex', execa);141+test('Can use duplexes with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'duplex', execa);142+test('Can use duplexes with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'duplex', execa);143+test('Can use duplexes with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'duplex', execa);144+test('Can use duplexes with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'duplex', execa);145+test('Can use duplexes with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'duplex', execa);146+test('Can use duplexes with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'duplex', execa);147+test('Can use duplexes with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'duplex', execa);148+test('Can use duplexes with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'duplex', execa);149+test('Can use duplexes with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'duplex', execa);150+test('Can use duplexes with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'duplex', execa);151+test('Can use duplexes with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'duplex', execa);152+test('Can use webTransforms with result.stdio[1]', testGeneratorOutput, 1, true, false, false, false, 'webTransform', execa);153+test('Can use webTransforms with result.stdout', testGeneratorOutput, 1, true, true, false, false, 'webTransform', execa);154+test('Can use webTransforms with result.stdio[2]', testGeneratorOutput, 2, true, false, false, false, 'webTransform', execa);155+test('Can use webTransforms with result.stderr', testGeneratorOutput, 2, true, true, false, false, 'webTransform', execa);156+test('Can use webTransforms with result.stdio[*] as output', testGeneratorOutput, 3, true, false, false, false, 'webTransform', execa);157+test('Can use webTransforms with error.stdio[1]', testGeneratorOutput, 1, false, false, false, false, 'webTransform', execa);158+test('Can use webTransforms with error.stdout', testGeneratorOutput, 1, false, true, false, false, 'webTransform', execa);159+test('Can use webTransforms with error.stdio[2]', testGeneratorOutput, 2, false, false, false, false, 'webTransform', execa);160+test('Can use webTransforms with error.stderr', testGeneratorOutput, 2, false, true, false, false, 'webTransform', execa);161+test('Can use webTransforms with error.stdio[*] as output', testGeneratorOutput, 3, false, false, false, false, 'webTransform', execa);162+test('Can use webTransforms with result.stdio[1], objectMode', testGeneratorOutput, 1, true, false, true, false, 'webTransform', execa);163+test('Can use webTransforms with result.stdout, objectMode', testGeneratorOutput, 1, true, true, true, false, 'webTransform', execa);164+test('Can use webTransforms with result.stdio[2], objectMode', testGeneratorOutput, 2, true, false, true, false, 'webTransform', execa);165+test('Can use webTransforms with result.stderr, objectMode', testGeneratorOutput, 2, true, true, true, false, 'webTransform', execa);166+test('Can use webTransforms with result.stdio[*] as output, objectMode', testGeneratorOutput, 3, true, false, true, false, 'webTransform', execa);167+test('Can use webTransforms with error.stdio[1], objectMode', testGeneratorOutput, 1, false, false, true, false, 'webTransform', execa);168+test('Can use webTransforms with error.stdout, objectMode', testGeneratorOutput, 1, false, true, true, false, 'webTransform', execa);169+test('Can use webTransforms with error.stdio[2], objectMode', testGeneratorOutput, 2, false, false, true, false, 'webTransform', execa);170+test('Can use webTransforms with error.stderr, objectMode', testGeneratorOutput, 2, false, true, true, false, 'webTransform', execa);171+test('Can use webTransforms with error.stdio[*] as output, objectMode', testGeneratorOutput, 3, false, false, true, false, 'webTransform', execa);172+test('Can use webTransforms with result.stdio[1], noop transform', testGeneratorOutput, 1, true, false, false, true, 'webTransform', execa);173+test('Can use webTransforms with result.stdout, noop transform', testGeneratorOutput, 1, true, true, false, true, 'webTransform', execa);174+test('Can use webTransforms with result.stdio[2], noop transform', testGeneratorOutput, 2, true, false, false, true, 'webTransform', execa);175+test('Can use webTransforms with result.stderr, noop transform', testGeneratorOutput, 2, true, true, false, true, 'webTransform', execa);176+test('Can use webTransforms with result.stdio[*] as output, noop transform', testGeneratorOutput, 3, true, false, false, true, 'webTransform', execa);177+test('Can use webTransforms with error.stdio[1], noop transform', testGeneratorOutput, 1, false, false, false, true, 'webTransform', execa);178+test('Can use webTransforms with error.stdout, noop transform', testGeneratorOutput, 1, false, true, false, true, 'webTransform', execa);179+test('Can use webTransforms with error.stdio[2], noop transform', testGeneratorOutput, 2, false, false, false, true, 'webTransform', execa);180+test('Can use webTransforms with error.stderr, noop transform', testGeneratorOutput, 2, false, true, false, true, 'webTransform', execa);181+test('Can use webTransforms with error.stdio[*] as output, noop transform', testGeneratorOutput, 3, false, false, false, true, 'webTransform', execa);182+test('Can use webTransforms with result.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, true, false, true, true, 'webTransform', execa);183+test('Can use webTransforms with result.stdout, objectMode, noop transform', testGeneratorOutput, 1, true, true, true, true, 'webTransform', execa);184+test('Can use webTransforms with result.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, true, false, true, true, 'webTransform', execa);185+test('Can use webTransforms with result.stderr, objectMode, noop transform', testGeneratorOutput, 2, true, true, true, true, 'webTransform', execa);186+test('Can use webTransforms with result.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, true, false, true, true, 'webTransform', execa);187+test('Can use webTransforms with error.stdio[1], objectMode, noop transform', testGeneratorOutput, 1, false, false, true, true, 'webTransform', execa);188+test('Can use webTransforms with error.stdout, objectMode, noop transform', testGeneratorOutput, 1, false, true, true, true, 'webTransform', execa);189+test('Can use webTransforms with error.stdio[2], objectMode, noop transform', testGeneratorOutput, 2, false, false, true, true, 'webTransform', execa);190+test('Can use webTransforms with error.stderr, objectMode, noop transform', testGeneratorOutput, 2, false, true, true, true, 'webTransform', execa);191+test('Can use webTransforms with error.stdio[*] as output, objectMode, noop transform', testGeneratorOutput, 3, false, false, true, true, 'webTransform', execa);192+193+// eslint-disable-next-line max-params194+const testGeneratorOutputPipe = async (t, fdNumber, useShortcutProperty, objectMode, addNoopTransform, type) => {195+ const {generators, output, getStreamMethod} = getOutputObjectMode(objectMode, addNoopTransform, type, true);196+ const subprocess = execa('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, generators));197+ const stream = useShortcutProperty ? [subprocess.stdout, subprocess.stderr][fdNumber - 1] : subprocess.stdio[fdNumber];198+ const [result] = await Promise.all([getStreamMethod(stream), subprocess]);199+ t.deepEqual(result, output);200+};201+202+test('Can use generators with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'generator');203+test('Can use generators with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'generator');204+test('Can use generators with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'generator');205+test('Can use generators with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'generator');206+test('Can use generators with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'generator');207+test('Can use generators with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'generator');208+test('Can use generators with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'generator');209+test('Can use generators with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'generator');210+test('Can use generators with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'generator');211+test('Can use generators with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'generator');212+test('Can use generators with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'generator');213+test('Can use generators with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'generator');214+test('Can use generators with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'generator');215+test('Can use generators with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'generator');216+test('Can use generators with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'generator');217+test('Can use generators with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'generator');218+test('Can use generators with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'generator');219+test('Can use generators with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'generator');220+test('Can use generators with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'generator');221+test('Can use generators with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'generator');222+test('Can use duplexes with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'duplex');223+test('Can use duplexes with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'duplex');224+test('Can use duplexes with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'duplex');225+test('Can use duplexes with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'duplex');226+test('Can use duplexes with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'duplex');227+test('Can use duplexes with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'duplex');228+test('Can use duplexes with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'duplex');229+test('Can use duplexes with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'duplex');230+test('Can use duplexes with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'duplex');231+test('Can use duplexes with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'duplex');232+test('Can use duplexes with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'duplex');233+test('Can use duplexes with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'duplex');234+test('Can use duplexes with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'duplex');235+test('Can use duplexes with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'duplex');236+test('Can use duplexes with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'duplex');237+test('Can use duplexes with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'duplex');238+test('Can use duplexes with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'duplex');239+test('Can use duplexes with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'duplex');240+test('Can use duplexes with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'duplex');241+test('Can use duplexes with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'duplex');242+test('Can use webTransforms with subprocess.stdio[1]', testGeneratorOutputPipe, 1, false, false, false, 'webTransform');243+test('Can use webTransforms with subprocess.stdout', testGeneratorOutputPipe, 1, true, false, false, 'webTransform');244+test('Can use webTransforms with subprocess.stdio[2]', testGeneratorOutputPipe, 2, false, false, false, 'webTransform');245+test('Can use webTransforms with subprocess.stderr', testGeneratorOutputPipe, 2, true, false, false, 'webTransform');246+test('Can use webTransforms with subprocess.stdio[*] as output', testGeneratorOutputPipe, 3, false, false, false, 'webTransform');247+test('Can use webTransforms with subprocess.stdio[1], objectMode', testGeneratorOutputPipe, 1, false, true, false, 'webTransform');248+test('Can use webTransforms with subprocess.stdout, objectMode', testGeneratorOutputPipe, 1, true, true, false, 'webTransform');249+test('Can use webTransforms with subprocess.stdio[2], objectMode', testGeneratorOutputPipe, 2, false, true, false, 'webTransform');250+test('Can use webTransforms with subprocess.stderr, objectMode', testGeneratorOutputPipe, 2, true, true, false, 'webTransform');251+test('Can use webTransforms with subprocess.stdio[*] as output, objectMode', testGeneratorOutputPipe, 3, false, true, false, 'webTransform');252+test('Can use webTransforms with subprocess.stdio[1], noop transform', testGeneratorOutputPipe, 1, false, false, true, 'webTransform');253+test('Can use webTransforms with subprocess.stdout, noop transform', testGeneratorOutputPipe, 1, true, false, true, 'webTransform');254+test('Can use webTransforms with subprocess.stdio[2], noop transform', testGeneratorOutputPipe, 2, false, false, true, 'webTransform');255+test('Can use webTransforms with subprocess.stderr, noop transform', testGeneratorOutputPipe, 2, true, false, true, 'webTransform');256+test('Can use webTransforms with subprocess.stdio[*] as output, noop transform', testGeneratorOutputPipe, 3, false, false, true, 'webTransform');257+test('Can use webTransforms with subprocess.stdio[1], objectMode, noop transform', testGeneratorOutputPipe, 1, false, true, true, 'webTransform');258+test('Can use webTransforms with subprocess.stdout, objectMode, noop transform', testGeneratorOutputPipe, 1, true, true, true, 'webTransform');259+test('Can use webTransforms with subprocess.stdio[2], objectMode, noop transform', testGeneratorOutputPipe, 2, false, true, true, 'webTransform');260+test('Can use webTransforms with subprocess.stderr, objectMode, noop transform', testGeneratorOutputPipe, 2, true, true, true, 'webTransform');261+test('Can use webTransforms with subprocess.stdio[*] as output, objectMode, noop transform', testGeneratorOutputPipe, 3, false, true, true, 'webTransform');added:test/stdio/transform-run.js+185 added
1+import {Buffer} from 'node:buffer';2+import {scheduler} from 'node:timers/promises';3+import test from 'ava';4+import {getStreamAsArray} from 'get-stream';5+import {execa, execaSync} from '../../index.js';6+import {foobarString} from '../helpers/input.js';7+import {8+ noopGenerator,9+ outputObjectGenerator,10+ convertTransformToFinal,11+ prefix,12+ suffix,13+} from '../helpers/generator.js';14+import {generatorsMap} from '../helpers/map.js';15+import {defaultHighWaterMark} from '../helpers/stream.js';16+import {setFixtureDir} from '../helpers/fixtures-dir.js';17+import {maxBuffer, assertErrorMessage} from '../helpers/max-buffer.js';18+19+setFixtureDir();20+21+const repeatCount = defaultHighWaterMark * 3;22+23+const writerGenerator = function * () {24+ for (let index = 0; index < repeatCount; index += 1) {25+ yield '\n';26+ }27+};28+29+const getLengthGenerator = function * (t, chunk) {30+ t.is(chunk.length, 1);31+ yield chunk;32+};33+34+// eslint-disable-next-line max-params35+const testHighWaterMark = async (t, passThrough, binary, objectMode, execaMethod) => {36+ const {stdout} = await execaMethod('noop.js', {37+ stdout: [38+ ...(objectMode ? [outputObjectGenerator()] : []),39+ writerGenerator,40+ ...(passThrough ? [noopGenerator(false, binary)] : []),41+ {transform: getLengthGenerator.bind(undefined, t), preserveNewlines: true, objectMode: true},42+ ],43+ });44+ t.is(stdout.length, repeatCount);45+ t.true(stdout.every(chunk => chunk === '\n'));46+};47+48+test('Synchronous yields are not buffered, no passThrough', testHighWaterMark, false, false, false, execa);49+test('Synchronous yields are not buffered, line-wise passThrough', testHighWaterMark, true, false, false, execa);50+test('Synchronous yields are not buffered, binary passThrough', testHighWaterMark, true, true, false, execa);51+test('Synchronous yields are not buffered, objectMode as input but not output', testHighWaterMark, false, false, true, execa);52+test('Synchronous yields are not buffered, no passThrough, sync', testHighWaterMark, false, false, false, execaSync);53+test('Synchronous yields are not buffered, line-wise passThrough, sync', testHighWaterMark, true, false, false, execaSync);54+test('Synchronous yields are not buffered, binary passThrough, sync', testHighWaterMark, true, true, false, execaSync);55+test('Synchronous yields are not buffered, objectMode as input but not output, sync', testHighWaterMark, false, false, true, execaSync);56+57+// eslint-disable-next-line max-params58+const testNoYield = async (t, type, objectMode, final, output, execaMethod) => {59+ const {stdout} = await execaMethod('noop.js', {stdout: convertTransformToFinal(generatorsMap[type].noYield(objectMode), final)});60+ t.deepEqual(stdout, output);61+};62+63+test('Generator can filter "transform" by not calling yield', testNoYield, 'generator', false, false, '', execa);64+test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, 'generator', true, false, [], execa);65+test('Generator can filter "final" by not calling yield', testNoYield, 'generator', false, true, '', execa);66+test('Generator can filter "final" by not calling yield, objectMode', testNoYield, 'generator', true, true, [], execa);67+test('Generator can filter "transform" by not calling yield, sync', testNoYield, 'generator', false, false, '', execaSync);68+test('Generator can filter "transform" by not calling yield, objectMode, sync', testNoYield, 'generator', true, false, [], execaSync);69+test('Generator can filter "final" by not calling yield, sync', testNoYield, 'generator', false, true, '', execaSync);70+test('Generator can filter "final" by not calling yield, objectMode, sync', testNoYield, 'generator', true, true, [], execaSync);71+test('Duplex can filter by not calling push', testNoYield, 'duplex', false, false, '', execa);72+test('Duplex can filter by not calling push, objectMode', testNoYield, 'duplex', true, false, [], execa);73+test('WebTransform can filter by not calling push', testNoYield, 'webTransform', false, false, '', execa);74+test('WebTransform can filter by not calling push, objectMode', testNoYield, 'webTransform', true, false, [], execa);75+76+const testMultipleYields = async (t, type, final, binary) => {77+ const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});78+ const newline = binary ? '' : '\n';79+ t.is(stdout, `${prefix}${newline}${foobarString}${newline}${suffix}`);80+};81+82+test('Generator can yield "transform" multiple times at different moments', testMultipleYields, 'generator', false, false);83+test('Generator can yield "final" multiple times at different moments', testMultipleYields, 'generator', true, false);84+test('Duplex can push multiple times at different moments', testMultipleYields, 'duplex', false, true);85+test('WebTransform can push multiple times at different moments', testMultipleYields, 'webTransform', false, true);86+87+const partsPerChunk = 4;88+const chunksPerCall = 10;89+const callCount = 5;90+const fullString = '\n'.repeat(defaultHighWaterMark / partsPerChunk);91+92+const yieldFullStrings = function * () {93+ yield * Array.from({length: partsPerChunk * chunksPerCall}).fill(fullString);94+};95+96+const manyYieldGenerator = async function * () {97+ for (let index = 0; index < callCount; index += 1) {98+ yield * yieldFullStrings();99+ // eslint-disable-next-line no-await-in-loop100+ await scheduler.yield();101+ }102+};103+104+const testManyYields = async (t, final) => {105+ const subprocess = execa('noop.js', {stdout: convertTransformToFinal(manyYieldGenerator, final), stripFinalNewline: false});106+ const [chunks, {stdout}] = await Promise.all([getStreamAsArray(subprocess.stdout), subprocess]);107+ const expectedChunk = Buffer.from(fullString);108+ t.deepEqual(chunks, Array.from({length: callCount * partsPerChunk * chunksPerCall}).fill(expectedChunk));109+ t.is(chunks.join(''), stdout);110+};111+112+test('Generator "transform" yields are sent right away', testManyYields, false);113+test('Generator "final" yields are sent right away', testManyYields, true);114+115+const testMaxBuffer = async (t, type) => {116+ const bigString = '.'.repeat(maxBuffer);117+ const {stdout} = await execa('noop.js', {118+ maxBuffer,119+ stdout: generatorsMap[type].getOutput(bigString)(false, true),120+ });121+ t.is(stdout, bigString);122+123+ const {isMaxBuffer, shortMessage} = await t.throwsAsync(execa('noop.js', {124+ maxBuffer,125+ stdout: generatorsMap[type].getOutput(`${bigString}.`)(false, true),126+ }));127+ t.true(isMaxBuffer);128+ assertErrorMessage(t, shortMessage);129+};130+131+test('Generators take "maxBuffer" into account', testMaxBuffer, 'generator');132+test('Duplexes take "maxBuffer" into account', testMaxBuffer, 'duplex');133+test('WebTransforms take "maxBuffer" into account', testMaxBuffer, 'webTransform');134+135+test('Generators does not take "maxBuffer" into account, sync', t => {136+ const bigString = '.'.repeat(maxBuffer);137+ const {isMaxBuffer, stdout} = execaSync('noop.js', {138+ maxBuffer,139+ stdout: generatorsMap.generator.getOutput(`${bigString}.`)(false, true),140+ });141+ t.false(isMaxBuffer);142+ t.is(stdout.length, maxBuffer + 1);143+});144+145+const testMaxBufferObject = async (t, type) => {146+ const bigArray = Array.from({length: maxBuffer}).fill('..');147+ const {stdout} = await execa('noop.js', {148+ maxBuffer,149+ stdout: generatorsMap[type].getOutputs(bigArray)(true, true),150+ });151+ t.is(stdout.length, maxBuffer);152+153+ const {isMaxBuffer, shortMessage} = await t.throwsAsync(execa('noop.js', {154+ maxBuffer,155+ stdout: generatorsMap[type].getOutputs([...bigArray, ''])(true, true),156+ }));157+ t.true(isMaxBuffer);158+ assertErrorMessage(t, shortMessage, {unit: 'objects'});159+};160+161+test('Generators take "maxBuffer" into account, objectMode', testMaxBufferObject, 'generator');162+test('Duplexes take "maxBuffer" into account, objectMode', testMaxBufferObject, 'duplex');163+test('WebTransforms take "maxBuffer" into account, objectMode', testMaxBufferObject, 'webTransform');164+165+test('Generators does not take "maxBuffer" into account, objectMode, sync', t => {166+ const bigArray = Array.from({length: maxBuffer}).fill('..');167+ const {isMaxBuffer, stdout} = execaSync('noop.js', {168+ maxBuffer,169+ stdout: generatorsMap.generator.getOutputs([...bigArray, ''])(true, true),170+ });171+ t.false(isMaxBuffer);172+ t.is(stdout.length, maxBuffer + 1);173+});174+175+const testAsyncGenerators = async (t, type, final) => {176+ const {stdout} = await execa('noop.js', {177+ stdout: convertTransformToFinal(generatorsMap[type].timeout(1e2)(), final),178+ });179+ t.is(stdout, foobarString);180+};181+182+test('Generators "transform" is awaited on success', testAsyncGenerators, 'generator', false);183+test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);184+test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);185+test('WebTransform is awaited on success', testAsyncGenerators, 'webTransform', false);deleted:test/stdio/transform.js-297 removed
1-import {Buffer} from 'node:buffer';2-import {once} from 'node:events';3-import {scheduler} from 'node:timers/promises';4-import test from 'ava';5-import {getStreamAsArray} from 'get-stream';6-import {execa, execaSync} from '../../index.js';7-import {foobarString} from '../helpers/input.js';8-import {9- noopGenerator,10- getOutputAsyncGenerator,11- getOutputGenerator,12- infiniteGenerator,13- outputObjectGenerator,14- convertTransformToFinal,15- prefix,16- suffix,17-} from '../helpers/generator.js';18-import {generatorsMap} from '../helpers/map.js';19-import {defaultHighWaterMark} from '../helpers/stream.js';20-import {setFixtureDir} from '../helpers/fixtures-dir.js';21-import {maxBuffer, assertErrorMessage} from '../helpers/max-buffer.js';22-23-setFixtureDir();24-25-const testGeneratorFinal = async (t, fixtureName, execaMethod) => {26- const {stdout} = await execaMethod(fixtureName, {stdout: convertTransformToFinal(getOutputGenerator(foobarString)(), true)});27- t.is(stdout, foobarString);28-};29-30-test('Generators "final" can be used', testGeneratorFinal, 'noop.js', execa);31-test('Generators "final" is used even on empty streams', testGeneratorFinal, 'empty.js', execa);32-test('Generators "final" can be used, sync', testGeneratorFinal, 'noop.js', execaSync);33-test('Generators "final" is used even on empty streams, sync', testGeneratorFinal, 'empty.js', execaSync);34-35-const testFinalAlone = async (t, final, execaMethod) => {36- const {stdout} = await execaMethod('noop-fd.js', ['1', '.'], {stdout: {final: final(foobarString)().transform, binary: true}});37- t.is(stdout, `.${foobarString}`);38-};39-40-test('Generators "final" can be used without "transform"', testFinalAlone, getOutputGenerator, execa);41-test('Generators "final" can be used without "transform", sync', testFinalAlone, getOutputGenerator, execaSync);42-test('Generators "final" can be used without "transform", async', testFinalAlone, getOutputAsyncGenerator, execa);43-44-const testFinalNoOutput = async (t, final, execaMethod) => {45- const {stdout} = await execaMethod('empty.js', {stdout: {final: final(foobarString)().transform}});46- t.is(stdout, foobarString);47-};48-49-test('Generators "final" can be used without "transform" nor output', testFinalNoOutput, getOutputGenerator, execa);50-test('Generators "final" can be used without "transform" nor output, sync', testFinalNoOutput, getOutputGenerator, execaSync);51-test('Generators "final" can be used without "transform" nor output, async', testFinalNoOutput, getOutputAsyncGenerator, execa);52-53-const repeatCount = defaultHighWaterMark * 3;54-55-const writerGenerator = function * () {56- for (let index = 0; index < repeatCount; index += 1) {57- yield '\n';58- }59-};60-61-const getLengthGenerator = function * (t, chunk) {62- t.is(chunk.length, 1);63- yield chunk;64-};65-66-// eslint-disable-next-line max-params67-const testHighWaterMark = async (t, passThrough, binary, objectMode, execaMethod) => {68- const {stdout} = await execaMethod('noop.js', {69- stdout: [70- ...(objectMode ? [outputObjectGenerator()] : []),71- writerGenerator,72- ...(passThrough ? [noopGenerator(false, binary)] : []),73- {transform: getLengthGenerator.bind(undefined, t), preserveNewlines: true, objectMode: true},74- ],75- });76- t.is(stdout.length, repeatCount);77- t.true(stdout.every(chunk => chunk === '\n'));78-};79-80-test('Synchronous yields are not buffered, no passThrough', testHighWaterMark, false, false, false, execa);81-test('Synchronous yields are not buffered, line-wise passThrough', testHighWaterMark, true, false, false, execa);82-test('Synchronous yields are not buffered, binary passThrough', testHighWaterMark, true, true, false, execa);83-test('Synchronous yields are not buffered, objectMode as input but not output', testHighWaterMark, false, false, true, execa);84-test('Synchronous yields are not buffered, no passThrough, sync', testHighWaterMark, false, false, false, execaSync);85-test('Synchronous yields are not buffered, line-wise passThrough, sync', testHighWaterMark, true, false, false, execaSync);86-test('Synchronous yields are not buffered, binary passThrough, sync', testHighWaterMark, true, true, false, execaSync);87-test('Synchronous yields are not buffered, objectMode as input but not output, sync', testHighWaterMark, false, false, true, execaSync);88-89-// eslint-disable-next-line max-params90-const testNoYield = async (t, type, objectMode, final, output, execaMethod) => {91- const {stdout} = await execaMethod('noop.js', {stdout: convertTransformToFinal(generatorsMap[type].noYield(objectMode), final)});92- t.deepEqual(stdout, output);93-};94-95-test('Generator can filter "transform" by not calling yield', testNoYield, 'generator', false, false, '', execa);96-test('Generator can filter "transform" by not calling yield, objectMode', testNoYield, 'generator', true, false, [], execa);97-test('Generator can filter "final" by not calling yield', testNoYield, 'generator', false, true, '', execa);98-test('Generator can filter "final" by not calling yield, objectMode', testNoYield, 'generator', true, true, [], execa);99-test('Generator can filter "transform" by not calling yield, sync', testNoYield, 'generator', false, false, '', execaSync);100-test('Generator can filter "transform" by not calling yield, objectMode, sync', testNoYield, 'generator', true, false, [], execaSync);101-test('Generator can filter "final" by not calling yield, sync', testNoYield, 'generator', false, true, '', execaSync);102-test('Generator can filter "final" by not calling yield, objectMode, sync', testNoYield, 'generator', true, true, [], execaSync);103-test('Duplex can filter by not calling push', testNoYield, 'duplex', false, false, '', execa);104-test('Duplex can filter by not calling push, objectMode', testNoYield, 'duplex', true, false, [], execa);105-test('WebTransform can filter by not calling push', testNoYield, 'webTransform', false, false, '', execa);106-test('WebTransform can filter by not calling push, objectMode', testNoYield, 'webTransform', true, false, [], execa);107-108-const testMultipleYields = async (t, type, final, binary) => {109- const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: convertTransformToFinal(generatorsMap[type].multipleYield(), final)});110- const newline = binary ? '' : '\n';111- t.is(stdout, `${prefix}${newline}${foobarString}${newline}${suffix}`);112-};113-114-test('Generator can yield "transform" multiple times at different moments', testMultipleYields, 'generator', false, false);115-test('Generator can yield "final" multiple times at different moments', testMultipleYields, 'generator', true, false);116-test('Duplex can push multiple times at different moments', testMultipleYields, 'duplex', false, true);117-test('WebTransform can push multiple times at different moments', testMultipleYields, 'webTransform', false, true);118-119-const partsPerChunk = 4;120-const chunksPerCall = 10;121-const callCount = 5;122-const fullString = '\n'.repeat(defaultHighWaterMark / partsPerChunk);123-124-const yieldFullStrings = function * () {125- yield * Array.from({length: partsPerChunk * chunksPerCall}).fill(fullString);126-};127-128-const manyYieldGenerator = async function * () {129- for (let index = 0; index < callCount; index += 1) {130- yield * yieldFullStrings();131- // eslint-disable-next-line no-await-in-loop132- await scheduler.yield();133- }134-};135-136-const testManyYields = async (t, final) => {137- const subprocess = execa('noop.js', {stdout: convertTransformToFinal(manyYieldGenerator, final), stripFinalNewline: false});138- const [chunks, {stdout}] = await Promise.all([getStreamAsArray(subprocess.stdout), subprocess]);139- const expectedChunk = Buffer.from(fullString);140- t.deepEqual(chunks, Array.from({length: callCount * partsPerChunk * chunksPerCall}).fill(expectedChunk));141- t.is(chunks.join(''), stdout);142-};143-144-test('Generator "transform" yields are sent right away', testManyYields, false);145-test('Generator "final" yields are sent right away', testManyYields, true);146-147-const testMaxBuffer = async (t, type) => {148- const bigString = '.'.repeat(maxBuffer);149- const {stdout} = await execa('noop.js', {150- maxBuffer,151- stdout: generatorsMap[type].getOutput(bigString)(false, true),152- });153- t.is(stdout, bigString);154-155- const {isMaxBuffer, shortMessage} = await t.throwsAsync(execa('noop.js', {156- maxBuffer,157- stdout: generatorsMap[type].getOutput(`${bigString}.`)(false, true),158- }));159- t.true(isMaxBuffer);160- assertErrorMessage(t, shortMessage);161-};162-163-test('Generators take "maxBuffer" into account', testMaxBuffer, 'generator');164-test('Duplexes take "maxBuffer" into account', testMaxBuffer, 'duplex');165-test('WebTransforms take "maxBuffer" into account', testMaxBuffer, 'webTransform');166-167-test('Generators does not take "maxBuffer" into account, sync', t => {168- const bigString = '.'.repeat(maxBuffer);169- const {isMaxBuffer, stdout} = execaSync('noop.js', {170- maxBuffer,171- stdout: generatorsMap.generator.getOutput(`${bigString}.`)(false, true),172- });173- t.false(isMaxBuffer);174- t.is(stdout.length, maxBuffer + 1);175-});176-177-const testMaxBufferObject = async (t, type) => {178- const bigArray = Array.from({length: maxBuffer}).fill('..');179- const {stdout} = await execa('noop.js', {180- maxBuffer,181- stdout: generatorsMap[type].getOutputs(bigArray)(true, true),182- });183- t.is(stdout.length, maxBuffer);184-185- const {isMaxBuffer, shortMessage} = await t.throwsAsync(execa('noop.js', {186- maxBuffer,187- stdout: generatorsMap[type].getOutputs([...bigArray, ''])(true, true),188- }));189- t.true(isMaxBuffer);190- assertErrorMessage(t, shortMessage, {unit: 'objects'});191-};192-193-test('Generators take "maxBuffer" into account, objectMode', testMaxBufferObject, 'generator');194-test('Duplexes take "maxBuffer" into account, objectMode', testMaxBufferObject, 'duplex');195-test('WebTransforms take "maxBuffer" into account, objectMode', testMaxBufferObject, 'webTransform');196-197-test('Generators does not take "maxBuffer" into account, objectMode, sync', t => {198- const bigArray = Array.from({length: maxBuffer}).fill('..');199- const {isMaxBuffer, stdout} = execaSync('noop.js', {200- maxBuffer,201- stdout: generatorsMap.generator.getOutputs([...bigArray, ''])(true, true),202- });203- t.false(isMaxBuffer);204- t.is(stdout.length, maxBuffer + 1);205-});206-207-const testAsyncGenerators = async (t, type, final) => {208- const {stdout} = await execa('noop.js', {209- stdout: convertTransformToFinal(generatorsMap[type].timeout(1e2)(), final),210- });211- t.is(stdout, foobarString);212-};213-214-test('Generators "transform" is awaited on success', testAsyncGenerators, 'generator', false);215-test('Generators "final" is awaited on success', testAsyncGenerators, 'generator', true);216-test('Duplex is awaited on success', testAsyncGenerators, 'duplex', false);217-test('WebTransform is awaited on success', testAsyncGenerators, 'webTransform', false);218-219-const assertProcessError = async (t, type, execaMethod, getSubprocess) => {220- const cause = new Error(foobarString);221- const transform = generatorsMap[type].throwing(cause)();222- const error = execaMethod === execa223- ? await t.throwsAsync(getSubprocess(transform))224- : t.throws(() => {225- getSubprocess(transform);226- });227- t.is(error.cause, cause);228-};229-230-const testThrowingGenerator = async (t, type, final, execaMethod) => {231- await assertProcessError(t, type, execaMethod, transform => execaMethod('noop.js', {232- stdout: convertTransformToFinal(transform, final),233- }));234-};235-236-test('Generators "transform" errors make subprocess fail', testThrowingGenerator, 'generator', false, execa);237-test('Generators "final" errors make subprocess fail', testThrowingGenerator, 'generator', true, execa);238-test('Generators "transform" errors make subprocess fail, sync', testThrowingGenerator, 'generator', false, execaSync);239-test('Generators "final" errors make subprocess fail, sync', testThrowingGenerator, 'generator', true, execaSync);240-test('Duplexes "transform" errors make subprocess fail', testThrowingGenerator, 'duplex', false, execa);241-test('WebTransform "transform" errors make subprocess fail', testThrowingGenerator, 'webTransform', false, execa);242-243-const testSingleErrorOutput = async (t, type, execaMethod) => {244- await assertProcessError(t, type, execaMethod, transform => execaMethod('noop.js', {245- stdout: [246- generatorsMap[type].noop(false),247- transform,248- generatorsMap[type].noop(false),249- ],250- }));251-};252-253-test('Generators errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'generator', execa);254-test('Generators errors make subprocess fail even when other output generators do not throw, sync', testSingleErrorOutput, 'generator', execaSync);255-test('Duplexes errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'duplex', execa);256-test('WebTransform errors make subprocess fail even when other output generators do not throw', testSingleErrorOutput, 'webTransform', execa);257-258-const testSingleErrorInput = async (t, type, execaMethod) => {259- await assertProcessError(t, type, execaMethod, transform => execaMethod('stdin.js', {260- stdin: [261- ['foobar\n'],262- generatorsMap[type].noop(false),263- transform,264- generatorsMap[type].noop(false),265- ],266- }));267-};268-269-test('Generators errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'generator', execa);270-test('Generators errors make subprocess fail even when other input generators do not throw, sync', testSingleErrorInput, 'generator', execaSync);271-test('Duplexes errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'duplex', execa);272-test('WebTransform errors make subprocess fail even when other input generators do not throw', testSingleErrorInput, 'webTransform', execa);273-274-const testGeneratorCancel = async (t, error) => {275- const subprocess = execa('noop.js', {stdout: infiniteGenerator()});276- await once(subprocess.stdout, 'data');277- subprocess.stdout.destroy(error);278- await (error === undefined ? t.notThrowsAsync(subprocess) : t.throwsAsync(subprocess));279-};280-281-test('Running generators are canceled on subprocess abort', testGeneratorCancel, undefined);282-test('Running generators are canceled on subprocess error', testGeneratorCancel, new Error('test'));283-284-const testGeneratorDestroy = async (t, transform) => {285- const subprocess = execa('forever.js', {stdout: transform});286- const cause = new Error('test');287- subprocess.stdout.destroy(cause);288- subprocess.kill();289- t.like(await t.throwsAsync(subprocess), {cause});290-};291-292-test('Generators are destroyed on subprocess error, sync', testGeneratorDestroy, noopGenerator(false));293-test('Generators are destroyed on subprocess error, async', testGeneratorDestroy, infiniteGenerator());294-295-test('Generators are destroyed on early subprocess exit', async t => {296- await t.throwsAsync(execa('noop.js', {stdout: infiniteGenerator(), uid: -1}));297-});added:test/stream/buffer-end.js+78 added
1+import {once} from 'node:events';2+import {setTimeout} from 'node:timers/promises';3+import test from 'ava';4+import {execa} from '../../index.js';5+import {setFixtureDir} from '../helpers/fixtures-dir.js';6+import {fullStdio, getStdio} from '../helpers/stdio.js';7+8+setFixtureDir();9+10+const testBufferIgnore = async (t, fdNumber, all) => {11+ await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`], {...getStdio(fdNumber, 'ignore'), buffer: false, all}));12+};13+14+test('Subprocess buffers stdout, which does not prevent exit if ignored', testBufferIgnore, 1, false);15+test('Subprocess buffers stderr, which does not prevent exit if ignored', testBufferIgnore, 2, false);16+test('Subprocess buffers all, which does not prevent exit if ignored', testBufferIgnore, 1, true);17+18+const testBufferNotRead = async (t, fdNumber, all) => {19+ const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});20+ await t.notThrowsAsync(subprocess);21+};22+23+test('Subprocess buffers stdout, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, false);24+test('Subprocess buffers stderr, which does not prevent exit if not read and buffer is false', testBufferNotRead, 2, false);25+test('Subprocess buffers stdio[*], which does not prevent exit if not read and buffer is false', testBufferNotRead, 3, false);26+test('Subprocess buffers all, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, true);27+28+const testBufferRead = async (t, fdNumber, all) => {29+ const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});30+ const stream = all ? subprocess.all : subprocess.stdio[fdNumber];31+ stream.resume();32+ await t.notThrowsAsync(subprocess);33+};34+35+test('Subprocess buffers stdout, which does not prevent exit if read and buffer is false', testBufferRead, 1, false);36+test('Subprocess buffers stderr, which does not prevent exit if read and buffer is false', testBufferRead, 2, false);37+test('Subprocess buffers stdio[*], which does not prevent exit if read and buffer is false', testBufferRead, 3, false);38+test('Subprocess buffers all, which does not prevent exit if read and buffer is false', testBufferRead, 1, true);39+40+const testBufferExit = async (t, fdNumber, fixtureName, reject) => {41+ const subprocess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});42+ await setTimeout(100);43+ const {stdio} = await subprocess;44+ t.is(stdio[fdNumber], 'foobar');45+};46+47+test('Subprocess buffers stdout before it is read', testBufferExit, 1, 'noop-delay.js', true);48+test('Subprocess buffers stderr before it is read', testBufferExit, 2, 'noop-delay.js', true);49+test('Subprocess buffers stdio[*] before it is read', testBufferExit, 3, 'noop-delay.js', true);50+test('Subprocess buffers stdout right away, on successfully exit', testBufferExit, 1, 'noop-fd.js', true);51+test('Subprocess buffers stderr right away, on successfully exit', testBufferExit, 2, 'noop-fd.js', true);52+test('Subprocess buffers stdio[*] right away, on successfully exit', testBufferExit, 3, 'noop-fd.js', true);53+test('Subprocess buffers stdout right away, on failure', testBufferExit, 1, 'noop-fail.js', false);54+test('Subprocess buffers stderr right away, on failure', testBufferExit, 2, 'noop-fail.js', false);55+test('Subprocess buffers stdio[*] right away, on failure', testBufferExit, 3, 'noop-fail.js', false);56+57+const testBufferDirect = async (t, fdNumber) => {58+ const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);59+ const data = await once(subprocess.stdio[fdNumber], 'data');60+ t.is(data.toString().trim(), 'foobar');61+ const result = await subprocess;62+ t.is(result.stdio[fdNumber], 'foobar');63+};64+65+test('Subprocess buffers stdout right away, even if directly read', testBufferDirect, 1);66+test('Subprocess buffers stderr right away, even if directly read', testBufferDirect, 2);67+test('Subprocess buffers stdio[*] right away, even if directly read', testBufferDirect, 3);68+69+const testBufferDestroyOnEnd = async (t, fdNumber) => {70+ const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);71+ const result = await subprocess;72+ t.is(result.stdio[fdNumber], 'foobar');73+ t.true(subprocess.stdio[fdNumber].destroyed);74+};75+76+test('subprocess.stdout must be read right away', testBufferDestroyOnEnd, 1);77+test('subprocess.stderr must be read right away', testBufferDestroyOnEnd, 2);78+test('subprocess.stdio[*] must be read right away', testBufferDestroyOnEnd, 3);modified:test/stream/exit.js+67 added-60 removed
1-import {once} from 'node:events';2-import {setTimeout} from 'node:timers/promises';1+import process from 'node:process';2 import test from 'ava';3 import {execa} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';6-import {fullStdio, getStdio} from '../helpers/stdio.js';5 6+const isWindows = process.platform === 'win32';7+8 setFixtureDir();9 10-const testBufferIgnore = async (t, fdNumber, all) => {11- await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`], {...getStdio(fdNumber, 'ignore'), buffer: false, all}));10+test('exitCode is 0 on success', async t => {11+ const {exitCode} = await execa('noop.js', ['foo']);12+ t.is(exitCode, 0);13+});14+15+const testExitCode = async (t, expectedExitCode) => {16+ const {exitCode, originalMessage, shortMessage, message} = await t.throwsAsync(17+ execa('exit.js', [`${expectedExitCode}`]),18+ );19+ t.is(exitCode, expectedExitCode);20+ t.is(originalMessage, '');21+ t.is(shortMessage, `Command failed with exit code ${expectedExitCode}: exit.js ${expectedExitCode}`);22+ t.is(message, shortMessage);23 };24 14-test('Subprocess buffers stdout, which does not prevent exit if ignored', testBufferIgnore, 1, false);15-test('Subprocess buffers stderr, which does not prevent exit if ignored', testBufferIgnore, 2, false);16-test('Subprocess buffers all, which does not prevent exit if ignored', testBufferIgnore, 1, true);25+test('exitCode is 2', testExitCode, 2);26+test('exitCode is 3', testExitCode, 3);27+test('exitCode is 4', testExitCode, 4);28 18-const testBufferNotRead = async (t, fdNumber, all) => {19- const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});20- await t.notThrowsAsync(subprocess);21-};29+if (!isWindows) {30+ test('error.signal is SIGINT', async t => {31+ const subprocess = execa('forever.js');32 23-test('Subprocess buffers stdout, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, false);24-test('Subprocess buffers stderr, which does not prevent exit if not read and buffer is false', testBufferNotRead, 2, false);25-test('Subprocess buffers stdio[*], which does not prevent exit if not read and buffer is false', testBufferNotRead, 3, false);26-test('Subprocess buffers all, which does not prevent exit if not read and buffer is false', testBufferNotRead, 1, true);33+ process.kill(subprocess.pid, 'SIGINT');34 28-const testBufferRead = async (t, fdNumber, all) => {29- const subprocess = execa('max-buffer.js', [`${fdNumber}`], {...fullStdio, buffer: false, all});30- const stream = all ? subprocess.all : subprocess.stdio[fdNumber];31- stream.resume();32- await t.notThrowsAsync(subprocess);33-};35+ const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});36+ t.is(signal, 'SIGINT');37+ });38 35-test('Subprocess buffers stdout, which does not prevent exit if read and buffer is false', testBufferRead, 1, false);36-test('Subprocess buffers stderr, which does not prevent exit if read and buffer is false', testBufferRead, 2, false);37-test('Subprocess buffers stdio[*], which does not prevent exit if read and buffer is false', testBufferRead, 3, false);38-test('Subprocess buffers all, which does not prevent exit if read and buffer is false', testBufferRead, 1, true);39+ test('error.signalDescription is defined', async t => {40+ const subprocess = execa('forever.js');41 40-const testBufferExit = async (t, fdNumber, fixtureName, reject) => {41- const subprocess = execa(fixtureName, [`${fdNumber}`], {...fullStdio, reject});42- await setTimeout(100);43- const {stdio} = await subprocess;44- t.is(stdio[fdNumber], 'foobar');45-};42+ process.kill(subprocess.pid, 'SIGINT');43 47-test('Subprocess buffers stdout before it is read', testBufferExit, 1, 'noop-delay.js', true);48-test('Subprocess buffers stderr before it is read', testBufferExit, 2, 'noop-delay.js', true);49-test('Subprocess buffers stdio[*] before it is read', testBufferExit, 3, 'noop-delay.js', true);50-test('Subprocess buffers stdout right away, on successfully exit', testBufferExit, 1, 'noop-fd.js', true);51-test('Subprocess buffers stderr right away, on successfully exit', testBufferExit, 2, 'noop-fd.js', true);52-test('Subprocess buffers stdio[*] right away, on successfully exit', testBufferExit, 3, 'noop-fd.js', true);53-test('Subprocess buffers stdout right away, on failure', testBufferExit, 1, 'noop-fail.js', false);54-test('Subprocess buffers stderr right away, on failure', testBufferExit, 2, 'noop-fail.js', false);55-test('Subprocess buffers stdio[*] right away, on failure', testBufferExit, 3, 'noop-fail.js', false);44+ const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});45+ t.is(signalDescription, 'User interruption with CTRL-C');46+ });47 57-const testBufferDirect = async (t, fdNumber) => {58- const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);59- const data = await once(subprocess.stdio[fdNumber], 'data');60- t.is(data.toString().trim(), 'foobar');61- const result = await subprocess;62- t.is(result.stdio[fdNumber], 'foobar');63-};48+ test('error.signal is SIGTERM', async t => {49+ const subprocess = execa('forever.js');50 65-test('Subprocess buffers stdout right away, even if directly read', testBufferDirect, 1);66-test('Subprocess buffers stderr right away, even if directly read', testBufferDirect, 2);67-test('Subprocess buffers stdio[*] right away, even if directly read', testBufferDirect, 3);51+ process.kill(subprocess.pid, 'SIGTERM');52 69-const testBufferDestroyOnEnd = async (t, fdNumber) => {70- const subprocess = execa('noop-fd.js', [`${fdNumber}`], fullStdio);71- const result = await subprocess;72- t.is(result.stdio[fdNumber], 'foobar');73- t.true(subprocess.stdio[fdNumber].destroyed);74-};53+ const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});54+ t.is(signal, 'SIGTERM');55+ });56 76-test('subprocess.stdout must be read right away', testBufferDestroyOnEnd, 1);77-test('subprocess.stderr must be read right away', testBufferDestroyOnEnd, 2);78-test('subprocess.stdio[*] must be read right away', testBufferDestroyOnEnd, 3);57+ test('error.signal uses killSignal', async t => {58+ const {signal} = await t.throwsAsync(execa('forever.js', {killSignal: 'SIGINT', timeout: 1, message: /timed out after/}));59+ t.is(signal, 'SIGINT');60+ });61+62+ test('exitCode is undefined on signal termination', async t => {63+ const subprocess = execa('forever.js');64+65+ process.kill(subprocess.pid);66+67+ const {exitCode} = await t.throwsAsync(subprocess);68+ t.is(exitCode, undefined);69+ });70+}71+72+test('result.signal is undefined for successful execution', async t => {73+ const {signal} = await execa('noop.js');74+ t.is(signal, undefined);75+});76+77+test('result.signal is undefined if subprocess failed, but was not killed', async t => {78+ const {signal} = await t.throwsAsync(execa('fail.js'));79+ t.is(signal, undefined);80+});81+82+test('result.signalDescription is undefined for successful execution', async t => {83+ const {signalDescription} = await execa('noop.js');84+ t.is(signalDescription, undefined);85+});modified:test/stream/no-buffer.js-32 removed
143 unmodified lines144 test('buffer: {stdout: false}, all: true, sync', testNoOutputAll, {stdout: false}, false, true, execaSync);145 test('buffer: {stderr: false}, all: true, sync', testNoOutputAll, {stderr: false}, true, false, execaSync);146 test('buffer: {all: false}, all: true, sync', testNoOutputAll, {all: false}, false, false, execaSync);147 148-// eslint-disable-next-line max-params149-const testPriorityOrder = async (t, buffer, bufferStdout, bufferStderr, execaMethod) => {150- const {stdout, stderr} = await execaMethod('noop-both.js', {buffer});151- t.is(stdout, bufferStdout ? foobarString : undefined);152- t.is(stderr, bufferStderr ? foobarString : undefined);153-};154-155-test('buffer: {stdout, fd1}', testPriorityOrder, {stdout: true, fd1: false}, true, true, execa);156-test('buffer: {stdout, all}', testPriorityOrder, {stdout: true, all: false}, true, false, execa);157-test('buffer: {fd1, all}', testPriorityOrder, {fd1: true, all: false}, true, false, execa);158-test('buffer: {stderr, fd2}', testPriorityOrder, {stderr: true, fd2: false}, true, true, execa);159-test('buffer: {stderr, all}', testPriorityOrder, {stderr: true, all: false}, false, true, execa);160-test('buffer: {fd2, all}', testPriorityOrder, {fd2: true, all: false}, false, true, execa);161-test('buffer: {fd1, stdout}', testPriorityOrder, {fd1: false, stdout: true}, true, true, execa);162-test('buffer: {all, stdout}', testPriorityOrder, {all: false, stdout: true}, true, false, execa);163-test('buffer: {all, fd1}', testPriorityOrder, {all: false, fd1: true}, true, false, execa);164-test('buffer: {fd2, stderr}', testPriorityOrder, {fd2: false, stderr: true}, true, true, execa);165-test('buffer: {all, stderr}', testPriorityOrder, {all: false, stderr: true}, false, true, execa);166-test('buffer: {all, fd2}', testPriorityOrder, {all: false, fd2: true}, false, true, execa);167-test('buffer: {stdout, fd1}, sync', testPriorityOrder, {stdout: true, fd1: false}, true, true, execaSync);168-test('buffer: {stdout, all}, sync', testPriorityOrder, {stdout: true, all: false}, true, false, execaSync);169-test('buffer: {fd1, all}, sync', testPriorityOrder, {fd1: true, all: false}, true, false, execaSync);170-test('buffer: {stderr, fd2}, sync', testPriorityOrder, {stderr: true, fd2: false}, true, true, execaSync);171-test('buffer: {stderr, all}, sync', testPriorityOrder, {stderr: true, all: false}, false, true, execaSync);172-test('buffer: {fd2, all}, sync', testPriorityOrder, {fd2: true, all: false}, false, true, execaSync);173-test('buffer: {fd1, stdout}, sync', testPriorityOrder, {fd1: false, stdout: true}, true, true, execaSync);174-test('buffer: {all, stdout}, sync', testPriorityOrder, {all: false, stdout: true}, true, false, execaSync);175-test('buffer: {all, fd1}, sync', testPriorityOrder, {all: false, fd1: true}, true, false, execaSync);176-test('buffer: {fd2, stderr}, sync', testPriorityOrder, {fd2: false, stderr: true}, true, true, execaSync);177-test('buffer: {all, stderr}, sync', testPriorityOrder, {all: false, stderr: true}, false, true, execaSync);178-test('buffer: {all, fd2}, sync', testPriorityOrder, {all: false, fd2: true}, false, true, execaSync);179-148 const testTransform = async (t, objectMode, execaMethod) => {149 const lines = [];150 const {stdout} = await execaMethod('noop.js', {151 buffer: false,41 unmodified linesadded:test/stream/wait-abort.js+99 added
1+import {setImmediate} from 'node:timers/promises';2+import test from 'ava';3+import {execa} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {prematureClose} from '../helpers/stdio.js';6+import {noopReadable, noopWritable, noopDuplex} from '../helpers/stream.js';7+import {endOptionStream, destroyOptionStream, destroySubprocessStream, getStreamStdio} from '../helpers/wait.js';8+9+setFixtureDir();10+11+const noop = () => {};12+13+// eslint-disable-next-line max-params14+const testStreamAbortWait = async (t, streamMethod, stream, fdNumber, useTransform) => {15+ const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));16+ streamMethod({stream, subprocess, fdNumber});17+ subprocess.stdin.end();18+ await setImmediate();19+ stream.destroy();20+21+ const {stdout} = await subprocess;22+ t.is(stdout, '');23+ t.true(stream.destroyed);24+};25+26+test('Keeps running when stdin option is used and subprocess.stdin ends', testStreamAbortWait, noop, noopReadable(), 0, false);27+test('Keeps running when stdin option is used and subprocess.stdin Duplex ends', testStreamAbortWait, noop, noopDuplex(), 0, false);28+test('Keeps running when input stdio[*] option is used and input subprocess.stdio[*] ends', testStreamAbortWait, noop, noopReadable(), 3, false);29+test('Keeps running when stdin option is used and subprocess.stdin ends, with a transform', testStreamAbortWait, noop, noopReadable(), 0, true);30+test('Keeps running when stdin option is used and subprocess.stdin Duplex ends, with a transform', testStreamAbortWait, noop, noopDuplex(), 0, true);31+test('Keeps running when input stdio[*] option is used and input subprocess.stdio[*] ends, with a transform', testStreamAbortWait, noop, noopReadable(), 3, true);32+33+// eslint-disable-next-line max-params34+const testStreamAbortSuccess = async (t, streamMethod, stream, fdNumber, useTransform) => {35+ const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));36+ streamMethod({stream, subprocess, fdNumber});37+ subprocess.stdin.end();38+39+ const {stdout} = await subprocess;40+ t.is(stdout, '');41+ t.true(stream.destroyed);42+};43+44+test('Passes when stdin option aborts', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 0, false);45+test('Passes when stdin option Duplex aborts', testStreamAbortSuccess, destroyOptionStream, noopDuplex(), 0, false);46+test('Passes when input stdio[*] option aborts', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 3, false);47+test('Passes when stdout option ends with no more writes', testStreamAbortSuccess, endOptionStream, noopWritable(), 1, false);48+test('Passes when stderr option ends with no more writes', testStreamAbortSuccess, endOptionStream, noopWritable(), 2, false);49+test('Passes when output stdio[*] option ends with no more writes', testStreamAbortSuccess, endOptionStream, noopWritable(), 3, false);50+test('Passes when subprocess.stdout aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 1, false);51+test('Passes when subprocess.stdout Duplex aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 1, false);52+test('Passes when subprocess.stderr aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 2, false);53+test('Passes when subprocess.stderr Duplex aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 2, false);54+test('Passes when output subprocess.stdio[*] aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 3, false);55+test('Passes when output subprocess.stdio[*] Duplex aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 3, false);56+test('Passes when stdin option aborts, with a transform', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 0, true);57+test('Passes when stdin option Duplex aborts, with a transform', testStreamAbortSuccess, destroyOptionStream, noopDuplex(), 0, true);58+test('Passes when input stdio[*] option aborts, with a transform', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 3, true);59+test('Passes when stdout option ends with no more writes, with a transform', testStreamAbortSuccess, endOptionStream, noopWritable(), 1, true);60+test('Passes when stderr option ends with no more writes, with a transform', testStreamAbortSuccess, endOptionStream, noopWritable(), 2, true);61+test('Passes when output stdio[*] option ends with no more writes, with a transform', testStreamAbortSuccess, endOptionStream, noopWritable(), 3, true);62+test('Passes when subprocess.stdout aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 1, true);63+test('Passes when subprocess.stdout Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 1, true);64+test('Passes when subprocess.stderr aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 2, true);65+test('Passes when subprocess.stderr Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 2, true);66+test('Passes when output subprocess.stdio[*] aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 3, true);67+test('Passes when output subprocess.stdio[*] Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 3, true);68+69+// eslint-disable-next-line max-params70+const testStreamAbortFail = async (t, streamMethod, stream, fdNumber, useTransform) => {71+ const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));72+ streamMethod({stream, subprocess, fdNumber});73+ if (fdNumber !== 0) {74+ subprocess.stdin.end();75+ }76+77+ const error = await t.throwsAsync(subprocess);78+ t.like(error, {...prematureClose, exitCode: 0});79+ t.true(stream.destroyed);80+};81+82+test('Throws abort error when subprocess.stdin aborts', testStreamAbortFail, destroySubprocessStream, noopReadable(), 0, false);83+test('Throws abort error when subprocess.stdin Duplex aborts', testStreamAbortFail, destroySubprocessStream, noopDuplex(), 0, false);84+test('Throws abort error when input subprocess.stdio[*] aborts', testStreamAbortFail, destroySubprocessStream, noopReadable(), 3, false);85+test('Throws abort error when stdout option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopWritable(), 1, false);86+test('Throws abort error when stdout option Duplex aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopDuplex(), 1, false);87+test('Throws abort error when stderr option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopWritable(), 2, false);88+test('Throws abort error when stderr option Duplex aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopDuplex(), 2, false);89+test('Throws abort error when output stdio[*] option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopWritable(), 3, false);90+test('Throws abort error when output stdio[*] Duplex option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopDuplex(), 3, false);91+test('Throws abort error when subprocess.stdin aborts, with a transform', testStreamAbortFail, destroySubprocessStream, noopReadable(), 0, true);92+test('Throws abort error when subprocess.stdin Duplex aborts, with a transform', testStreamAbortFail, destroySubprocessStream, noopDuplex(), 0, true);93+test('Throws abort error when input subprocess.stdio[*] aborts, with a transform', testStreamAbortFail, destroySubprocessStream, noopReadable(), 3, true);94+test('Throws abort error when stdout option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 1, true);95+test('Throws abort error when stdout option Duplex aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 1, true);96+test('Throws abort error when stderr option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 2, true);97+test('Throws abort error when stderr option Duplex aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 2, true);98+test('Throws abort error when output stdio[*] option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 3, true);99+test('Throws abort error when output stdio[*] Duplex option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 3, true);added:test/stream/wait-epipe.js+55 added
1+import {setImmediate} from 'node:timers/promises';2+import test from 'ava';3+import {execa} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {assertEpipe} from '../helpers/stdio.js';6+import {foobarString} from '../helpers/input.js';7+import {noopWritable, noopDuplex} from '../helpers/stream.js';8+import {endOptionStream, destroyOptionStream, destroySubprocessStream, getStreamStdio} from '../helpers/wait.js';9+10+setFixtureDir();11+12+// eslint-disable-next-line max-params13+const testStreamEpipeFail = async (t, streamMethod, stream, fdNumber, useTransform) => {14+ const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));15+ streamMethod({stream, subprocess, fdNumber});16+ await setImmediate();17+ subprocess.stdin.end(foobarString);18+19+ const {exitCode, stdio, stderr} = await t.throwsAsync(subprocess);20+ t.is(exitCode, 1);21+ t.is(stdio[fdNumber], '');22+ t.true(stream.destroyed);23+ assertEpipe(t, stderr, fdNumber);24+};25+26+test('Throws EPIPE when stdout option ends with more writes', testStreamEpipeFail, endOptionStream, noopWritable(), 1, false);27+test('Throws EPIPE when stdout option aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopWritable(), 1, false);28+test('Throws EPIPE when stdout option Duplex aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 1, false);29+test('Throws EPIPE when stderr option ends with more writes', testStreamEpipeFail, endOptionStream, noopWritable(), 2, false);30+test('Throws EPIPE when stderr option aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopWritable(), 2, false);31+test('Throws EPIPE when stderr option Duplex aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 2, false);32+test('Throws EPIPE when output stdio[*] option ends with more writes', testStreamEpipeFail, endOptionStream, noopWritable(), 3, false);33+test('Throws EPIPE when output stdio[*] option aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopWritable(), 3, false);34+test('Throws EPIPE when output stdio[*] option Duplex aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 3, false);35+test('Throws EPIPE when subprocess.stdout aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 1, false);36+test('Throws EPIPE when subprocess.stdout Duplex aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 1, false);37+test('Throws EPIPE when subprocess.stderr aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 2, false);38+test('Throws EPIPE when subprocess.stderr Duplex aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 2, false);39+test('Throws EPIPE when output subprocess.stdio[*] aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 3, false);40+test('Throws EPIPE when output subprocess.stdio[*] Duplex aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 3, false);41+test('Throws EPIPE when stdout option ends with more writes, with a transform', testStreamEpipeFail, endOptionStream, noopWritable(), 1, true);42+test('Throws EPIPE when stdout option aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopWritable(), 1, true);43+test('Throws EPIPE when stdout option Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 1, true);44+test('Throws EPIPE when stderr option ends with more writes, with a transform', testStreamEpipeFail, endOptionStream, noopWritable(), 2, true);45+test('Throws EPIPE when stderr option aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopWritable(), 2, true);46+test('Throws EPIPE when stderr option Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 2, true);47+test('Throws EPIPE when output stdio[*] option ends with more writes, with a transform', testStreamEpipeFail, endOptionStream, noopWritable(), 3, true);48+test('Throws EPIPE when output stdio[*] option aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopWritable(), 3, true);49+test('Throws EPIPE when output stdio[*] option Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 3, true);50+test('Throws EPIPE when subprocess.stdout aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 1, true);51+test('Throws EPIPE when subprocess.stdout Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 1, true);52+test('Throws EPIPE when subprocess.stderr aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 2, true);53+test('Throws EPIPE when subprocess.stderr Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 2, true);54+test('Throws EPIPE when output subprocess.stdio[*] aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 3, true);55+test('Throws EPIPE when output subprocess.stdio[*] Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 3, true);added:test/stream/wait-error.js+59 added
1+import test from 'ava';2+import {execa} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {noopReadable, noopWritable, noopDuplex} from '../helpers/stream.js';5+import {destroyOptionStream, destroySubprocessStream, getStreamStdio} from '../helpers/wait.js';6+7+setFixtureDir();8+9+// eslint-disable-next-line max-params10+const testStreamError = async (t, streamMethod, stream, fdNumber, useTransform) => {11+ const subprocess = execa('empty.js', getStreamStdio(fdNumber, stream, useTransform));12+ const cause = new Error('test');13+ streamMethod({stream, subprocess, fdNumber, error: cause});14+15+ const error = await t.throwsAsync(subprocess);16+ t.is(error.cause, cause);17+ t.is(error.exitCode, 0);18+ t.is(error.signal, undefined);19+ t.false(error.isTerminated);20+ t.true(error.failed);21+ t.true(stream.destroyed);22+};23+24+test('Throws stream error when stdin option errors', testStreamError, destroyOptionStream, noopReadable(), 0, false);25+test('Throws stream error when stdin option Duplex errors', testStreamError, destroyOptionStream, noopDuplex(), 0, false);26+test('Throws stream error when stdout option errors', testStreamError, destroyOptionStream, noopWritable(), 1, false);27+test('Throws stream error when stdout option Duplex errors', testStreamError, destroyOptionStream, noopDuplex(), 1, false);28+test('Throws stream error when stderr option errors', testStreamError, destroyOptionStream, noopWritable(), 2, false);29+test('Throws stream error when stderr option Duplex errors', testStreamError, destroyOptionStream, noopDuplex(), 2, false);30+test('Throws stream error when output stdio[*] option errors', testStreamError, destroyOptionStream, noopWritable(), 3, false);31+test('Throws stream error when output stdio[*] Duplex option errors', testStreamError, destroyOptionStream, noopDuplex(), 3, false);32+test('Throws stream error when input stdio[*] option errors', testStreamError, destroyOptionStream, noopReadable(), 3, false);33+test('Throws stream error when subprocess.stdin errors', testStreamError, destroySubprocessStream, noopReadable(), 0, false);34+test('Throws stream error when subprocess.stdin Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 0, false);35+test('Throws stream error when subprocess.stdout errors', testStreamError, destroySubprocessStream, noopWritable(), 1, false);36+test('Throws stream error when subprocess.stdout Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 1, false);37+test('Throws stream error when subprocess.stderr errors', testStreamError, destroySubprocessStream, noopWritable(), 2, false);38+test('Throws stream error when subprocess.stderr Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 2, false);39+test('Throws stream error when output subprocess.stdio[*] errors', testStreamError, destroySubprocessStream, noopWritable(), 3, false);40+test('Throws stream error when output subprocess.stdio[*] Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 3, false);41+test('Throws stream error when input subprocess.stdio[*] errors', testStreamError, destroySubprocessStream, noopReadable(), 3, false);42+test('Throws stream error when stdin option errors, with a transform', testStreamError, destroyOptionStream, noopReadable(), 0, true);43+test('Throws stream error when stdin option Duplex errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 0, true);44+test('Throws stream error when stdout option errors, with a transform', testStreamError, destroyOptionStream, noopWritable(), 1, true);45+test('Throws stream error when stdout option Duplex errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 1, true);46+test('Throws stream error when stderr option errors, with a transform', testStreamError, destroyOptionStream, noopWritable(), 2, true);47+test('Throws stream error when stderr option Duplex errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 2, true);48+test('Throws stream error when output stdio[*] option errors, with a transform', testStreamError, destroyOptionStream, noopWritable(), 3, true);49+test('Throws stream error when output stdio[*] Duplex option errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 3, true);50+test('Throws stream error when input stdio[*] option errors, with a transform', testStreamError, destroyOptionStream, noopReadable(), 3, true);51+test('Throws stream error when subprocess.stdin errors, with a transform', testStreamError, destroySubprocessStream, noopReadable(), 0, true);52+test('Throws stream error when subprocess.stdin Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 0, true);53+test('Throws stream error when subprocess.stdout errors, with a transform', testStreamError, destroySubprocessStream, noopWritable(), 1, true);54+test('Throws stream error when subprocess.stdout Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 1, true);55+test('Throws stream error when subprocess.stderr errors, with a transform', testStreamError, destroySubprocessStream, noopWritable(), 2, true);56+test('Throws stream error when subprocess.stderr Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 2, true);57+test('Throws stream error when output subprocess.stdio[*] errors, with a transform', testStreamError, destroySubprocessStream, noopWritable(), 3, true);58+test('Throws stream error when output subprocess.stdio[*] Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 3, true);59+test('Throws stream error when input subprocess.stdio[*] errors, with a transform', testStreamError, destroySubprocessStream, noopReadable(), 3, true);deleted:test/stream/wait.js-211 removed
1-import {setImmediate} from 'node:timers/promises';2-import test from 'ava';3-import {execa} from '../../index.js';4-import {setFixtureDir} from '../helpers/fixtures-dir.js';5-import {getStdio, prematureClose, assertEpipe} from '../helpers/stdio.js';6-import {foobarString} from '../helpers/input.js';7-import {noopGenerator} from '../helpers/generator.js';8-import {noopReadable, noopWritable, noopDuplex} from '../helpers/stream.js';9-10-setFixtureDir();11-12-const noop = () => {};13-14-const endOptionStream = ({stream}) => {15- stream.end();16-};17-18-const destroyOptionStream = ({stream, error}) => {19- stream.destroy(error);20-};21-22-const destroySubprocessStream = ({subprocess, fdNumber, error}) => {23- subprocess.stdio[fdNumber].destroy(error);24-};25-26-const getStreamStdio = (fdNumber, stream, useTransform) => getStdio(fdNumber, [stream, useTransform ? noopGenerator(false) : 'pipe']);27-28-// eslint-disable-next-line max-params29-const testStreamAbortWait = async (t, streamMethod, stream, fdNumber, useTransform) => {30- const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));31- streamMethod({stream, subprocess, fdNumber});32- subprocess.stdin.end();33- await setImmediate();34- stream.destroy();35-36- const {stdout} = await subprocess;37- t.is(stdout, '');38- t.true(stream.destroyed);39-};40-41-test('Keeps running when stdin option is used and subprocess.stdin ends', testStreamAbortWait, noop, noopReadable(), 0, false);42-test('Keeps running when stdin option is used and subprocess.stdin Duplex ends', testStreamAbortWait, noop, noopDuplex(), 0, false);43-test('Keeps running when input stdio[*] option is used and input subprocess.stdio[*] ends', testStreamAbortWait, noop, noopReadable(), 3, false);44-test('Keeps running when stdin option is used and subprocess.stdin ends, with a transform', testStreamAbortWait, noop, noopReadable(), 0, true);45-test('Keeps running when stdin option is used and subprocess.stdin Duplex ends, with a transform', testStreamAbortWait, noop, noopDuplex(), 0, true);46-test('Keeps running when input stdio[*] option is used and input subprocess.stdio[*] ends, with a transform', testStreamAbortWait, noop, noopReadable(), 3, true);47-48-// eslint-disable-next-line max-params49-const testStreamAbortSuccess = async (t, streamMethod, stream, fdNumber, useTransform) => {50- const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));51- streamMethod({stream, subprocess, fdNumber});52- subprocess.stdin.end();53-54- const {stdout} = await subprocess;55- t.is(stdout, '');56- t.true(stream.destroyed);57-};58-59-test('Passes when stdin option aborts', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 0, false);60-test('Passes when stdin option Duplex aborts', testStreamAbortSuccess, destroyOptionStream, noopDuplex(), 0, false);61-test('Passes when input stdio[*] option aborts', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 3, false);62-test('Passes when stdout option ends with no more writes', testStreamAbortSuccess, endOptionStream, noopWritable(), 1, false);63-test('Passes when stderr option ends with no more writes', testStreamAbortSuccess, endOptionStream, noopWritable(), 2, false);64-test('Passes when output stdio[*] option ends with no more writes', testStreamAbortSuccess, endOptionStream, noopWritable(), 3, false);65-test('Passes when subprocess.stdout aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 1, false);66-test('Passes when subprocess.stdout Duplex aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 1, false);67-test('Passes when subprocess.stderr aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 2, false);68-test('Passes when subprocess.stderr Duplex aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 2, false);69-test('Passes when output subprocess.stdio[*] aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 3, false);70-test('Passes when output subprocess.stdio[*] Duplex aborts with no more writes', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 3, false);71-test('Passes when stdin option aborts, with a transform', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 0, true);72-test('Passes when stdin option Duplex aborts, with a transform', testStreamAbortSuccess, destroyOptionStream, noopDuplex(), 0, true);73-test('Passes when input stdio[*] option aborts, with a transform', testStreamAbortSuccess, destroyOptionStream, noopReadable(), 3, true);74-test('Passes when stdout option ends with no more writes, with a transform', testStreamAbortSuccess, endOptionStream, noopWritable(), 1, true);75-test('Passes when stderr option ends with no more writes, with a transform', testStreamAbortSuccess, endOptionStream, noopWritable(), 2, true);76-test('Passes when output stdio[*] option ends with no more writes, with a transform', testStreamAbortSuccess, endOptionStream, noopWritable(), 3, true);77-test('Passes when subprocess.stdout aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 1, true);78-test('Passes when subprocess.stdout Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 1, true);79-test('Passes when subprocess.stderr aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 2, true);80-test('Passes when subprocess.stderr Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 2, true);81-test('Passes when output subprocess.stdio[*] aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopWritable(), 3, true);82-test('Passes when output subprocess.stdio[*] Duplex aborts with no more writes, with a transform', testStreamAbortSuccess, destroySubprocessStream, noopDuplex(), 3, true);83-84-// eslint-disable-next-line max-params85-const testStreamAbortFail = async (t, streamMethod, stream, fdNumber, useTransform) => {86- const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));87- streamMethod({stream, subprocess, fdNumber});88- if (fdNumber !== 0) {89- subprocess.stdin.end();90- }91-92- const error = await t.throwsAsync(subprocess);93- t.like(error, {...prematureClose, exitCode: 0});94- t.true(stream.destroyed);95-};96-97-test('Throws abort error when subprocess.stdin aborts', testStreamAbortFail, destroySubprocessStream, noopReadable(), 0, false);98-test('Throws abort error when subprocess.stdin Duplex aborts', testStreamAbortFail, destroySubprocessStream, noopDuplex(), 0, false);99-test('Throws abort error when input subprocess.stdio[*] aborts', testStreamAbortFail, destroySubprocessStream, noopReadable(), 3, false);100-test('Throws abort error when stdout option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopWritable(), 1, false);101-test('Throws abort error when stdout option Duplex aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopDuplex(), 1, false);102-test('Throws abort error when stderr option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopWritable(), 2, false);103-test('Throws abort error when stderr option Duplex aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopDuplex(), 2, false);104-test('Throws abort error when output stdio[*] option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopWritable(), 3, false);105-test('Throws abort error when output stdio[*] Duplex option aborts with no more writes', testStreamAbortFail, destroyOptionStream, noopDuplex(), 3, false);106-test('Throws abort error when subprocess.stdin aborts, with a transform', testStreamAbortFail, destroySubprocessStream, noopReadable(), 0, true);107-test('Throws abort error when subprocess.stdin Duplex aborts, with a transform', testStreamAbortFail, destroySubprocessStream, noopDuplex(), 0, true);108-test('Throws abort error when input subprocess.stdio[*] aborts, with a transform', testStreamAbortFail, destroySubprocessStream, noopReadable(), 3, true);109-test('Throws abort error when stdout option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 1, true);110-test('Throws abort error when stdout option Duplex aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 1, true);111-test('Throws abort error when stderr option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 2, true);112-test('Throws abort error when stderr option Duplex aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 2, true);113-test('Throws abort error when output stdio[*] option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopWritable(), 3, true);114-test('Throws abort error when output stdio[*] Duplex option aborts with no more writes, with a transform', testStreamAbortFail, destroyOptionStream, noopDuplex(), 3, true);115-116-// eslint-disable-next-line max-params117-const testStreamEpipeFail = async (t, streamMethod, stream, fdNumber, useTransform) => {118- const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));119- streamMethod({stream, subprocess, fdNumber});120- await setImmediate();121- subprocess.stdin.end(foobarString);122-123- const {exitCode, stdio, stderr} = await t.throwsAsync(subprocess);124- t.is(exitCode, 1);125- t.is(stdio[fdNumber], '');126- t.true(stream.destroyed);127- assertEpipe(t, stderr, fdNumber);128-};129-130-test('Throws EPIPE when stdout option ends with more writes', testStreamEpipeFail, endOptionStream, noopWritable(), 1, false);131-test('Throws EPIPE when stdout option aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopWritable(), 1, false);132-test('Throws EPIPE when stdout option Duplex aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 1, false);133-test('Throws EPIPE when stderr option ends with more writes', testStreamEpipeFail, endOptionStream, noopWritable(), 2, false);134-test('Throws EPIPE when stderr option aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopWritable(), 2, false);135-test('Throws EPIPE when stderr option Duplex aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 2, false);136-test('Throws EPIPE when output stdio[*] option ends with more writes', testStreamEpipeFail, endOptionStream, noopWritable(), 3, false);137-test('Throws EPIPE when output stdio[*] option aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopWritable(), 3, false);138-test('Throws EPIPE when output stdio[*] option Duplex aborts with more writes', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 3, false);139-test('Throws EPIPE when subprocess.stdout aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 1, false);140-test('Throws EPIPE when subprocess.stdout Duplex aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 1, false);141-test('Throws EPIPE when subprocess.stderr aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 2, false);142-test('Throws EPIPE when subprocess.stderr Duplex aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 2, false);143-test('Throws EPIPE when output subprocess.stdio[*] aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 3, false);144-test('Throws EPIPE when output subprocess.stdio[*] Duplex aborts with more writes', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 3, false);145-test('Throws EPIPE when stdout option ends with more writes, with a transform', testStreamEpipeFail, endOptionStream, noopWritable(), 1, true);146-test('Throws EPIPE when stdout option aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopWritable(), 1, true);147-test('Throws EPIPE when stdout option Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 1, true);148-test('Throws EPIPE when stderr option ends with more writes, with a transform', testStreamEpipeFail, endOptionStream, noopWritable(), 2, true);149-test('Throws EPIPE when stderr option aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopWritable(), 2, true);150-test('Throws EPIPE when stderr option Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 2, true);151-test('Throws EPIPE when output stdio[*] option ends with more writes, with a transform', testStreamEpipeFail, endOptionStream, noopWritable(), 3, true);152-test('Throws EPIPE when output stdio[*] option aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopWritable(), 3, true);153-test('Throws EPIPE when output stdio[*] option Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroyOptionStream, noopDuplex(), 3, true);154-test('Throws EPIPE when subprocess.stdout aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 1, true);155-test('Throws EPIPE when subprocess.stdout Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 1, true);156-test('Throws EPIPE when subprocess.stderr aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 2, true);157-test('Throws EPIPE when subprocess.stderr Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 2, true);158-test('Throws EPIPE when output subprocess.stdio[*] aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopWritable(), 3, true);159-test('Throws EPIPE when output subprocess.stdio[*] Duplex aborts with more writes, with a transform', testStreamEpipeFail, destroySubprocessStream, noopDuplex(), 3, true);160-161-// eslint-disable-next-line max-params162-const testStreamError = async (t, streamMethod, stream, fdNumber, useTransform) => {163- const subprocess = execa('empty.js', getStreamStdio(fdNumber, stream, useTransform));164- const cause = new Error('test');165- streamMethod({stream, subprocess, fdNumber, error: cause});166-167- const error = await t.throwsAsync(subprocess);168- t.is(error.cause, cause);169- t.is(error.exitCode, 0);170- t.is(error.signal, undefined);171- t.false(error.isTerminated);172- t.true(error.failed);173- t.true(stream.destroyed);174-};175-176-test('Throws stream error when stdin option errors', testStreamError, destroyOptionStream, noopReadable(), 0, false);177-test('Throws stream error when stdin option Duplex errors', testStreamError, destroyOptionStream, noopDuplex(), 0, false);178-test('Throws stream error when stdout option errors', testStreamError, destroyOptionStream, noopWritable(), 1, false);179-test('Throws stream error when stdout option Duplex errors', testStreamError, destroyOptionStream, noopDuplex(), 1, false);180-test('Throws stream error when stderr option errors', testStreamError, destroyOptionStream, noopWritable(), 2, false);181-test('Throws stream error when stderr option Duplex errors', testStreamError, destroyOptionStream, noopDuplex(), 2, false);182-test('Throws stream error when output stdio[*] option errors', testStreamError, destroyOptionStream, noopWritable(), 3, false);183-test('Throws stream error when output stdio[*] Duplex option errors', testStreamError, destroyOptionStream, noopDuplex(), 3, false);184-test('Throws stream error when input stdio[*] option errors', testStreamError, destroyOptionStream, noopReadable(), 3, false);185-test('Throws stream error when subprocess.stdin errors', testStreamError, destroySubprocessStream, noopReadable(), 0, false);186-test('Throws stream error when subprocess.stdin Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 0, false);187-test('Throws stream error when subprocess.stdout errors', testStreamError, destroySubprocessStream, noopWritable(), 1, false);188-test('Throws stream error when subprocess.stdout Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 1, false);189-test('Throws stream error when subprocess.stderr errors', testStreamError, destroySubprocessStream, noopWritable(), 2, false);190-test('Throws stream error when subprocess.stderr Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 2, false);191-test('Throws stream error when output subprocess.stdio[*] errors', testStreamError, destroySubprocessStream, noopWritable(), 3, false);192-test('Throws stream error when output subprocess.stdio[*] Duplex errors', testStreamError, destroySubprocessStream, noopDuplex(), 3, false);193-test('Throws stream error when input subprocess.stdio[*] errors', testStreamError, destroySubprocessStream, noopReadable(), 3, false);194-test('Throws stream error when stdin option errors, with a transform', testStreamError, destroyOptionStream, noopReadable(), 0, true);195-test('Throws stream error when stdin option Duplex errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 0, true);196-test('Throws stream error when stdout option errors, with a transform', testStreamError, destroyOptionStream, noopWritable(), 1, true);197-test('Throws stream error when stdout option Duplex errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 1, true);198-test('Throws stream error when stderr option errors, with a transform', testStreamError, destroyOptionStream, noopWritable(), 2, true);199-test('Throws stream error when stderr option Duplex errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 2, true);200-test('Throws stream error when output stdio[*] option errors, with a transform', testStreamError, destroyOptionStream, noopWritable(), 3, true);201-test('Throws stream error when output stdio[*] Duplex option errors, with a transform', testStreamError, destroyOptionStream, noopDuplex(), 3, true);202-test('Throws stream error when input stdio[*] option errors, with a transform', testStreamError, destroyOptionStream, noopReadable(), 3, true);203-test('Throws stream error when subprocess.stdin errors, with a transform', testStreamError, destroySubprocessStream, noopReadable(), 0, true);204-test('Throws stream error when subprocess.stdin Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 0, true);205-test('Throws stream error when subprocess.stdout errors, with a transform', testStreamError, destroySubprocessStream, noopWritable(), 1, true);206-test('Throws stream error when subprocess.stdout Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 1, true);207-test('Throws stream error when subprocess.stderr errors, with a transform', testStreamError, destroySubprocessStream, noopWritable(), 2, true);208-test('Throws stream error when subprocess.stderr Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 2, true);209-test('Throws stream error when output subprocess.stdio[*] errors, with a transform', testStreamError, destroySubprocessStream, noopWritable(), 3, true);210-test('Throws stream error when output subprocess.stdio[*] Duplex errors, with a transform', testStreamError, destroySubprocessStream, noopDuplex(), 3, true);211-test('Throws stream error when input subprocess.stdio[*] errors, with a transform', testStreamError, destroySubprocessStream, noopReadable(), 3, true);added:test/verbose/output-buffer.js+39 added
1+import test from 'ava';2+import {setFixtureDir} from '../helpers/fixtures-dir.js';3+import {foobarString, foobarUppercase} from '../helpers/input.js';4+import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5+import {getOutputLine, testTimestamp, fdFullOption, fdStderrFullOption} from '../helpers/verbose.js';6+7+setFixtureDir();8+9+const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {10+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});11+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);12+};13+14+test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);15+test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);16+test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, fdFullOption, false, parentExecaAsync);17+test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);18+test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);19+test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, fdFullOption, false, parentExecaSync);20+21+const testPrintOutputNoBufferFalse = async (t, buffer, execaMethod) => {22+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer});23+ t.is(getOutputLine(stderr), undefined);24+};25+26+test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, false, parentExecaAsync);27+test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaAsync);28+test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, false, parentExecaSync);29+test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaSync);30+31+const testPrintOutputNoBufferTransform = async (t, buffer, isSync) => {32+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer, type: 'generator', isSync});33+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);34+};35+36+test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false, false);37+test('Prints stdout, buffer: false, transform, fd-specific buffer', testPrintOutputNoBufferTransform, {stdout: false}, false);38+test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, false, true);39+test('Prints stdout, buffer: false, transform, fd-specific buffer, sync', testPrintOutputNoBufferTransform, {stdout: false}, true);added:test/verbose/output-enable.js+141 added
1+import test from 'ava';2+import {red} from 'yoctocolors';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString} from '../helpers/input.js';5+import {fullStdio} from '../helpers/stdio.js';6+import {nestedExecaAsync, parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7+import {8+ runErrorSubprocessAsync,9+ runErrorSubprocessSync,10+ getOutputLine,11+ getOutputLines,12+ testTimestamp,13+ fdShortOption,14+ fdFullOption,15+ fdStdoutNoneOption,16+ fdStderrNoneOption,17+ fdStderrShortOption,18+ fdStderrFullOption,19+ fd3NoneOption,20+ fd3ShortOption,21+ fd3FullOption,22+} from '../helpers/verbose.js';23+24+setFixtureDir();25+26+const testPrintOutput = async (t, verbose, fdNumber, execaMethod) => {27+ const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose});28+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);29+};30+31+test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, parentExecaAsync);32+test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, parentExecaAsync);33+test('Prints stdout, verbose "full", fd-specific', testPrintOutput, fdFullOption, 1, parentExecaAsync);34+test('Prints stderr, verbose "full", fd-specific', testPrintOutput, fdStderrFullOption, 2, parentExecaAsync);35+test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, parentExecaSync);36+test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, parentExecaSync);37+test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, fdFullOption, 1, parentExecaSync);38+test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, fdStderrFullOption, 2, parentExecaSync);39+40+const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {41+ const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});42+ t.is(getOutputLine(stderr), undefined);43+};44+45+test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, parentExecaAsync);46+test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);47+test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);48+test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, parentExecaAsync);49+test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);50+test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);51+test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, parentExecaAsync);52+test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);53+test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);54+test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);55+test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, parentExecaAsync);56+test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, fdStdoutNoneOption, 1, parentExecaAsync);57+test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, fdShortOption, 1, parentExecaAsync);58+test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, parentExecaAsync);59+test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, fdStderrNoneOption, 2, parentExecaAsync);60+test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, fdStderrShortOption, 2, parentExecaAsync);61+test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, parentExecaAsync);62+test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, parentExecaAsync);63+test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, parentExecaAsync);64+test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, parentExecaAsync);65+test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, parentExecaSync);66+test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);67+test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);68+test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, parentExecaSync);69+test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);70+test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);71+test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, parentExecaSync);72+test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);73+test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);74+test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);75+test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, parentExecaSync);76+test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, fdStdoutNoneOption, 1, parentExecaSync);77+test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, fdShortOption, 1, parentExecaSync);78+test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, parentExecaSync);79+test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, fdStderrNoneOption, 2, parentExecaSync);80+test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, fdStderrShortOption, 2, parentExecaSync);81+test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, parentExecaSync);82+test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, parentExecaSync);83+test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, parentExecaSync);84+test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, parentExecaSync);85+86+const testPrintError = async (t, execaMethod) => {87+ const stderr = await execaMethod(t, 'full');88+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);89+};90+91+test('Prints stdout after errors', testPrintError, runErrorSubprocessAsync);92+test('Prints stdout after errors, sync', testPrintError, runErrorSubprocessSync);93+94+test('Does not quote spaces from stdout', async t => {95+ const {stderr} = await parentExecaAsync('noop.js', ['foo bar'], {verbose: 'full'});96+ t.is(getOutputLine(stderr), `${testTimestamp} [0] foo bar`);97+});98+99+test('Does not quote special punctuation from stdout', async t => {100+ const {stderr} = await parentExecaAsync('noop.js', ['%'], {verbose: 'full'});101+ t.is(getOutputLine(stderr), `${testTimestamp} [0] %`);102+});103+104+test('Does not escape internal characters from stdout', async t => {105+ const {stderr} = await parentExecaAsync('noop.js', ['ã'], {verbose: 'full'});106+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);107+});108+109+test('Strips color sequences from stdout', async t => {110+ const {stderr} = await parentExecaAsync('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});111+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);112+});113+114+test('Escapes control characters from stdout', async t => {115+ const {stderr} = await parentExecaAsync('noop.js', ['\u0001'], {verbose: 'full'});116+ t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);117+});118+119+const testStdioSame = async (t, fdNumber) => {120+ const {stdio} = await nestedExecaAsync('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: true});121+ t.is(stdio[fdNumber], foobarString);122+};123+124+test('Does not change subprocess.stdout', testStdioSame, 1);125+test('Does not change subprocess.stderr', testStdioSame, 2);126+127+const testSingleNewline = async (t, execaMethod) => {128+ const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});129+ t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);130+};131+132+test('Prints stdout, single newline', testSingleNewline, parentExecaAsync);133+test('Prints stdout, single newline, sync', testSingleNewline, parentExecaSync);134+135+const testUtf16 = async (t, isSync) => {136+ const {stderr} = await parentExeca('nested-input.js', 'stdin.js', [`${isSync}`], {verbose: 'full', encoding: 'utf16le'});137+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);138+};139+140+test('Can use encoding UTF16, verbose "full"', testUtf16, false);141+test('Can use encoding UTF16, verbose "full", sync', testUtf16, true);added:test/verbose/output-mixed.js+57 added
1+import {inspect} from 'node:util';2+import test from 'ava';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString, foobarObject} from '../helpers/input.js';5+import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';6+import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7+import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';8+9+setFixtureDir();10+11+const testLines = async (t, lines, stripFinalNewline, execaMethod) => {12+ const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines, stripFinalNewline});13+ t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));14+};15+16+test('Prints stdout, "lines: true"', testLines, true, false, parentExecaAsync);17+test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, parentExecaAsync);18+test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, parentExecaAsync);19+test('Prints stdout, "lines: true", sync', testLines, true, false, parentExecaSync);20+test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, parentExecaSync);21+test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, parentExecaSync);22+23+const testOnlyTransforms = async (t, type, isSync) => {24+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});25+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);26+};27+28+test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);29+test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);30+test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);31+32+const testObjectMode = async (t, isSync) => {33+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'object', isSync});34+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);35+};36+37+test('Prints stdout with object transforms', testObjectMode, false);38+test('Prints stdout with object transforms, sync', testObjectMode, true);39+40+const testBigArray = async (t, isSync) => {41+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'bigArray', isSync});42+ const lines = getOutputLines(stderr);43+ t.is(lines[0], `${testTimestamp} [0] [`);44+ t.true(lines[1].startsWith(`${testTimestamp} [0] 0, 1,`));45+ t.is(lines.at(-1), `${testTimestamp} [0] ]`);46+};47+48+test('Prints stdout with big object transforms', testBigArray, false);49+test('Prints stdout with big object transforms, sync', testBigArray, true);50+51+const testObjectModeString = async (t, isSync) => {52+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'stringObject', isSync});53+ t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));54+};55+56+test('Prints stdout with string transforms in objectMode', testObjectModeString, false);57+test('Prints stdout with string transforms in objectMode, sync', testObjectModeString, true);added:test/verbose/output-noop.js+57 added
1+import {rm, readFile} from 'node:fs/promises';2+import test from 'ava';3+import tempfile from 'tempfile';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {foobarString} from '../helpers/input.js';6+import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7+import {getOutputLine, testTimestamp} from '../helpers/verbose.js';8+9+setFixtureDir();10+11+const testNoOutputOptions = async (t, fixtureName, options = {}) => {12+ const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});13+ t.is(getOutputLine(stderr), undefined);14+};15+16+test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});17+test('Does not print stdout, encoding "hex"', testNoOutputOptions, 'nested.js', {encoding: 'hex'});18+test('Does not print stdout, encoding "base64"', testNoOutputOptions, 'nested.js', {encoding: 'base64'});19+test('Does not print stdout, stdout "ignore"', testNoOutputOptions, 'nested.js', {stdout: 'ignore'});20+test('Does not print stdout, stdout "inherit"', testNoOutputOptions, 'nested.js', {stdout: 'inherit'});21+test('Does not print stdout, stdout 1', testNoOutputOptions, 'nested.js', {stdout: 1});22+test('Does not print stdout, stdout Writable', testNoOutputOptions, 'nested-writable.js');23+test('Does not print stdout, stdout WritableStream', testNoOutputOptions, 'nested-writable-web.js');24+test('Does not print stdout, .pipe(stream)', testNoOutputOptions, 'nested-pipe-stream.js');25+test('Does not print stdout, .pipe(subprocess)', testNoOutputOptions, 'nested-pipe-subprocess.js');26+test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'buffer'});27+test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'hex'});28+test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'base64'});29+test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'ignore'});30+test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'inherit'});31+test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});32+33+const testStdoutFile = async (t, fixtureName, getStdout) => {34+ const file = tempfile();35+ const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});36+ t.is(getOutputLine(stderr), undefined);37+ const contents = await readFile(file, 'utf8');38+ t.is(contents.trim(), foobarString);39+ await rm(file);40+};41+42+test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));43+test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);44+test('Does not print stdout, stdout { file }, sync', testStdoutFile, 'nested-sync.js', file => ({file}));45+46+const testPrintOutputOptions = async (t, options, execaMethod) => {47+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});48+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);49+};50+51+test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaAsync);52+test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, parentExecaAsync);53+test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, parentExecaAsync);54+test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaAsync);55+test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);56+test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);57+test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);added:test/verbose/output-pipe.js+45 added
1+import test from 'ava';2+import {execa} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString} from '../helpers/input.js';5+import {parentExeca} from '../helpers/nested.js';6+import {getOutputLine, getOutputLines, testTimestamp, getVerboseOption} from '../helpers/verbose.js';7+8+setFixtureDir();9+10+const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {11+ const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [12+ JSON.stringify(getVerboseOption(sourceVerbose, 'full')),13+ 'noop.js',14+ foobarString,15+ JSON.stringify(getVerboseOption(destinationVerbose, 'full')),16+ 'stdin.js',17+ ]);18+19+ const lines = getOutputLines(stderr);20+ const id = sourceVerbose && destinationVerbose ? 1 : 0;21+ t.deepEqual(lines, destinationVerbose22+ ? [`${testTimestamp} [${id}] ${foobarString}`]23+ : []);24+};25+26+test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'file', true, true);27+test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'script', true, true);28+test('Prints stdout if both verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, true);29+test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'file', false, true);30+test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'script', false, true);31+test('Prints stdout if only second verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, true);32+test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'file', true, false);33+test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'script', true, false);34+test('Does not print stdout if only first verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, false);35+test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);36+test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);37+test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);38+39+const testPrintOutputFixture = async (t, fixtureName, ...args) => {40+ const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});41+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);42+};43+44+test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');45+test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js', 'true');added:test/verbose/output-progressive.js+58 added
1+import {on} from 'node:events';2+import test from 'ava';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {foobarString} from '../helpers/input.js';5+import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6+import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';7+8+setFixtureDir();9+10+test('Prints stdout one line at a time', async t => {11+ const subprocess = parentExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});12+13+ for await (const chunk of on(subprocess.stderr, 'data')) {14+ const outputLine = getOutputLine(chunk.toString().trim());15+ if (outputLine !== undefined) {16+ t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);17+ break;18+ }19+ }20+21+ await subprocess;22+});23+24+test.serial('Prints stdout progressively, interleaved', async t => {25+ const subprocess = parentExeca('nested-double.js', 'noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});26+27+ let firstSubprocessPrinted = false;28+ let secondSubprocessPrinted = false;29+ for await (const chunk of on(subprocess.stderr, 'data')) {30+ const outputLine = getOutputLine(chunk.toString().trim());31+ if (outputLine === undefined) {32+ continue;33+ }34+35+ if (outputLine.includes(foobarString)) {36+ t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);37+ firstSubprocessPrinted ||= true;38+ } else {39+ t.is(outputLine, `${testTimestamp} [1] ${foobarString.toUpperCase()}`);40+ secondSubprocessPrinted ||= true;41+ }42+43+ if (firstSubprocessPrinted && secondSubprocessPrinted) {44+ break;45+ }46+ }47+48+ subprocess.kill();49+ await t.throwsAsync(subprocess);50+});51+52+const testInterleaved = async (t, expectedLines, execaMethod) => {53+ const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});54+ t.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));55+};56+57+test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], parentExecaAsync);58+test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], parentExecaSync);deleted:test/verbose/output.js-363 removed
1-import {on} from 'node:events';2-import {rm, readFile} from 'node:fs/promises';3-import {inspect} from 'node:util';4-import test from 'ava';5-import tempfile from 'tempfile';6-import {red} from 'yoctocolors';7-import {execa} from '../../index.js';8-import {setFixtureDir} from '../helpers/fixtures-dir.js';9-import {foobarString, foobarObject, foobarUppercase} from '../helpers/input.js';10-import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';11-import {fullStdio} from '../helpers/stdio.js';12-import {nestedExecaAsync, parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';13-import {14- runErrorSubprocessAsync,15- runErrorSubprocessSync,16- getOutputLine,17- getOutputLines,18- testTimestamp,19- getVerboseOption,20- fdShortOption,21- fdFullOption,22- fdStdoutNoneOption,23- fdStderrNoneOption,24- fdStderrShortOption,25- fdStderrFullOption,26- fd3NoneOption,27- fd3ShortOption,28- fd3FullOption,29-} from '../helpers/verbose.js';30-31-setFixtureDir();32-33-const testPrintOutput = async (t, verbose, fdNumber, execaMethod) => {34- const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose});35- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);36-};37-38-test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, parentExecaAsync);39-test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, parentExecaAsync);40-test('Prints stdout, verbose "full", fd-specific', testPrintOutput, fdFullOption, 1, parentExecaAsync);41-test('Prints stderr, verbose "full", fd-specific', testPrintOutput, fdStderrFullOption, 2, parentExecaAsync);42-test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, parentExecaSync);43-test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, parentExecaSync);44-test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, fdFullOption, 1, parentExecaSync);45-test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, fdStderrFullOption, 2, parentExecaSync);46-47-const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {48- const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});49- t.is(getOutputLine(stderr), undefined);50-};51-52-test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, parentExecaAsync);53-test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);54-test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);55-test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, parentExecaAsync);56-test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);57-test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);58-test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, parentExecaAsync);59-test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);60-test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);61-test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);62-test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, parentExecaAsync);63-test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, fdStdoutNoneOption, 1, parentExecaAsync);64-test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, fdShortOption, 1, parentExecaAsync);65-test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, parentExecaAsync);66-test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, fdStderrNoneOption, 2, parentExecaAsync);67-test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, fdStderrShortOption, 2, parentExecaAsync);68-test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, parentExecaAsync);69-test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, parentExecaAsync);70-test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, parentExecaAsync);71-test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, parentExecaAsync);72-test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, parentExecaSync);73-test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);74-test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);75-test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, parentExecaSync);76-test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);77-test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);78-test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, parentExecaSync);79-test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);80-test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);81-test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);82-test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, parentExecaSync);83-test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, fdStdoutNoneOption, 1, parentExecaSync);84-test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, fdShortOption, 1, parentExecaSync);85-test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, parentExecaSync);86-test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, fdStderrNoneOption, 2, parentExecaSync);87-test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, fdStderrShortOption, 2, parentExecaSync);88-test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, parentExecaSync);89-test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, parentExecaSync);90-test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, parentExecaSync);91-test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, parentExecaSync);92-93-const testPrintError = async (t, execaMethod) => {94- const stderr = await execaMethod(t, 'full');95- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);96-};97-98-test('Prints stdout after errors', testPrintError, runErrorSubprocessAsync);99-test('Prints stdout after errors, sync', testPrintError, runErrorSubprocessSync);100-101-const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {102- const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [103- JSON.stringify(getVerboseOption(sourceVerbose, 'full')),104- 'noop.js',105- foobarString,106- JSON.stringify(getVerboseOption(destinationVerbose, 'full')),107- 'stdin.js',108- ]);109-110- const lines = getOutputLines(stderr);111- const id = sourceVerbose && destinationVerbose ? 1 : 0;112- t.deepEqual(lines, destinationVerbose113- ? [`${testTimestamp} [${id}] ${foobarString}`]114- : []);115-};116-117-test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'file', true, true);118-test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'script', true, true);119-test('Prints stdout if both verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, true);120-test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'file', false, true);121-test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'script', false, true);122-test('Prints stdout if only second verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, true);123-test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'file', true, false);124-test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'script', true, false);125-test('Does not print stdout if only first verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, false);126-test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);127-test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);128-test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);129-130-test('Does not quote spaces from stdout', async t => {131- const {stderr} = await parentExecaAsync('noop.js', ['foo bar'], {verbose: 'full'});132- t.is(getOutputLine(stderr), `${testTimestamp} [0] foo bar`);133-});134-135-test('Does not quote special punctuation from stdout', async t => {136- const {stderr} = await parentExecaAsync('noop.js', ['%'], {verbose: 'full'});137- t.is(getOutputLine(stderr), `${testTimestamp} [0] %`);138-});139-140-test('Does not escape internal characters from stdout', async t => {141- const {stderr} = await parentExecaAsync('noop.js', ['ã'], {verbose: 'full'});142- t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);143-});144-145-test('Strips color sequences from stdout', async t => {146- const {stderr} = await parentExecaAsync('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});147- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);148-});149-150-test('Escapes control characters from stdout', async t => {151- const {stderr} = await parentExecaAsync('noop.js', ['\u0001'], {verbose: 'full'});152- t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);153-});154-155-const testStdioSame = async (t, fdNumber) => {156- const {stdio} = await nestedExecaAsync('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: true});157- t.is(stdio[fdNumber], foobarString);158-};159-160-test('Does not change subprocess.stdout', testStdioSame, 1);161-test('Does not change subprocess.stderr', testStdioSame, 2);162-163-const testLines = async (t, lines, stripFinalNewline, execaMethod) => {164- const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines, stripFinalNewline});165- t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));166-};167-168-test('Prints stdout, "lines: true"', testLines, true, false, parentExecaAsync);169-test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, parentExecaAsync);170-test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, parentExecaAsync);171-test('Prints stdout, "lines: true", sync', testLines, true, false, parentExecaSync);172-test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, parentExecaSync);173-test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, parentExecaSync);174-175-const testOnlyTransforms = async (t, type, isSync) => {176- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});177- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);178-};179-180-test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);181-test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);182-test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);183-184-const testObjectMode = async (t, isSync) => {185- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'object', isSync});186- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);187-};188-189-test('Prints stdout with object transforms', testObjectMode, false);190-test('Prints stdout with object transforms, sync', testObjectMode, true);191-192-const testBigArray = async (t, isSync) => {193- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'bigArray', isSync});194- const lines = getOutputLines(stderr);195- t.is(lines[0], `${testTimestamp} [0] [`);196- t.true(lines[1].startsWith(`${testTimestamp} [0] 0, 1,`));197- t.is(lines.at(-1), `${testTimestamp} [0] ]`);198-};199-200-test('Prints stdout with big object transforms', testBigArray, false);201-test('Prints stdout with big object transforms, sync', testBigArray, true);202-203-const testObjectModeString = async (t, isSync) => {204- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'stringObject', isSync});205- t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));206-};207-208-test('Prints stdout with string transforms in objectMode', testObjectModeString, false);209-test('Prints stdout with string transforms in objectMode, sync', testObjectModeString, true);210-211-test('Prints stdout one line at a time', async t => {212- const subprocess = parentExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});213-214- for await (const chunk of on(subprocess.stderr, 'data')) {215- const outputLine = getOutputLine(chunk.toString().trim());216- if (outputLine !== undefined) {217- t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);218- break;219- }220- }221-222- await subprocess;223-});224-225-test.serial('Prints stdout progressively, interleaved', async t => {226- const subprocess = parentExeca('nested-double.js', 'noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});227-228- let firstSubprocessPrinted = false;229- let secondSubprocessPrinted = false;230- for await (const chunk of on(subprocess.stderr, 'data')) {231- const outputLine = getOutputLine(chunk.toString().trim());232- if (outputLine === undefined) {233- continue;234- }235-236- if (outputLine.includes(foobarString)) {237- t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);238- firstSubprocessPrinted ||= true;239- } else {240- t.is(outputLine, `${testTimestamp} [1] ${foobarString.toUpperCase()}`);241- secondSubprocessPrinted ||= true;242- }243-244- if (firstSubprocessPrinted && secondSubprocessPrinted) {245- break;246- }247- }248-249- subprocess.kill();250- await t.throwsAsync(subprocess);251-});252-253-const testSingleNewline = async (t, execaMethod) => {254- const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});255- t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);256-};257-258-test('Prints stdout, single newline', testSingleNewline, parentExecaAsync);259-test('Prints stdout, single newline, sync', testSingleNewline, parentExecaSync);260-261-const testUtf16 = async (t, isSync) => {262- const {stderr} = await parentExeca('nested-input.js', 'stdin.js', [`${isSync}`], {verbose: 'full', encoding: 'utf16le'});263- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);264-};265-266-test('Can use encoding UTF16, verbose "full"', testUtf16, false);267-test('Can use encoding UTF16, verbose "full", sync', testUtf16, true);268-269-const testNoOutputOptions = async (t, fixtureName, options = {}) => {270- const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});271- t.is(getOutputLine(stderr), undefined);272-};273-274-test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});275-test('Does not print stdout, encoding "hex"', testNoOutputOptions, 'nested.js', {encoding: 'hex'});276-test('Does not print stdout, encoding "base64"', testNoOutputOptions, 'nested.js', {encoding: 'base64'});277-test('Does not print stdout, stdout "ignore"', testNoOutputOptions, 'nested.js', {stdout: 'ignore'});278-test('Does not print stdout, stdout "inherit"', testNoOutputOptions, 'nested.js', {stdout: 'inherit'});279-test('Does not print stdout, stdout 1', testNoOutputOptions, 'nested.js', {stdout: 1});280-test('Does not print stdout, stdout Writable', testNoOutputOptions, 'nested-writable.js');281-test('Does not print stdout, stdout WritableStream', testNoOutputOptions, 'nested-writable-web.js');282-test('Does not print stdout, .pipe(stream)', testNoOutputOptions, 'nested-pipe-stream.js');283-test('Does not print stdout, .pipe(subprocess)', testNoOutputOptions, 'nested-pipe-subprocess.js');284-test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'buffer'});285-test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'hex'});286-test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'base64'});287-test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'ignore'});288-test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'inherit'});289-test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});290-291-const testStdoutFile = async (t, fixtureName, getStdout) => {292- const file = tempfile();293- const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});294- t.is(getOutputLine(stderr), undefined);295- const contents = await readFile(file, 'utf8');296- t.is(contents.trim(), foobarString);297- await rm(file);298-};299-300-test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));301-test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);302-test('Does not print stdout, stdout { file }, sync', testStdoutFile, 'nested-sync.js', file => ({file}));303-304-const testPrintOutputOptions = async (t, options, execaMethod) => {305- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});306- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);307-};308-309-test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaAsync);310-test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, parentExecaAsync);311-test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, parentExecaAsync);312-test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaAsync);313-test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);314-test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);315-test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);316-317-const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {318- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});319- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);320-};321-322-test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);323-test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);324-test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, fdFullOption, false, parentExecaAsync);325-test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);326-test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);327-test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, fdFullOption, false, parentExecaSync);328-329-const testPrintOutputNoBufferFalse = async (t, buffer, execaMethod) => {330- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer});331- t.is(getOutputLine(stderr), undefined);332-};333-334-test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, false, parentExecaAsync);335-test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaAsync);336-test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, false, parentExecaSync);337-test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaSync);338-339-const testPrintOutputNoBufferTransform = async (t, buffer, isSync) => {340- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer, type: 'generator', isSync});341- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);342-};343-344-test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false, false);345-test('Prints stdout, buffer: false, transform, fd-specific buffer', testPrintOutputNoBufferTransform, {stdout: false}, false);346-test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, false, true);347-test('Prints stdout, buffer: false, transform, fd-specific buffer, sync', testPrintOutputNoBufferTransform, {stdout: false}, true);348-349-const testPrintOutputFixture = async (t, fixtureName, ...args) => {350- const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});351- t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);352-};353-354-test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');355-test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js', 'true');356-357-const testInterleaved = async (t, expectedLines, execaMethod) => {358- const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});359- t.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));360-};361-362-test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], parentExecaAsync);363-test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], parentExecaSync);modified:test/async.js+1 added-11 removed
1 import process from 'node:process';2 import test from 'ava';3-import {execa, execaSync} from '../index.js';3+import {execa} from '../index.js';4 import {setFixtureDir} from './helpers/fixtures-dir.js';5 6 setFixtureDir();7 10 unmodified lines18 t.is(stdout, 'Hello World');19 });20 }21 22-test('skip throwing when using reject option', async t => {23- const {exitCode} = await execa('fail.js', {reject: false});24- t.is(exitCode, 2);25-});26-27-test('skip throwing when using reject option in sync mode', t => {28- const {exitCode} = execaSync('fail.js', {reject: false});29- t.is(exitCode, 2);30-});31-22 test('execa() returns a promise with pid', async t => {23 const subprocess = execa('noop.js', ['foo']);24 t.is(typeof subprocess.pid, 'number');25 await subprocess;1 unmodified linemodified:package.json+1 added-1 removed
86 unmodified lines87 },88 "ava": {89 "workerThreads": false,90 "concurrency": 1,91- "timeout": "60s"91+ "timeout": "120s"92 },93 "xo": {94 "rules": {95 "unicorn/no-empty-file": "off",4 unmodified lines