Skip to content
Myr

Fix `lines` option (#957)

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

authored by ehmicky · committed by GitHub · parent 8ad9ee7 · Browse files · 20 files+346 added−246 removed
This commit

State

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

Diff stats

20 files+346 added−246 removed

  • tests:+191 added−95 removed
  • other:+155 added−151 removed

20 files+346 added−246 removed

modified:lib/convert/iterable.js+2 added-2 removed
modified:lib/convert/loop.js+56 added-39 removed
modified:lib/convert/readable.js+2 added-2 removed
7 unmodified lines
8 waitForSubprocessStdout,9 waitForSubprocess,10 destroyOtherStream,11} from './shared.js';12import {iterateOnStdout, DEFAULT_OBJECT_HIGH_WATER_MARK} from './loop.js';12import {iterateOnSubprocessStream, DEFAULT_OBJECT_HIGH_WATER_MARK} from './loop.js';1314// Create a `Readable` stream that forwards from `stdout` and awaits the subprocess15export const createReadable = ({subprocess, concurrentStreams, useBinaryEncoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {}) => {16 const binary = binaryOption || useBinaryEncoding;
23 unmodified lines
40 : {readableEncoding, readableObjectMode: true, readableHighWaterMark: DEFAULT_OBJECT_HIGH_WATER_MARK};4142export const getReadableMethods = ({subprocessStdout, subprocess, binary, preserveNewlines}) => {43 const onStdoutDataDone = createDeferred();44 const onStdoutData = iterateOnStdout({subprocessStdout, subprocess, binary, preserveNewlines, isStream: true});44 const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: !binary, preserveNewlines});4546 return {47 read() {48 onRead(this, onStdoutData, onStdoutDataDone);
46 unmodified lines
modified:lib/stdio/encoding-transform.js+2 added-2 removed
modified:lib/stdio/generator.js+7 added-9 removed
140 unmodified lines
141*/142export const generatorToDuplexStream = ({143 value,144 value: {transform, final, writableObjectMode, readableObjectMode},145 forceEncoding,145 optionName,146}) => {148 const generators = addInternalGenerators({value, forceEncoding, optionName});147 const generators = addInternalGenerators(value, optionName);148 const transformAsync = isAsyncGenerator(transform);149 const finalAsync = isAsyncGenerator(final);150 const stream = generatorsToTransform(generators, {transformAsync, finalAsync, writableObjectMode, readableObjectMode});151 return {stream};
2 unmodified lines
154export const getGenerators = stdioItems => stdioItems.filter(({type}) => type === 'generator');155156export const runGeneratorsSync = (chunks, generators) => {157 for (const {value, optionName} of generators) {159 const generators = addInternalGenerators({value, forceEncoding: false, optionName});158 const generators = addInternalGenerators(value, optionName);159 chunks = runTransformSync(generators, chunks);160 }161162 return chunks;163};164166const addInternalGenerators = ({167 value: {transform, final, binary, writableObjectMode, readableObjectMode, preserveNewlines},168 forceEncoding,165const addInternalGenerators = (166 {transform, final, binary, writableObjectMode, readableObjectMode, preserveNewlines},167 optionName,170}) => {168) => {169 const state = {};170 return [171 {transform: getValidateTransformInput(writableObjectMode, optionName)},174 getEncodingTransformGenerator(binary, writableObjectMode, forceEncoding),175 getSplitLinesGenerator({binary, preserveNewlines, writableObjectMode, state}),172 getEncodingTransformGenerator(binary, writableObjectMode),173 getSplitLinesGenerator(binary, preserveNewlines, writableObjectMode, state),174 {transform, final},175 {transform: getValidateTransformReturn(readableObjectMode, optionName)},176 getAppendNewlineGenerator({binary, preserveNewlines, readableObjectMode, state}),177 ].filter(Boolean);
19 unmodified lines
modified:lib/stdio/handle.js+5 added-8 removed
2 unmodified lines
3import {getStreamDirection} from './direction.js';4import {normalizeStdio} from './option.js';5import {handleNativeStream} from './native.js';6import {handleInputOptions} from './input.js';7import {handleStreamsLines} from './lines.js';7import {handleStreamsEncoding} from './encoding-final.js';8import {normalizeTransforms, getObjectMode} from './generator.js';9import {forwardStdio, willPipeFileDescriptor} from './forward.js';10
10 unmodified lines
21// We make sure passing an array with a single item behaves the same as passing that item without an array.22// This is what users would expect.23// For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.24const getFileDescriptor = ({stdioOption, fdNumber, addProperties, options, isSync, stdioState, verboseInfo}) => {26 const outputLines = [];25 const optionName = getOptionName(fdNumber);26 const {stdioItems: initialStdioItems, isStdioArray} = initializeStdioItems({stdioOption, fdNumber, options, optionName});27 const direction = getStreamDirection(initialStdioItems, fdNumber, optionName);28 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({stdioItem, isStdioArray, fdNumber, direction, isSync}));29 const objectMode = getObjectMode(stdioItems, optionName, direction, options);30 validateFileObjectMode(stdioItems, objectMode);33 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});34 return {direction, objectMode, outputLines, stdioItems: normalizedStdioItems};31 const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo, objectMode});32 return {direction, objectMode, stdioItems: normalizedStdioItems};33};3435const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;36const KNOWN_OPTION_NAMES = ['stdin', 'stdout', 'stderr'];
60 unmodified lines
97 throw new TypeError(`The \`${optionName}: { file: '...' }\` option must be used instead of \`${optionName}: '...'\`.`);98 }99};100103const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode}) => {104 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode});101const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo, objectMode}) => {102 const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, direction, stdioState, verboseInfo, objectMode});103 const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);104 return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));105};106109const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, isSync, direction, stdioState, verboseInfo, outputLines, objectMode}) => willPipeFileDescriptor(stdioItems)107const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, direction, stdioState, verboseInfo, objectMode}) => willPipeFileDescriptor(stdioItems)108 ? [109 ...stdioItems,110 ...handleStreamsEncoding({options, direction, optionName, objectMode}),111 ...handleStreamsVerbose({stdioItems, options, stdioState, verboseInfo, fdNumber, optionName}),114 ...handleStreamsLines({options, isSync, direction, optionName, objectMode, outputLines}),112 ]113 : stdioItems;114115// Some `stdio` values require Execa to create streams.
17 unmodified lines
deleted:lib/stdio/lines.js-29 removed
1import {MaxBufferError} from 'get-stream';2import stripFinalNewlineFunction from 'strip-final-newline';34// Split chunks line-wise for streams exposed to users like `subprocess.stdout`.5// Appending a noop transform in object mode is enough to do this, since every non-binary transform iterates line-wise.6export const handleStreamsLines = ({options: {lines, stripFinalNewline, maxBuffer}, isSync, direction, optionName, objectMode, outputLines}) => shouldSplitLines(lines, direction, objectMode)7 ? [{8 type: 'generator',9 value: {transform: linesEndGenerator.bind(undefined, {outputLines, stripFinalNewline, maxBuffer, isSync}), preserveNewlines: true},10 optionName,11 }]12 : [];1314const shouldSplitLines = (lines, direction, objectMode) => direction === 'output'15 && lines16 && !objectMode;1718const linesEndGenerator = function * ({outputLines, stripFinalNewline, maxBuffer, isSync}, line) {19 if (!isSync && outputLines.length >= maxBuffer) {20 const error = new MaxBufferError();21 error.bufferedData = outputLines;22 throw error;23 }2425 const strippedLine = stripFinalNewline ? stripFinalNewlineFunction(line) : line;26 outputLines.push(strippedLine);2728 yield line;29};
modified:lib/stdio/output-sync.js+16 added-7 removed
1import {writeFileSync} from 'node:fs';2import {joinToString, joinToUint8Array, bufferToUint8Array, isUint8Array, concatUint8Arrays} from './uint-array.js';3import {getGenerators, runGeneratorsSync} from './generator.js';4import {splitLinesSync} from './split.js';5import {FILE_TYPES} from './type.js';67// Apply `stdout`/`stderr` options, after spawning, in sync mode8export const transformOutputSync = (fileDescriptors, {output}, options) => {
6 unmodified lines
15 transformOutputResultSync({result, fileDescriptors, fdNumber, state}, options));16 return {output: transformedOutput, ...state};17};1818const transformOutputResultSync = ({result, fileDescriptors, fdNumber, state}, {buffer, encoding, lines}) => {19const transformOutputResultSync = ({result, fileDescriptors, fdNumber, state}, {buffer, encoding, lines, stripFinalNewline}) => {20 if (result === null) {21 return;22 }2323 const {stdioItems, outputLines, objectMode} = fileDescriptors[fdNumber];24 const {stdioItems, objectMode} = fileDescriptors[fdNumber];25 const uint8ArrayResult = bufferToUint8Array(result);26 const generators = getGenerators(stdioItems);27 const chunks = runOutputGeneratorsSync([uint8ArrayResult], generators, state);27 const {serializedResult, finalResult} = serializeChunks({chunks, objectMode, outputLines, encoding, lines});28 const {serializedResult, finalResult} = serializeChunks({chunks, objectMode, encoding, lines, stripFinalNewline});29 const returnedResult = buffer ? finalResult : undefined;3031 try {32 if (state.error === undefined) {
15 unmodified lines
48 return chunks;49 }50};5151const serializeChunks = ({chunks, objectMode, outputLines, encoding, lines}) => {52const serializeChunks = ({chunks, objectMode, encoding, lines, stripFinalNewline}) => {53 if (objectMode) {54 return {finalResult: chunks};55 }5656 const serializedResult = encoding === 'buffer' ? joinToUint8Array(chunks) : joinToString(chunks, true);57 const finalResult = lines ? outputLines : serializedResult;58 return {serializedResult, finalResult};57 if (encoding === 'buffer') {58 const serializedResult = joinToUint8Array(chunks);59 return {serializedResult, finalResult: serializedResult};60 }6162 const serializedResult = joinToString(chunks);63 if (!lines) {64 return {serializedResult, finalResult: serializedResult};65 }6667 return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline)};68};6970const writeToFiles = (serializedResult, stdioItems) => {71 for (const {type, path} of stdioItems) {
33 unmodified lines
modified:lib/stdio/split.js+14 added-4 removed
1// Split chunks line-wise for generators passed to the `std*` options2export const getSplitLinesGenerator = ({binary, preserveNewlines, writableObjectMode, state}) => {3 if (binary || writableObjectMode) {4 return;5 }2export const getSplitLinesGenerator = (binary, preserveNewlines, writableObjectMode, state) => binary || writableObjectMode3 ? undefined4 : initializeSplitLines(preserveNewlines, state);56export const splitLinesSync = (string, preserveNewlines) => {7 const {transform, final} = initializeSplitLines(preserveNewlines, {});8 return [...transform(string), ...final()];9};1011const initializeSplitLines = (preserveNewlines, state) => {12 state.previousChunks = '';13 return {14 transform: splitGenerator.bind(undefined, state, preserveNewlines),15 final: linesFinal.bind(undefined, state),
1 unmodified line
17};1819// This imperative logic is much faster than using `String.split()` and uses very low memory.20const splitGenerator = function * (state, preserveNewlines, chunk) {21 if (typeof chunk !== 'string') {22 yield chunk;23 return;24 }2526 let {previousChunks} = state;27 let start = -1;2829 for (let end = 0; end < chunk.length; end += 1) {
76 unmodified lines
modified:lib/stdio/uint-array.js+9 added-5 removed
1import {Buffer} from 'node:buffer';23export const isUint8Array = value => Object.prototype.toString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);3const {toString: objectToString} = Object.prototype;45export const isArrayBuffer = value => objectToString.call(value) === '[object ArrayBuffer]';67export const isUint8Array = value => objectToString.call(value) === '[object Uint8Array]' && !Buffer.isBuffer(value);89export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);1011const textEncoder = new TextEncoder();12const stringToUint8Array = string => textEncoder.encode(string);1314const textDecoder = new TextDecoder();15export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);1613export const joinToString = (uint8ArraysOrStrings, areRelated) => {17export const joinToString = uint8ArraysOrStrings => {18 if (uint8ArraysOrStrings.length === 1 && typeof uint8ArraysOrStrings[0] === 'string') {19 return uint8ArraysOrStrings[0];20 }2118 const strings = uint8ArraysToStrings(uint8ArraysOrStrings, areRelated);22 const strings = uint8ArraysToStrings(uint8ArraysOrStrings);23 return strings.join('');24};2522const uint8ArraysToStrings = (uint8ArraysOrStrings, areRelated) => {26const uint8ArraysToStrings = uint8ArraysOrStrings => {27 const decoder = new TextDecoder();28 const strings = uint8ArraysOrStrings.map(uint8ArrayOrString => isUint8Array(uint8ArrayOrString)25 ? decoder.decode(uint8ArrayOrString, {stream: areRelated})29 ? decoder.decode(uint8ArrayOrString, {stream: true})30 : uint8ArrayOrString);31 const finalString = decoder.decode();32 return finalString === '' ? strings : [...strings, finalString];33};
33 unmodified lines
modified:lib/stream/all.js+9 added-18 removed
1import mergeStreams from '@sindresorhus/merge-streams';2import {generatorToDuplexStream} from '../stdio/generator.js';2import {waitForSubprocessStream} from './subprocess.js';34// `all` interleaves `stdout` and `stderr`5export const makeAllStream = ({stdout, stderr}, {all}) => all && (stdout || stderr)6 ? mergeStreams([stdout, stderr].filter(Boolean))7 : undefined;89// Read the contents of `subprocess.all` and|or wait for its completion11export const waitForAllStream = ({subprocess, encoding, buffer, maxBuffer, streamInfo}) => waitForSubprocessStream({12 stream: getAllStream(subprocess, encoding),10export const waitForAllStream = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo}) => waitForSubprocessStream({11 stream: subprocess.all,12 subprocess,13 fdNumber: 1,14 encoding,15 buffer,16 maxBuffer: maxBuffer * 2,17 lines,18 allMixed: getAllMixed(subprocess),19 stripFinalNewline,20 streamInfo,21});2223// When `subprocess.stdout` is in objectMode but not `subprocess.stderr` (or the opposite), we need to use both:24// - `getStreamAsArray()` for the chunks in objectMode, to return as an array without changing each chunk25// - `getStreamAsArrayBuffer()` or `getStream()` for the chunks not in objectMode, to convert them from Buffers to string or Uint8Array26// We do this by emulating the Buffer -> string|Uint8Array conversion performed by `get-stream` with our own, which is identical.25const getAllStream = ({all, stdout, stderr}, encoding) => all && stdout && stderr && stdout.readableObjectMode !== stderr.readableObjectMode26 ? all.pipe(generatorToDuplexStream(getAllStreamTransform(encoding)).stream)27 : all;2829const getAllStreamTransform = encoding => ({30 value: {31 * final() {},32 binary: encoding === 'buffer',33 writableObjectMode: true,34 readableObjectMode: true,35 preserveNewlines: true,36 },37 forceEncoding: true,38 optionName: 'all',39});27const getAllMixed = ({all, stdout, stderr}) => all28 && stdout29 && stderr30 && stdout.readableObjectMode !== stderr.readableObjectMode;
modified:lib/stream/resolve.js+7 added-7 removed
11 unmodified lines
1213// Retrieve result of subprocess: exit code, signal, error, streams (stdout/stderr/all)14export const getSubprocessResult = async ({15 subprocess,16 options: {encoding, buffer, maxBuffer, lines, timeoutDuration: timeout},16 options: {encoding, buffer, maxBuffer, lines, timeoutDuration: timeout, stripFinalNewline},17 context,18 fileDescriptors,19 originalStreams,20 controller,21}) => {22 const exitPromise = waitForExit(subprocess);23 const streamInfo = {originalStreams, fileDescriptors, subprocess, exitPromise, propagating: false};2425 const stdioPromises = waitForSubprocessStreams({subprocess, encoding, buffer, maxBuffer, lines, streamInfo});26 const allPromise = waitForAllStream({subprocess, encoding, buffer, maxBuffer, streamInfo});25 const stdioPromises = waitForSubprocessStreams({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo});26 const allPromise = waitForAllStream({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo});27 const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);28 const customStreamsEndPromises = waitForCustomStreamsEnd(fileDescriptors, streamInfo);2930 try {
13 unmodified lines
44 } catch (error) {45 return Promise.all([46 {error},47 exitPromise,48 Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise, encoding))),49 getBufferedData(allPromise, encoding),48 Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise))),49 getBufferedData(allPromise),50 Promise.allSettled(originalPromises),51 Promise.allSettled(customStreamsEndPromises),52 ]);53 }54};5556// Read the contents of `subprocess.std*` and|or wait for its completion57const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, streamInfo}) =>58 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, lines, streamInfo}));57const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, streamInfo}) =>58 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, lines, allMixed: false, stripFinalNewline, streamInfo}));5960// Transforms replace `subprocess.std*`, which means they are not exposed to users.61// However, we still want to wait for their completion.62const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>
23 unmodified lines
modified:lib/stream/subprocess.js+26 added-19 removed
1import {setImmediate} from 'node:timers/promises';2import getStream, {getStreamAsArrayBuffer, getStreamAsArray, MaxBufferError} from 'get-stream';3import {iterateForResult} from '../convert/loop.js';4import {isArrayBuffer} from '../stdio/uint-array.js';5import {waitForStream, handleStreamError, isInputFileDescriptor} from './wait.js';65export const waitForSubprocessStream = async ({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, lines, streamInfo}) => {7export const waitForSubprocessStream = async ({stream, subprocess, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, streamInfo}) => {8 if (!stream) {9 return;10 }11
10 unmodified lines
22 return;23 }2425 try {24 return await getAnyStream({stream, fdNumber, encoding, maxBuffer, lines, streamInfo});26 return await getAnyStream({stream, fdNumber, encoding, maxBuffer, lines, allMixed, stripFinalNewline, streamInfo});27 } catch (error) {28 if (error instanceof MaxBufferError) {29 subprocess.kill();30 }3132 handleStreamError(error, fdNumber, streamInfo);31 return handleBufferedData(error, encoding);33 return handleBufferedData(error);34 }35};3637// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away
4 unmodified lines
42 stream.resume();43 }44};4544const getAnyStream = async ({stream, fdNumber, encoding, maxBuffer, lines, streamInfo}) => {46const getAnyStream = async ({stream, fdNumber, encoding, maxBuffer, lines, allMixed, stripFinalNewline, streamInfo}) => {47 if (allMixed) {48 return getStreamLines({stream, fdNumber, encoding, maxBuffer, lines, stripFinalNewline, streamInfo});49 }5051 if (stream.readableObjectMode) {52 return getStreamAsArray(stream, {maxBuffer});53 }5449 if (lines) {50 return getOutputLines(stream, fdNumber, streamInfo);55 if (encoding === 'buffer') {56 return new Uint8Array(await getStreamAsArrayBuffer(stream, {maxBuffer}));57 }5853 const contents = encoding === 'buffer'54 ? await getStreamAsArrayBuffer(stream, {maxBuffer})55 : await getStream(stream, {maxBuffer});56 return applyEncoding(contents, encoding);59 if (!lines) {60 return getStream(stream, {maxBuffer});61 }6263 return getStreamLines({stream, fdNumber, encoding, maxBuffer, lines, stripFinalNewline, streamInfo});64};6559const getOutputLines = async (stream, fdNumber, streamInfo) => {60 await waitForStream(stream, fdNumber, streamInfo);61 return streamInfo.fileDescriptors[fdNumber].outputLines;66const getStreamLines = ({stream, fdNumber, encoding, maxBuffer, lines, stripFinalNewline, streamInfo}) => {67 const onStreamEnd = waitForStream(stream, fdNumber, streamInfo);68 const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline});69 return getStreamAsArray(iterable, {maxBuffer});70};7172// On failure, `result.stdout|stderr|all` should contain the currently buffered stream73// They are automatically closed and flushed by Node.js when the subprocess exits74// When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve67export const getBufferedData = async (streamPromise, encoding) => {75export const getBufferedData = async streamPromise => {76 try {77 return await streamPromise;78 } catch (error) {71 return handleBufferedData(error, encoding);79 return handleBufferedData(error);80 }81};8275const handleBufferedData = ({bufferedData}, encoding) => bufferedData === undefined || Array.isArray(bufferedData)76 ? bufferedData77 : applyEncoding(bufferedData, encoding);83const handleBufferedData = ({bufferedData}) => isArrayBuffer(bufferedData)84 ? new Uint8Array(bufferedData)85 : bufferedData;8679const applyEncoding = (contents, encoding) => encoding === 'buffer' ? new Uint8Array(contents) : contents;
modified:test/fixtures/all-fail.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';34console.log('stdout');5console.error('stderr');4console.log('std\nout');5console.error('std\nerr');6process.exitCode = 1;
modified:test/fixtures/all.js+2 added-2 removed
1#!/usr/bin/env node2console.log('stdout');3console.error('stderr');2console.log('std\nout');3console.error('std\nerr');
modified:test/helpers/convert.js+5 added
1import {text} from 'node:stream/consumers';2import {finished} from 'node:stream/promises';3import getStream from 'get-stream';4import isPlainObj from 'is-plain-obj';5import {execa} from '../../index.js';6import {foobarString} from '../helpers/input.js';7
27 unmodified lines
35export const assertStreamOutput = async (t, stream, expectedOutput = foobarString) => {36 t.is(await text(stream), expectedOutput);37};3839export const assertStreamDataEvents = async (t, stream, expectedOutput = foobarString) => {40 t.is(await getStream(stream), expectedOutput);41};4243export const assertIterableChunks = async (t, asyncIterable, expectedChunks) => {44 t.deepEqual(await arrayFromAsync(asyncIterable), expectedChunks);45};46
32 unmodified lines
modified:test/return/error.js+1 added-1 removed
69 unmodified lines
70});7172// eslint-disable-next-line max-params73const testStdioMessage = async (t, encoding, all, objectMode, execaMethod) => {74 const {exitCode, message} = await execaMethod('echo-fail.js', {...getStdio(1, noopGenerator(objectMode), 4), encoding, all, reject: false});74 const {exitCode, message} = await execaMethod('echo-fail.js', {...getStdio(1, noopGenerator(objectMode, false, true), 4), encoding, all, reject: false});75 t.is(exitCode, 1);76 const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';77 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));78};
150 unmodified lines
modified:test/stdio/generator.js+163 added-82 removed
422 unmodified lines
423424 return encoding === 'utf8' ? uppercaseGenerator() : uppercaseBufferGenerator();425};426427const getStdoutStderrOutput = (output, stdioOption, encoding, objectMode) => {427const getStdoutStderrOutput = ({output, stdioOption, encoding, objectMode, lines}) => {428 if (objectMode && !stdioOption) {429 return [foobarObject];429 return encoding === 'utf8' ? [foobarObject, foobarObject] : [foobarObject];430 }431432 const stdioOutput = stdioOption ? output : output.toUpperCase();433434 if (encoding === 'hex') {435 return Buffer.from(stdioOutput).toString('hex');436 }437438 return encoding === 'buffer' ? textEncoder.encode(stdioOutput) : stdioOutput;438 if (encoding === 'buffer') {439 return textEncoder.encode(stdioOutput);440 }441442 return lines ? stdioOutput.trim().split('\n').map(string => `${string}\n`) : stdioOutput;443};444441const getAllOutput = (stdoutOutput, stderrOutput, encoding, objectMode) => {442 if (objectMode) {445const getAllOutput = ({stdoutOutput, stderrOutput, encoding, objectMode, lines}) => {446 if (objectMode || (lines && encoding === 'utf8')) {447 return [stdoutOutput, stderrOutput].flat();448 }449450 return encoding === 'buffer'
1 unmodified line
452 : `${stdoutOutput}${stderrOutput}`;453};454455// eslint-disable-next-line max-params452const testGeneratorAll = async (t, reject, encoding, objectMode, stdoutOption, stderrOption, execaMethod) => {456const testGeneratorAll = async (t, reject, encoding, objectMode, stdoutOption, stderrOption, lines, execaMethod) => {457 const fixtureName = reject ? 'all.js' : 'all-fail.js';458 const {stdout, stderr, all} = await execaMethod(fixtureName, {459 all: true,460 reject,461 stdout: getAllStdioOption(stdoutOption, encoding, objectMode),462 stderr: getAllStdioOption(stderrOption, encoding, objectMode),463 encoding,464 lines,465 stripFinalNewline: false,466 });467463 const stdoutOutput = getStdoutStderrOutput('stdout\n', stdoutOption, encoding, objectMode);468 const stdoutOutput = getStdoutStderrOutput({output: 'std\nout\n', stdioOption: stdoutOption, encoding, objectMode, lines});469 t.deepEqual(stdout, stdoutOutput);465 const stderrOutput = getStdoutStderrOutput('stderr\n', stderrOption, encoding, objectMode);470 const stderrOutput = getStdoutStderrOutput({output: 'std\nerr\n', stdioOption: stderrOption, encoding, objectMode, lines});471 t.deepEqual(stderr, stderrOutput);467 const allOutput = getAllOutput(stdoutOutput, stderrOutput, encoding, objectMode);468 t.deepEqual(all, allOutput);472 const allOutput = getAllOutput({stdoutOutput, stderrOutput, encoding, objectMode, lines});473 if (Array.isArray(all) && Array.isArray(allOutput)) {474 t.deepEqual([...all].sort(), [...allOutput].sort());475 } else {476 t.deepEqual(all, allOutput);477 }478};479471test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false, execa);472test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false, execa);473test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false, execa);474test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false, execa);475test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false, execa);476test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false, execa);477test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true, execa);478test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true, execa);479test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true, execa);480test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true, execa);481test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true, execa);482test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true, execa);483test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false, execa);484test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false, execa);485test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false, execa);486test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false, execa);487test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false, execa);488test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false, execa);489test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false, execa);490test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false, execa);491test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false, execa);492test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false, execa);493test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false, execa);494test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false, execa);495test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true, execa);496test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true, execa);497test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true, execa);498test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true, execa);499test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true, execa);500test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true, execa);501test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false, execa);502test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false, execa);503test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false, execa);504test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false, execa);505test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false, execa);506test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false, execa);507test('Can use generators with result.all = transform + transform, sync', testGeneratorAll, true, 'utf8', false, false, false, execaSync);508test('Can use generators with error.all = transform + transform, sync', testGeneratorAll, false, 'utf8', false, false, false, execaSync);509test('Can use generators with result.all = transform + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, false, execaSync);510test('Can use generators with error.all = transform + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, false, execaSync);511test('Can use generators with result.all = transform + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, false, execaSync);512test('Can use generators with error.all = transform + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, false, execaSync);513test('Can use generators with result.all = transform + pipe, sync', testGeneratorAll, true, 'utf8', false, false, true, execaSync);514test('Can use generators with error.all = transform + pipe, sync', testGeneratorAll, false, 'utf8', false, false, true, execaSync);515test('Can use generators with result.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, true, execaSync);516test('Can use generators with error.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, true, execaSync);517test('Can use generators with result.all = transform + pipe, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, true, execaSync);518test('Can use generators with error.all = transform + pipe, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, true, execaSync);519test('Can use generators with result.all = pipe + transform, sync', testGeneratorAll, true, 'utf8', false, true, false, execaSync);520test('Can use generators with error.all = pipe + transform, sync', testGeneratorAll, false, 'utf8', false, true, false, execaSync);521test('Can use generators with result.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, true, false, execaSync);522test('Can use generators with error.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, true, false, execaSync);523test('Can use generators with result.all = pipe + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, true, false, execaSync);524test('Can use generators with error.all = pipe + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, true, false, execaSync);525test('Can use generators with result.all = transform + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, false, execaSync);526test('Can use generators with error.all = transform + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, false, execaSync);527test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, false, execaSync);528test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, false, execaSync);529test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, false, execaSync);530test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, false, execaSync);531test('Can use generators with result.all = transform + pipe, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, true, execaSync);532test('Can use generators with error.all = transform + pipe, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, true, execaSync);533test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, true, execaSync);534test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, true, execaSync);535test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, true, execaSync);536test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, true, execaSync);537test('Can use generators with result.all = pipe + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, true, false, execaSync);538test('Can use generators with error.all = pipe + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, true, false, execaSync);539test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, true, false, execaSync);540test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, true, false, execaSync);541test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, true, false, execaSync);542test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, true, false, execaSync);480test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false, false, execa);481test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false, false, execa);482test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false, false, execa);483test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false, false, execa);484test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false, false, execa);485test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false, false, execa);486test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true, false, execa);487test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true, false, execa);488test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true, false, execa);489test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true, false, execa);490test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true, false, execa);491test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true, false, execa);492test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false, false, execa);493test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false, false, execa);494test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false, false, execa);495test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false, false, execa);496test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false, false, execa);497test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false, false, execa);498test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false, false, execa);499test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false, false, execa);500test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false, false, execa);501test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false, false, execa);502test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false, false, execa);503test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false, false, execa);504test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true, false, execa);505test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true, false, execa);506test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true, false, execa);507test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true, false, execa);508test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true, false, execa);509test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true, false, execa);510test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false, false, execa);511test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false, false, execa);512test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false, false, execa);513test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false, false, execa);514test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false, false, execa);515test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false, false, execa);516test('Can use generators with result.all = transform + transform, sync', testGeneratorAll, true, 'utf8', false, false, false, false, execaSync);517test('Can use generators with error.all = transform + transform, sync', testGeneratorAll, false, 'utf8', false, false, false, false, execaSync);518test('Can use generators with result.all = transform + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, false, false, execaSync);519test('Can use generators with error.all = transform + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, false, false, execaSync);520test('Can use generators with result.all = transform + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, false, false, execaSync);521test('Can use generators with error.all = transform + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, false, false, execaSync);522test('Can use generators with result.all = transform + pipe, sync', testGeneratorAll, true, 'utf8', false, false, true, false, execaSync);523test('Can use generators with error.all = transform + pipe, sync', testGeneratorAll, false, 'utf8', false, false, true, false, execaSync);524test('Can use generators with result.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, true, false, execaSync);525test('Can use generators with error.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, true, false, execaSync);526test('Can use generators with result.all = transform + pipe, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, true, false, execaSync);527test('Can use generators with error.all = transform + pipe, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, true, false, execaSync);528test('Can use generators with result.all = pipe + transform, sync', testGeneratorAll, true, 'utf8', false, true, false, false, execaSync);529test('Can use generators with error.all = pipe + transform, sync', testGeneratorAll, false, 'utf8', false, true, false, false, execaSync);530test('Can use generators with result.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, true, false, false, execaSync);531test('Can use generators with error.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, true, false, false, execaSync);532test('Can use generators with result.all = pipe + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, true, false, false, execaSync);533test('Can use generators with error.all = pipe + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, true, false, false, execaSync);534test('Can use generators with result.all = transform + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, false, false, execaSync);535test('Can use generators with error.all = transform + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, false, false, execaSync);536test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, false, false, execaSync);537test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, false, false, execaSync);538test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, false, false, execaSync);539test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, false, false, execaSync);540test('Can use generators with result.all = transform + pipe, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, true, false, execaSync);541test('Can use generators with error.all = transform + pipe, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, true, false, execaSync);542test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, true, false, execaSync);543test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, true, false, execaSync);544test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, true, false, execaSync);545test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, true, false, execaSync);546test('Can use generators with result.all = pipe + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, true, false, false, execaSync);547test('Can use generators with error.all = pipe + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, true, false, false, execaSync);548test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, true, false, false, execaSync);549test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, true, false, false, execaSync);550test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, true, false, false, execaSync);551test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, true, false, false, execaSync);552test('Can use generators with result.all = transform + transform, lines', testGeneratorAll, true, 'utf8', false, false, false, true, execa);553test('Can use generators with error.all = transform + transform, lines', testGeneratorAll, false, 'utf8', false, false, false, true, execa);554test('Can use generators with result.all = transform + transform, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, false, false, true, execa);555test('Can use generators with error.all = transform + transform, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, false, false, true, execa);556test('Can use generators with result.all = transform + transform, encoding "hex", lines', testGeneratorAll, true, 'hex', false, false, false, true, execa);557test('Can use generators with error.all = transform + transform, encoding "hex", lines', testGeneratorAll, false, 'hex', false, false, false, true, execa);558test('Can use generators with result.all = transform + pipe, lines', testGeneratorAll, true, 'utf8', false, false, true, true, execa);559test('Can use generators with error.all = transform + pipe, lines', testGeneratorAll, false, 'utf8', false, false, true, true, execa);560test('Can use generators with result.all = transform + pipe, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, false, true, true, execa);561test('Can use generators with error.all = transform + pipe, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, false, true, true, execa);562test('Can use generators with result.all = transform + pipe, encoding "hex", lines', testGeneratorAll, true, 'hex', false, false, true, true, execa);563test('Can use generators with error.all = transform + pipe, encoding "hex", lines', testGeneratorAll, false, 'hex', false, false, true, true, execa);564test('Can use generators with result.all = pipe + transform, lines', testGeneratorAll, true, 'utf8', false, true, false, true, execa);565test('Can use generators with error.all = pipe + transform, lines', testGeneratorAll, false, 'utf8', false, true, false, true, execa);566test('Can use generators with result.all = pipe + transform, encoding "buffer", lines', testGeneratorAll, true, 'buffer', false, true, false, true, execa);567test('Can use generators with error.all = pipe + transform, encoding "buffer", lines', testGeneratorAll, false, 'buffer', false, true, false, true, execa);568test('Can use generators with result.all = pipe + transform, encoding "hex", lines', testGeneratorAll, true, 'hex', false, true, false, true, execa);569test('Can use generators with error.all = pipe + transform, encoding "hex", lines', testGeneratorAll, false, 'hex', false, true, false, true, execa);570test('Can use generators with result.all = transform + transform, objectMode, lines', testGeneratorAll, true, 'utf8', true, false, false, true, execa);571test('Can use generators with error.all = transform + transform, objectMode, lines', testGeneratorAll, false, 'utf8', true, false, false, true, execa);572test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, false, false, true, execa);573test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, false, false, true, execa);574test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, false, false, true, execa);575test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, false, false, true, execa);576test('Can use generators with result.all = transform + pipe, objectMode, lines', testGeneratorAll, true, 'utf8', true, false, true, true, execa);577test('Can use generators with error.all = transform + pipe, objectMode, lines', testGeneratorAll, false, 'utf8', true, false, true, true, execa);578test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, false, true, true, execa);579test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, false, true, true, execa);580test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, false, true, true, execa);581test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, false, true, true, execa);582test('Can use generators with result.all = pipe + transform, objectMode, lines', testGeneratorAll, true, 'utf8', true, true, false, true, execa);583test('Can use generators with error.all = pipe + transform, objectMode, lines', testGeneratorAll, false, 'utf8', true, true, false, true, execa);584test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", lines', testGeneratorAll, true, 'buffer', true, true, false, true, execa);585test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", lines', testGeneratorAll, false, 'buffer', true, true, false, true, execa);586test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", lines', testGeneratorAll, true, 'hex', true, true, false, true, execa);587test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", lines', testGeneratorAll, false, 'hex', true, true, false, true, execa);588test('Can use generators with result.all = transform + transform, sync, lines', testGeneratorAll, true, 'utf8', false, false, false, true, execaSync);589test('Can use generators with error.all = transform + transform, sync, lines', testGeneratorAll, false, 'utf8', false, false, false, true, execaSync);590test('Can use generators with result.all = transform + transform, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, false, false, true, execaSync);591test('Can use generators with error.all = transform + transform, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, false, false, true, execaSync);592test('Can use generators with result.all = transform + transform, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, false, false, true, execaSync);593test('Can use generators with error.all = transform + transform, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, false, false, true, execaSync);594test('Can use generators with result.all = transform + pipe, sync, lines', testGeneratorAll, true, 'utf8', false, false, true, true, execaSync);595test('Can use generators with error.all = transform + pipe, sync, lines', testGeneratorAll, false, 'utf8', false, false, true, true, execaSync);596test('Can use generators with result.all = transform + pipe, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, false, true, true, execaSync);597test('Can use generators with error.all = transform + pipe, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, false, true, true, execaSync);598test('Can use generators with result.all = transform + pipe, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, false, true, true, execaSync);599test('Can use generators with error.all = transform + pipe, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, false, true, true, execaSync);600test('Can use generators with result.all = pipe + transform, sync, lines', testGeneratorAll, true, 'utf8', false, true, false, true, execaSync);601test('Can use generators with error.all = pipe + transform, sync, lines', testGeneratorAll, false, 'utf8', false, true, false, true, execaSync);602test('Can use generators with result.all = pipe + transform, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', false, true, false, true, execaSync);603test('Can use generators with error.all = pipe + transform, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', false, true, false, true, execaSync);604test('Can use generators with result.all = pipe + transform, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', false, true, false, true, execaSync);605test('Can use generators with error.all = pipe + transform, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', false, true, false, true, execaSync);606test('Can use generators with result.all = transform + transform, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, false, false, true, execaSync);607test('Can use generators with error.all = transform + transform, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, false, false, true, execaSync);608test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, false, false, true, execaSync);609test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, false, false, true, execaSync);610test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, false, false, true, execaSync);611test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, false, false, true, execaSync);612test('Can use generators with result.all = transform + pipe, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, false, true, true, execaSync);613test('Can use generators with error.all = transform + pipe, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, false, true, true, execaSync);614test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, false, true, true, execaSync);615test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, false, true, true, execaSync);616test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, false, true, true, execaSync);617test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, false, true, true, execaSync);618test('Can use generators with result.all = pipe + transform, objectMode, sync, lines', testGeneratorAll, true, 'utf8', true, true, false, true, execaSync);619test('Can use generators with error.all = pipe + transform, objectMode, sync, lines', testGeneratorAll, false, 'utf8', true, true, false, true, execaSync);620test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, true, 'buffer', true, true, false, true, execaSync);621test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync, lines', testGeneratorAll, false, 'buffer', true, true, false, true, execaSync);622test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, true, 'hex', true, true, false, true, execaSync);623test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync, lines', testGeneratorAll, false, 'hex', true, true, false, true, execaSync);624625const testInputOption = async (t, type, execaMethod) => {626 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});627 t.is(stdout, foobarUppercase);
152 unmodified lines
modified:test/stdio/lines.js+14 added-8 removed
1import {Buffer} from 'node:buffer';2import {once} from 'node:events';1import {Writable} from 'node:stream';2import test from 'ava';3import {MaxBufferError} from 'get-stream';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {fullStdio} from '../helpers/stdio.js';7import {getOutputsGenerator} from '../helpers/generator.js';8import {foobarString, foobarObject} from '../helpers/input.js';11import {assertStreamOutput, assertIterableChunks} from '../helpers/convert.js';9import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';10import {11 simpleFull,12 simpleChunks,13 simpleFullUint8Array,
148 unmodified lines
162 t.is(error.cause, cause);163 t.deepEqual(error.stdout, noNewlinesChunks.slice(0, 2));164});165166test('"lines: true" stops on stream error event', async t => {167 const cause = new Error(foobarString);168 const subprocess = getSimpleChunkSubprocessAsync();169 subprocess.stdout.emit('error', cause);170 const error = await t.throwsAsync(subprocess);171 t.is(error.cause, cause);172 t.deepEqual(error.stdout, []);173});174175const testAsyncIteration = async (t, expectedLines, stripFinalNewline) => {176 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});177 t.false(subprocess.stdout.readableObjectMode);178 await assertStreamOutput(t, subprocess.stdout, simpleFull);
5 unmodified lines
184test('"lines: true" works with stream async iteration, stripFinalNewline', testAsyncIteration, noNewlinesChunks, true);185186const testDataEvents = async (t, expectedLines, stripFinalNewline) => {187 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});181 const [firstLine] = await once(subprocess.stdout, 'data');182 t.deepEqual(firstLine, Buffer.from(simpleLines[0]));188 await assertStreamDataEvents(t, subprocess.stdout, simpleFull);189 const {stdout} = await subprocess;190 t.deepEqual(stdout, expectedLines);191};192193test('"lines: true" works with stream "data" events', testDataEvents, simpleLines, false);194test('"lines: true" works with stream "data" events, stripFinalNewline', testDataEvents, noNewlinesChunks, true);195196const testWritableStream = async (t, expectedLines, stripFinalNewline) => {191 const lines = [];197 let output = '';198 const writable = new Writable({199 write(line, encoding, done) {194 lines.push(line.toString());200 output += line.toString();201 done();202 },203 decodeStrings: false,204 });205 const {stdout} = await getSimpleChunkSubprocessAsync({stripFinalNewline, stdout: ['pipe', writable]});200 t.deepEqual(lines, simpleLines);206 t.deepEqual(output, simpleFull);207 t.deepEqual(stdout, expectedLines);208};209210test('"lines: true" works with writable streams targets', testWritableStream, simpleLines, false);
11 unmodified lines
modified:test/stream/all.js+4 added
23 unmodified lines
24};2526test('result.all is defined', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execa);27test('result.all is defined, encoding "buffer"', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execa);28test('result.all is defined, lines', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execa);29test('result.all is defined, stripFinalNewline', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execa);30test('result.all is defined, encoding "buffer", stripFinalNewline', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execa);31test('result.all is defined, lines, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execa);32test('result.all is defined, failure', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execa);33test('result.all is defined, encoding "buffer", failure', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execa);34test('result.all is defined, lines, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execa);35test('result.all is defined, stripFinalNewline, failure', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execa);36test('result.all is defined, encoding "buffer", stripFinalNewline, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execa);37test('result.all is defined, lines, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execa);38test('result.all is defined, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execaSync);39test('result.all is defined, encoding "buffer", sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execaSync);40test('result.all is defined, lines, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execaSync);41test('result.all is defined, stripFinalNewline, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execaSync);
87 unmodified lines