Improve `encoding` option (#958)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 15ab4e6 · Browse files · 22 files·+305 added−204 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+305 added−204 removed
- tests:+213 added−86 removed
- other:+92 added−118 removed
Provenance
- Commit
507b09c- Tree
3ad7b47- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
15ab4e6
22 files changed+305 added−204 removed
modified:lib/convert/add.js+4 added-6 removed
112345678101191013141511121314import {BINARY_ENCODINGS} from '../arguments/encoding.js';import {initializeConcurrentStreams} from './concurrent.js';import {createReadable} from './readable.js';import {createWritable} from './writable.js';import {createDuplex} from './duplex.js';import {createIterable} from './iterable.js';
export const addConvertedStreams = (subprocess, {encoding}) => { const concurrentStreams = initializeConcurrentStreams(); const useBinaryEncoding = BINARY_ENCODINGS.has(encoding); subprocess.readable = createReadable.bind(undefined, {subprocess, concurrentStreams, useBinaryEncoding}); subprocess.readable = createReadable.bind(undefined, {subprocess, concurrentStreams, encoding}); subprocess.writable = createWritable.bind(undefined, {subprocess, concurrentStreams}); subprocess.duplex = createDuplex.bind(undefined, {subprocess, concurrentStreams, useBinaryEncoding}); subprocess.iterable = createIterable.bind(undefined, subprocess, useBinaryEncoding); subprocess[Symbol.asyncIterator] = createIterable.bind(undefined, subprocess, useBinaryEncoding, {}); subprocess.duplex = createDuplex.bind(undefined, {subprocess, concurrentStreams, encoding}); subprocess.iterable = createIterable.bind(undefined, subprocess, encoding); subprocess[Symbol.asyncIterator] = createIterable.bind(undefined, subprocess, encoding, {});};modified:lib/convert/duplex.js+4 added-3 removed
12345677 unmodified lines151617181819192021222323242526272817 unmodified linesimport {Duplex} from 'node:stream';import {callbackify} from 'node:util';import {BINARY_ENCODINGS} from '../arguments/encoding.js';import { getSubprocessStdout, getReadableOptions, getReadableMethods,7 unmodified lines onWritableDestroy,} from './writable.js';
// Create a `Duplex` stream combining bothexport const createDuplex = ({subprocess, concurrentStreams, useBinaryEncoding}, {from, to, binary: binaryOption = true, preserveNewlines = true} = {}) => { const binary = binaryOption || useBinaryEncoding;export const createDuplex = ({subprocess, concurrentStreams, encoding}, {from, to, binary: binaryOption = true, preserveNewlines = true} = {}) => { const binary = binaryOption || BINARY_ENCODINGS.has(encoding); const {subprocessStdout, waitReadableDestroy} = getSubprocessStdout(subprocess, from, concurrentStreams); const {subprocessStdin, waitWritableFinal, waitWritableDestroy} = getSubprocessStdin(subprocess, to, concurrentStreams); const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary); const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, preserveNewlines}); const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, encoding, preserveNewlines}); const duplex = new Duplex({ read, ...getWritableMethods(subprocessStdin, subprocess, waitWritableFinal), destroy: callbackify(onDuplexDestroy.bind(undefined, {subprocessStdout, subprocessStdin, subprocess, waitReadableDestroy, waitWritableFinal, waitWritableDestroy})),17 unmodified linesmodified:lib/convert/iterable.js+4 added-3 removed
12344567899101111121314151610 unmodified linesimport {BINARY_ENCODINGS} from '../arguments/encoding.js';import {getReadable} from '../pipe/validate.js';import {iterateOnSubprocessStream} from './loop.js';
export const createIterable = (subprocess, useBinaryEncoding, {export const createIterable = (subprocess, encoding, { from, binary: binaryOption = false, preserveNewlines = false,} = {}) => { const binary = binaryOption || useBinaryEncoding; const binary = binaryOption || BINARY_ENCODINGS.has(encoding); const subprocessStdout = getReadable(subprocess, from); const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: true, preserveNewlines}); const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: true, encoding, preserveNewlines}); return iterateOnStdoutData(onStdoutData, subprocessStdout, subprocess);};
const iterateOnStdoutData = async function * (onStdoutData, subprocessStdout, subprocess) {10 unmodified linesmodified:lib/convert/loop.js+12 added-12 removed
1 unmodified line2 import {getEncodingTransformGenerator} from '../stdio/encoding-transform.js';3 import {getSplitLinesGenerator} from '../stdio/split.js';4 5 // Iterate over lines of `subprocess.stdout`, used by `subprocess.readable|duplex|iterable()`6-export const iterateOnSubprocessStream = ({subprocessStdout, subprocess, binary, shouldEncode, preserveNewlines}) => {6+export const iterateOnSubprocessStream = ({subprocessStdout, subprocess, binary, shouldEncode, encoding, preserveNewlines}) => {7 const controller = new AbortController();8 stopReadingOnExit(subprocess, controller);9 return iterateOnStream({10 stream: subprocessStdout,11 controller,12- writableObjectMode: subprocessStdout.readableObjectMode,12 binary,14- shouldEncode,15- shouldSplit: true,13+ shouldEncode: shouldEncode && !subprocessStdout.readableObjectMode,14+ encoding,15+ shouldSplit: !subprocessStdout.readableObjectMode,16 preserveNewlines,17 });18 };19 11 unmodified lines31 stopReadingOnStreamEnd(controller, onStreamEnd);32 return iterateOnStream({33 stream,34 controller,35- writableObjectMode: false,35 binary: encoding === 'buffer',36 shouldEncode: true,37+ encoding,38 shouldSplit: lines,39 preserveNewlines: !stripFinalNewline,40 });41 };5 unmodified lines47 controller.abort();48 }49 };50 51-const iterateOnStream = ({stream, controller, writableObjectMode, binary, shouldEncode, shouldSplit, preserveNewlines}) => {51+const iterateOnStream = ({stream, controller, binary, shouldEncode, encoding, shouldSplit, preserveNewlines}) => {52 const onStdoutChunk = on(stream, 'data', {53 signal: controller.signal,54 highWaterMark: HIGH_WATER_MARK,55 // Backward compatibility with older name for this option56 // See https://github.com/nodejs/node/pull/52080#discussion_r152522786157 // @todo Remove after removing support for Node 2158 highWatermark: HIGH_WATER_MARK,59 });60- return iterateOnData({onStdoutChunk, controller, writableObjectMode, binary, shouldEncode, shouldSplit, preserveNewlines});60+ return iterateOnData({onStdoutChunk, controller, binary, shouldEncode, encoding, shouldSplit, preserveNewlines});61 };62 63 // @todo: replace with `getDefaultHighWaterMark(true)` after dropping support for Node <18.17.064 export const DEFAULT_OBJECT_HIGH_WATER_MARK = 16;3 unmodified lines68 // Therefore, we use the value of `getDefaultHighWaterMark(true)`.69 // Note: this option does not exist on Node 18, but this is ok since the logic works without it. It just consumes more memory.70 const HIGH_WATER_MARK = DEFAULT_OBJECT_HIGH_WATER_MARK;71 72-const iterateOnData = async function * ({onStdoutChunk, controller, writableObjectMode, binary, shouldEncode, shouldSplit, preserveNewlines}) {73- const {encodeChunk, encodeChunkFinal, splitLines, splitLinesFinal} = getTransforms({writableObjectMode, binary, shouldEncode, shouldSplit, preserveNewlines});72+const iterateOnData = async function * ({onStdoutChunk, controller, binary, shouldEncode, encoding, shouldSplit, preserveNewlines}) {73+ const {encodeChunk, encodeChunkFinal, splitLines, splitLinesFinal} = getTransforms({binary, shouldEncode, encoding, shouldSplit, preserveNewlines});74 75 try {76 for await (const [chunk] of onStdoutChunk) {77 yield * handleChunk(encodeChunk, splitLines, chunk);6 unmodified lines84 yield * handleFinalChunks(encodeChunkFinal, splitLines, splitLinesFinal);85 }86 };87 88-const getTransforms = ({writableObjectMode, binary, shouldEncode, shouldSplit, preserveNewlines}) => {88+const getTransforms = ({binary, shouldEncode, encoding, shouldSplit, preserveNewlines}) => {89 const {90 transform: encodeChunk = identityGenerator,91 final: encodeChunkFinal = noopGenerator,92- } = getEncodingTransformGenerator(binary, writableObjectMode || !shouldEncode) ?? {};92+ } = getEncodingTransformGenerator(binary, encoding, !shouldEncode) ?? {};93 const {94 transform: splitLines = identityGenerator,95 final: splitLinesFinal = noopGenerator,96- } = getSplitLinesGenerator(binary, preserveNewlines, writableObjectMode || !shouldSplit, {}) ?? {};96+ } = getSplitLinesGenerator(binary, preserveNewlines, !shouldSplit, {}) ?? {};97 return {encodeChunk, encodeChunkFinal, splitLines, splitLinesFinal};98 };99 100 const identityGenerator = function * (chunk) {18 unmodified linesmodified:lib/convert/readable.js+6 added-5 removed
12345674 unmodified lines1213141515161617181919202122232414 unmodified lines3940414242434444454647484946 unmodified linesimport {Readable} from 'node:stream';import {callbackify} from 'node:util';import {BINARY_ENCODINGS} from '../arguments/encoding.js';import {getReadable} from '../pipe/validate.js';import {addConcurrentStream, waitForConcurrentStreams} from './concurrent.js';import { createDeferred,4 unmodified lines} from './shared.js';import {iterateOnSubprocessStream, DEFAULT_OBJECT_HIGH_WATER_MARK} from './loop.js';
// Create a `Readable` stream that forwards from `stdout` and awaits the subprocessexport const createReadable = ({subprocess, concurrentStreams, useBinaryEncoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {}) => { const binary = binaryOption || useBinaryEncoding;export const createReadable = ({subprocess, concurrentStreams, encoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {}) => { const binary = binaryOption || BINARY_ENCODINGS.has(encoding); const {subprocessStdout, waitReadableDestroy} = getSubprocessStdout(subprocess, from, concurrentStreams); const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary); const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, preserveNewlines}); const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, encoding, preserveNewlines}); const readable = new Readable({ read, destroy: callbackify(onReadableDestroy.bind(undefined, {subprocessStdout, subprocess, waitReadableDestroy})), highWaterMark: readableHighWaterMark,14 unmodified linesexport const getReadableOptions = ({readableEncoding, readableObjectMode, readableHighWaterMark}, binary) => binary ? {readableEncoding, readableObjectMode, readableHighWaterMark} : {readableEncoding, readableObjectMode: true, readableHighWaterMark: DEFAULT_OBJECT_HIGH_WATER_MARK};
export const getReadableMethods = ({subprocessStdout, subprocess, binary, preserveNewlines}) => {export const getReadableMethods = ({subprocessStdout, subprocess, binary, encoding, preserveNewlines}) => { const onStdoutDataDone = createDeferred(); const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: !binary, preserveNewlines}); const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: !binary, encoding, preserveNewlines});
return { read() { onRead(this, onStdoutData, onStdoutDataDone);46 unmodified linesdeleted:lib/stdio/encoding-final.js-36 removed
1-import {StringDecoder} from 'node:string_decoder';2-3-// Apply the `encoding` option using an implicit generator.4-// This encodes the final output of `stdout`/`stderr`.5-export const handleStreamsEncoding = ({options: {encoding}, direction, optionName, objectMode}) => {6- if (!shouldEncodeOutput({encoding, direction, objectMode})) {7- return [];8- }9-10- const stringDecoder = new StringDecoder(encoding);11- return [{12- type: 'generator',13- value: {14- transform: encodingStringGenerator.bind(undefined, stringDecoder),15- final: encodingStringFinal.bind(undefined, stringDecoder),16- binary: true,17- },18- optionName,19- }];20-};21-22-const shouldEncodeOutput = ({encoding, direction, objectMode}) => direction === 'output'23- && encoding !== 'utf8'24- && encoding !== 'buffer'25- && !objectMode;26-27-const encodingStringGenerator = function * (stringDecoder, chunk) {28- yield stringDecoder.write(chunk);29-};30-31-const encodingStringFinal = function * (stringDecoder) {32- const lastChunk = stringDecoder.end();33- if (lastChunk !== '') {34- yield lastChunk;35- }36-};modified:lib/stdio/encoding-transform.js+12 added-11 removed
1 import {Buffer} from 'node:buffer';2-import {isUint8Array} from './uint-array.js';2+import {StringDecoder} from 'node:string_decoder';3+import {isUint8Array, bufferToUint8Array} from './uint-array.js';4 5 /*6 When using generators, add an internal generator that converts chunks from `Buffer` to `string` or `Uint8Array`.7 This allows generator functions to operate with those types instead.5 unmodified lines13 However, those are converted to Buffer:14 - on writes: `Duplex.writable` `decodeStrings: true` default option15 - on reads: `Duplex.readable` `readableEncoding: null` default option16 */16-export const getEncodingTransformGenerator = (binary, writableObjectMode) => {17- if (writableObjectMode) {17+export const getEncodingTransformGenerator = (binary, encoding, skipped) => {18+ if (skipped) {19 return;20 }21 22 if (binary) {23 return {transform: encodingUint8ArrayGenerator.bind(undefined, new TextEncoder())};24 }25 25- const textDecoder = new TextDecoder();26+ const stringDecoder = new StringDecoder(encoding);27 return {27- transform: encodingStringGenerator.bind(undefined, textDecoder),28- final: encodingStringFinal.bind(undefined, textDecoder),28+ transform: encodingStringGenerator.bind(undefined, stringDecoder),29+ final: encodingStringFinal.bind(undefined, stringDecoder),30 };31 };32 33 const encodingUint8ArrayGenerator = function * (textEncoder, chunk) {34 if (Buffer.isBuffer(chunk)) {34- yield new Uint8Array(chunk);35+ yield bufferToUint8Array(chunk);36 } else if (typeof chunk === 'string') {37 yield textEncoder.encode(chunk);38 } else {39 yield chunk;40 }41 };42 42-const encodingStringGenerator = function * (textDecoder, chunk) {43+const encodingStringGenerator = function * (stringDecoder, chunk) {44 yield Buffer.isBuffer(chunk) || isUint8Array(chunk)44- ? textDecoder.decode(chunk, {stream: true})45+ ? stringDecoder.write(chunk)46 : chunk;47 };48 48-const encodingStringFinal = function * (textDecoder) {49- const lastChunk = textDecoder.decode();49+const encodingStringFinal = function * (stringDecoder) {50+ const lastChunk = stringDecoder.end();51 if (lastChunk !== '') {52 yield lastChunk;53 }54 };modified:lib/stdio/generator.js+6 added-5 removed
141 unmodified lines142 export const generatorToDuplexStream = ({143 value,144 value: {transform, final, writableObjectMode, readableObjectMode},145 optionName,146-}) => {147- const generators = addInternalGenerators(value, optionName);146+}, {encoding}) => {147+ const generators = addInternalGenerators(value, encoding, optionName);148 const transformAsync = isAsyncGenerator(transform);149 const finalAsync = isAsyncGenerator(final);150 const stream = generatorsToTransform(generators, {transformAsync, finalAsync, writableObjectMode, readableObjectMode});151 return {stream};152 };153 154 export const getGenerators = stdioItems => stdioItems.filter(({type}) => type === 'generator');155 156-export const runGeneratorsSync = (chunks, generators) => {156+export const runGeneratorsSync = (chunks, generators, encoding) => {157 for (const {value, optionName} of generators) {158- const generators = addInternalGenerators(value, optionName);158+ const generators = addInternalGenerators(value, encoding, optionName);159 chunks = runTransformSync(generators, chunks);160 }161 162 return chunks;163 };164 165 const addInternalGenerators = (166 {transform, final, binary, writableObjectMode, readableObjectMode, preserveNewlines},167+ encoding,168 optionName,169 ) => {170 const state = {};171 return [172 {transform: getValidateTransformInput(writableObjectMode, optionName)},172- getEncodingTransformGenerator(binary, writableObjectMode),173+ getEncodingTransformGenerator(binary, encoding, writableObjectMode),174 getSplitLinesGenerator(binary, preserveNewlines, writableObjectMode, state),175 {transform, final},176 {transform: getValidateTransformReturn(readableObjectMode, optionName)},177 getAppendNewlineGenerator({binary, preserveNewlines, readableObjectMode, state}),20 unmodified linesmodified:lib/stdio/handle.js+7 added-9 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 {handleStreamsEncoding} from './encoding-final.js';7 import {normalizeTransforms, getObjectMode} from './generator.js';8 import {forwardStdio, willPipeFileDescriptor} from './forward.js';9 10 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode15 unmodified lines26 const direction = getStreamDirection(initialStdioItems, fdNumber, optionName);27 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({stdioItem, isStdioArray, fdNumber, direction, isSync}));28 const objectMode = getObjectMode(stdioItems, optionName, direction, options);29 validateFileObjectMode(stdioItems, objectMode);31- const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo, objectMode});30+ const normalizedStdioItems = normalizeStdioItems({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo});31 return {direction, objectMode, stdioItems: normalizedStdioItems};32 };33 34 const getOptionName = fdNumber => KNOWN_OPTION_NAMES[fdNumber] ?? `stdio[${fdNumber}]`;61 unmodified lines96 throw new TypeError(`The \`${optionName}: { file: '...' }\` option must be used instead of \`${optionName}: '...'\`.`);97 }98 };99 101-const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo, objectMode}) => {102- const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, direction, stdioState, verboseInfo, objectMode});100+const normalizeStdioItems = ({stdioItems, fdNumber, optionName, addProperties, options, direction, stdioState, verboseInfo}) => {101+ const allStdioItems = addInternalStdioItems({stdioItems, fdNumber, optionName, options, stdioState, verboseInfo});102 const normalizedStdioItems = normalizeTransforms(allStdioItems, optionName, direction, options);104- return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction));103+ return normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction, options));104 };105 107-const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, direction, stdioState, verboseInfo, objectMode}) => willPipeFileDescriptor(stdioItems)106+const addInternalStdioItems = ({stdioItems, fdNumber, optionName, options, stdioState, verboseInfo}) => willPipeFileDescriptor(stdioItems)107 ? [108 ...stdioItems,110- ...handleStreamsEncoding({options, direction, optionName, objectMode}),109 ...handleStreamsVerbose({stdioItems, options, stdioState, verboseInfo, fdNumber, optionName}),110 ]111 : stdioItems;112 113 // Some `stdio` values require Execa to create streams.114 // For example, file paths create file read/write streams.115 // Those transformations are specified in `addProperties`, which is both direction-specific and type-specific.118-const addStreamProperties = (stdioItem, addProperties, direction) => ({116+const addStreamProperties = (stdioItem, addProperties, direction, options) => ({117 ...stdioItem,120- ...addProperties[direction][stdioItem.type](stdioItem),118+ ...addProperties[direction][stdioItem.type](stdioItem, options),119 });120 121 const validateFileObjectMode = (stdioItems, objectMode) => {122 if (!objectMode) {8 unmodified linesmodified:lib/stdio/input-sync.js+1 added-1 removed
30 unmodified lines31 };32 33 const applySingleInputGeneratorsSync = (contents, stdioItems) => {34 const generators = getGenerators(stdioItems).reverse();35- const newContents = runGeneratorsSync(contents, generators);35+ const newContents = runGeneratorsSync(contents, generators, 'utf8');36 validateSerializable(newContents);37 return joinToUint8Array(newContents);38 };39 6 unmodified linesmodified:lib/stdio/output-sync.js+7 added-7 removed
22 unmodified lines23 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 chunks = runOutputGeneratorsSync([uint8ArrayResult], generators, encoding, state);28 const {serializedResult, finalResult} = serializeChunks({chunks, objectMode, encoding, lines, stripFinalNewline});29 const returnedResult = buffer ? finalResult : undefined;30 31 try {7 unmodified lines39 return returnedResult;40 }41 };42 43-const runOutputGeneratorsSync = (chunks, generators, state) => {43+const runOutputGeneratorsSync = (chunks, generators, encoding, state) => {44 try {45- return runGeneratorsSync(chunks, generators);45+ return runGeneratorsSync(chunks, generators, encoding);46 } catch (error) {47 state.error = error;48 return chunks;49 }8 unmodified lines58 const serializedResult = joinToUint8Array(chunks);59 return {serializedResult, finalResult: serializedResult};60 }61 62- const serializedResult = joinToString(chunks);63- if (!lines) {64- return {serializedResult, finalResult: serializedResult};62+ const serializedResult = joinToString(chunks, encoding);63+ if (lines) {64+ return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline)};65 }66 67- return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline)};67+ return {serializedResult, finalResult: serializedResult};68 };69 70 const writeToFiles = (serializedResult, stdioItems) => {71 for (const {type, path} of stdioItems) {33 unmodified linesmodified:lib/stdio/split.js+1 added-1 removed
1 // Split chunks line-wise for generators passed to the `std*` options2-export const getSplitLinesGenerator = (binary, preserveNewlines, writableObjectMode, state) => binary || writableObjectMode2+export const getSplitLinesGenerator = (binary, preserveNewlines, skipped, state) => binary || skipped3 ? undefined4 : initializeSplitLines(preserveNewlines, state);5 6 export const splitLinesSync = (string, preserveNewlines) => {99 unmodified linesmodified:lib/stdio/uint-array.js+15 added-12 removed
1 import {Buffer} from 'node:buffer';2+import {StringDecoder} from 'node:string_decoder';3 4 const {toString: objectToString} = Object.prototype;5 6 export const isArrayBuffer = value => objectToString.call(value) === '[object ArrayBuffer]';7 unmodified lines14 15 const textDecoder = new TextDecoder();16 export const uint8ArrayToString = uint8Array => textDecoder.decode(uint8Array);17 17-export const joinToString = uint8ArraysOrStrings => {18- if (uint8ArraysOrStrings.length === 1 && typeof uint8ArraysOrStrings[0] === 'string') {19- return uint8ArraysOrStrings[0];20- }21-22- const strings = uint8ArraysToStrings(uint8ArraysOrStrings);18+export const joinToString = (uint8ArraysOrStrings, encoding) => {19+ const strings = uint8ArraysToStrings(uint8ArraysOrStrings, encoding);20 return strings.join('');21 };22 26-const uint8ArraysToStrings = uint8ArraysOrStrings => {27- const decoder = new TextDecoder();28- const strings = uint8ArraysOrStrings.map(uint8ArrayOrString => isUint8Array(uint8ArrayOrString)29- ? decoder.decode(uint8ArrayOrString, {stream: true})30- : uint8ArrayOrString);31- const finalString = decoder.decode();23+const uint8ArraysToStrings = (uint8ArraysOrStrings, encoding) => {24+ if (encoding === 'utf8' && uint8ArraysOrStrings.every(uint8ArrayOrString => typeof uint8ArrayOrString === 'string')) {25+ return uint8ArraysOrStrings;26+ }27+28+ const decoder = new StringDecoder(encoding);29+ const strings = uint8ArraysOrStrings30+ .map(uint8ArrayOrString => typeof uint8ArrayOrString === 'string'31+ ? stringToUint8Array(uint8ArrayOrString)32+ : uint8ArrayOrString)33+ .map(uint8Array => decoder.write(uint8Array));34+ const finalString = decoder.end();35 return finalString === '' ? strings : [...strings, finalString];36 };37 38 export const joinToUint8Array = uint8ArraysOrStrings => {31 unmodified linesmodified:lib/stream/subprocess.js+13 added-7 removed
43 unmodified lines44 };45 46 const getAnyStream = async ({stream, fdNumber, encoding, maxBuffer, lines, allMixed, stripFinalNewline, streamInfo}) => {47 if (allMixed) {48- return getStreamLines({stream, fdNumber, encoding, maxBuffer, lines, stripFinalNewline, streamInfo});48+ const iterable = getIterable({stream, fdNumber, encoding, lines, stripFinalNewline, streamInfo});49+ return getStreamAsArray(iterable, {maxBuffer});50 }51 52 if (stream.readableObjectMode) {53 return getStreamAsArray(stream, {maxBuffer});2 unmodified lines56 if (encoding === 'buffer') {57 return new Uint8Array(await getStreamAsArrayBuffer(stream, {maxBuffer}));58 }59 59- if (!lines) {60- return getStream(stream, {maxBuffer});60+ if (lines) {61+ const iterable = getIterable({stream, fdNumber, encoding, lines, stripFinalNewline, streamInfo});62+ return getStreamAsArray(iterable, {maxBuffer});63 }64 63- return getStreamLines({stream, fdNumber, encoding, maxBuffer, lines, stripFinalNewline, streamInfo});65+ if (encoding !== 'utf8') {66+ const iterable = getIterable({stream, fdNumber, encoding, lines, stripFinalNewline, streamInfo});67+ return getStream(iterable, {maxBuffer});68+ }69+70+ return getStream(stream, {maxBuffer});71 };72 66-const getStreamLines = ({stream, fdNumber, encoding, maxBuffer, lines, stripFinalNewline, streamInfo}) => {73+const getIterable = ({stream, fdNumber, encoding, lines, stripFinalNewline, streamInfo}) => {74 const onStreamEnd = waitForStream(stream, fdNumber, streamInfo);68- const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline});69- return getStreamAsArray(iterable, {maxBuffer});75+ return iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline});76 };77 78 // On failure, `result.stdout|stderr|all` should contain the currently buffered stream79 // They are automatically closed and flushed by Node.js when the subprocess exits13 unmodified linesmodified:test/convert/loop.js+27 added-9 removed
17 unmodified lines18 simpleChunksUint8Array,19 simpleLines,20 noNewlinesFull,21 complexFull,22+ complexFullUtf16,23+ complexFullUtf16Uint8Array,24 singleComplexBuffer,25+ singleComplexUtf16Buffer,26 singleComplexUint8Array,27 singleComplexHex,25- singleComplexHexBuffer,26- singleComplexHexUint8Array,28 complexChunks,29 complexChunksEnd,30 } from '../helpers/lines.js';31 import {outputObjectGenerator, getOutputGenerator} from '../helpers/generator.js';20 unmodified lines52 };53 54 // eslint-disable-next-line max-params55 const testText = async (t, expectedChunks, methodName, binary, preserveNewlines, encoding) => {55- const subprocess = getSubprocess(methodName, complexFull, {encoding});56+ const subprocess = getReadWriteSubprocess({encoding});57+ const input = encoding === 'utf16le' ? complexFullUtf16 : complexFull;58+ subprocess.stdin.end(input);59 const stream = subprocess[methodName]({binary, preserveNewlines});60 61 await assertChunks(t, stream, expectedChunks, methodName);62 const expectedOutput = encoding === 'hex'2 unmodified lines65 await assertSubprocessOutput(t, subprocess, expectedOutput);66 };67 68 test('.iterable() can use "binary: true"', testText, [singleComplexUint8Array], 'iterable', true, undefined, 'utf8');69+test('.iterable() can use "binary: true" + "encoding: utf16le"', testText, [complexFullUtf16Uint8Array], 'iterable', true, undefined, 'utf16le');70+test('.iterable() can use "binary: true" + "encoding: "buffer"', testText, [singleComplexUint8Array], 'iterable', true, undefined, 'buffer');71+test('.iterable() can use "binary: true" + "encoding: "hex"', testText, [singleComplexUint8Array], 'iterable', true, undefined, 'hex');72 test('.iterable() can use "binary: undefined"', testText, complexChunks, 'iterable', undefined, undefined, 'utf8');73+test('.iterable() can use "binary: undefined" + "encoding: utf16le"', testText, complexChunks, 'iterable', undefined, undefined, 'utf16le');74 test('.iterable() can use "binary: undefined" + "encoding: buffer"', testText, [singleComplexUint8Array], 'iterable', undefined, undefined, 'buffer');68-test('.iterable() can use "binary: undefined" + "encoding: hex"', testText, [singleComplexHexUint8Array], 'iterable', undefined, undefined, 'hex');75+test('.iterable() can use "binary: undefined" + "encoding: hex"', testText, [singleComplexUint8Array], 'iterable', undefined, undefined, 'hex');76 test('.iterable() can use "binary: false"', testText, complexChunks, 'iterable', false, undefined, 'utf8');77+test('.iterable() can use "binary: false" + "encoding: utf16le"', testText, complexChunks, 'iterable', false, undefined, 'utf16le');78 test('.iterable() can use "binary: false" + "encoding: buffer"', testText, [singleComplexUint8Array], 'iterable', false, undefined, 'buffer');71-test('.iterable() can use "binary: false" + "encoding: hex"', testText, [singleComplexHexUint8Array], 'iterable', false, undefined, 'hex');79+test('.iterable() can use "binary: false" + "encoding: hex"', testText, [singleComplexUint8Array], 'iterable', false, undefined, 'hex');80 test('.iterable() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'iterable', false, true, 'utf8');81 test('.iterable() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'iterable', false, false, 'utf8');82 test('.readable() can use "binary: true"', testText, singleComplexBuffer, 'readable', true, undefined, 'utf8');83+test('.readable() can use "binary: true" + "encoding: utf16le"', testText, singleComplexUtf16Buffer, 'readable', true, undefined, 'utf16le');84+test('.readable() can use "binary: true" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', true, undefined, 'buffer');85+test('.readable() can use "binary: true" + "encoding: hex"', testText, singleComplexBuffer, 'readable', true, undefined, 'hex');86 test('.readable() can use "binary: undefined"', testText, singleComplexBuffer, 'readable', undefined, undefined, 'utf8');87+test('.readable() can use "binary: undefined" + "encoding: utf16le"', testText, singleComplexUtf16Buffer, 'readable', undefined, undefined, 'utf16le');88 test('.readable() can use "binary: undefined" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', undefined, undefined, 'buffer');77-test('.readable() can use "binary: undefined" + "encoding: hex"', testText, [singleComplexHexBuffer], 'readable', undefined, undefined, 'hex');89+test('.readable() can use "binary: undefined" + "encoding: hex"', testText, singleComplexBuffer, 'readable', undefined, undefined, 'hex');90 test('.readable() can use "binary: false"', testText, complexChunksEnd, 'readable', false, undefined, 'utf8');91+test('.readable() can use "binary: false" + "encoding: utf16le"', testText, complexChunksEnd, 'readable', false, undefined, 'utf16le');92 test('.readable() can use "binary: false" + "encoding: buffer"', testText, singleComplexBuffer, 'readable', false, undefined, 'buffer');80-test('.readable() can use "binary: false" + "encoding: hex"', testText, [singleComplexHexBuffer], 'readable', false, undefined, 'hex');93+test('.readable() can use "binary: false" + "encoding: hex"', testText, singleComplexBuffer, 'readable', false, undefined, 'hex');94 test('.readable() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'readable', false, true, 'utf8');95 test('.readable() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'readable', false, false, 'utf8');96 test('.duplex() can use "binary: true"', testText, singleComplexBuffer, 'duplex', true, undefined, 'utf8');97+test('.duplex() can use "binary: true" + "encoding: utf16le"', testText, singleComplexUtf16Buffer, 'duplex', true, undefined, 'utf16le');98+test('.duplex() can use "binary: true" + "encoding: buffer"', testText, singleComplexBuffer, 'duplex', true, undefined, 'buffer');99+test('.duplex() can use "binary: true" + "encoding: hex"', testText, singleComplexBuffer, 'duplex', true, undefined, 'hex');100 test('.duplex() can use "binary: undefined"', testText, singleComplexBuffer, 'duplex', undefined, undefined, 'utf8');101+test('.duplex() can use "binary: undefined" + "encoding: utf16le"', testText, singleComplexUtf16Buffer, 'duplex', undefined, undefined, 'utf16le');102 test('.duplex() can use "binary: undefined" + "encoding: "buffer"', testText, singleComplexBuffer, 'duplex', undefined, undefined, 'buffer');86-test('.duplex() can use "binary: undefined" + "encoding: "hex"', testText, [singleComplexHexBuffer], 'duplex', undefined, undefined, 'hex');103+test('.duplex() can use "binary: undefined" + "encoding: "hex"', testText, singleComplexBuffer, 'duplex', undefined, undefined, 'hex');104 test('.duplex() can use "binary: false"', testText, complexChunksEnd, 'duplex', false, undefined, 'utf8');105+test('.duplex() can use "binary: false" + "encoding: utf16le"', testText, complexChunksEnd, 'duplex', false, undefined, 'utf16le');106 test('.duplex() can use "binary: false" + "encoding: buffer"', testText, singleComplexBuffer, 'duplex', false, undefined, 'buffer');89-test('.duplex() can use "binary: false" + "encoding: hex"', testText, [singleComplexHexBuffer], 'duplex', false, undefined, 'hex');107+test('.duplex() can use "binary: false" + "encoding: hex"', testText, singleComplexBuffer, 'duplex', false, undefined, 'hex');108 test('.duplex() can use "binary: false" + "preserveNewlines: true"', testText, complexChunksEnd, 'duplex', false, true, 'utf8');109 test('.duplex() can use "binary: false" + "preserveNewlines: false"', testText, complexChunks, 'duplex', false, false, 'utf8');110 111 const testTextOutput = async (t, expectedOutput, methodName, preserveNewlines) => {90 unmodified linesmodified:test/helpers/input.js+1 added-3 removed
1 import {Buffer} from 'node:buffer';2 3 const textEncoder = new TextEncoder();4 5-export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);6-5 export const foobarString = 'foobar';6 export const foobarArray = ['foo', 'bar'];7 export const foobarUint8Array = textEncoder.encode(foobarString);8 export const foobarArrayBuffer = foobarUint8Array.buffer;9 export const foobarUint16Array = new Uint16Array(foobarArrayBuffer);10 export const foobarBuffer = Buffer.from(foobarString);11 const foobarUtf16Buffer = Buffer.from(foobarString, 'utf16le');14-export const foobarUtf16Uint8Array = bufferToUint8Array(foobarUtf16Buffer);12+export const foobarUtf16Uint8Array = new Uint8Array(foobarUtf16Buffer);13 export const foobarDataView = new DataView(foobarArrayBuffer);14 export const foobarHex = foobarBuffer.toString('hex');15 export const foobarUppercase = foobarString.toUpperCase();16 export const foobarUppercaseUint8Array = textEncoder.encode(foobarUppercase);3 unmodified linesmodified:test/helpers/lines.js+15 added-8 removed
1 import {Buffer} from 'node:buffer';2-import {bufferToUint8Array} from './input.js';2 3 const textEncoder = new TextEncoder();4 5 export const stringsToUint8Arrays = strings => strings.map(string => stringToUint8Arrays(string, true));5 unmodified lines11 export const simpleFull = 'aaa\nbbb\nccc';12 export const simpleChunks = [simpleFull];13 export const simpleFullUint8Array = textEncoder.encode(simpleFull);14 export const simpleChunksUint8Array = [simpleFullUint8Array];16-export const simpleFullHex = Buffer.from(simpleFull).toString('hex');17-export const simpleChunksBuffer = [Buffer.from(simpleFull)];15+const simpleFullBuffer = Buffer.from(simpleFull);16+export const simpleFullHex = simpleFullBuffer.toString('hex');17+export const simpleChunksBuffer = [simpleFullBuffer];18+export const simpleFullUtf16Inverted = simpleFullBuffer.toString('utf16le');19 const simpleFullUtf16Buffer = Buffer.from(simpleFull, 'utf16le');19-export const simpleFullUtf16Uint8Array = bufferToUint8Array(simpleFullUtf16Buffer);20+export const simpleFullUtf16Uint8Array = new Uint8Array(simpleFullUtf16Buffer);21+export const simpleFullEnd = `${simpleFull}\n`;22+const simpleFullEndBuffer = Buffer.from(simpleFullEnd);23+export const simpleFullEndUtf16Inverted = simpleFullEndBuffer.toString('utf16le');24 export const simpleLines = ['aaa\n', 'bbb\n', 'ccc'];25 export const simpleFullEndLines = ['aaa\n', 'bbb\n', 'ccc\n'];26 export const noNewlinesFull = 'aaabbbccc';27 export const noNewlinesChunks = ['aaa', 'bbb', 'ccc'];28 export const complexFull = '\naaa\r\nbbb\n\nccc';29+const complexFullBuffer = Buffer.from(complexFull);30+const complexFullUtf16Buffer = Buffer.from(complexFull, 'utf16le');31+export const complexFullUtf16 = complexFullUtf16Buffer.toString();32+export const complexFullUtf16Uint8Array = new Uint8Array(complexFullUtf16Buffer);25-export const singleComplexBuffer = [Buffer.from(complexFull)];33+export const singleComplexBuffer = [complexFullBuffer];34+export const singleComplexUtf16Buffer = [complexFullUtf16Buffer];35 export const singleComplexUint8Array = textEncoder.encode(complexFull);27-export const singleComplexHex = Buffer.from(complexFull).toString('hex');28-export const singleComplexHexBuffer = Buffer.from(singleComplexHex);29-export const singleComplexHexUint8Array = textEncoder.encode(singleComplexHex);36+export const singleComplexHex = complexFullBuffer.toString('hex');37 export const complexChunksEnd = ['\n', 'aaa\r\n', 'bbb\n', '\n', 'ccc'];38 export const complexChunks = ['', 'aaa', 'bbb', '', 'ccc'];modified:test/stdio/encoding-final.js+19 added-4 removed
1 unmodified line2 import {exec} from 'node:child_process';3 import process from 'node:process';4 import {promisify} from 'node:util';5 import test from 'ava';6-import getStream, {getStreamAsBuffer} from 'get-stream';6+import getStream from 'get-stream';7 import {execa, execaSync} from '../../index.js';8 import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';9 import {fullStdio} from '../helpers/stdio.js';10 import {outputObjectGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';8 unmodified lines19 compareValues(t, stdio[fdNumber], encoding);20 21 if (execaMethod !== execaSync) {22 const subprocess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});23- const getStreamMethod = encoding === 'buffer' ? getStreamAsBuffer : getStream;24- const result = await getStreamMethod(subprocess.stdio[fdNumber]);25- compareValues(t, result, encoding);23+ const result = await getStream(subprocess.stdio[fdNumber]);24+ compareValues(t, result, 'utf8');25 await subprocess;26 }27 28 if (fdNumber === 3) {190 unmodified lines219 test('Can use string input, encoding "buffer", sync', testEncodingInput, foobarString, foobarUint8Array, 'buffer', execaSync);220 test('Can use Uint8Array input, encoding "buffer", sync', testEncodingInput, foobarUint8Array, foobarUint8Array, 'buffer', execaSync);221 test('Can use string input, encoding "hex", sync', testEncodingInput, foobarString, foobarHex, 'hex', execaSync);222 test('Can use Uint8Array input, encoding "hex", sync', testEncodingInput, foobarUint8Array, foobarHex, 'hex', execaSync);223+224+const testSubprocessEncoding = (t, encoding) => {225+ const subprocess = execa('empty.js', {...fullStdio, encoding});226+ t.is(subprocess.stdout.readableEncoding, null);227+ t.is(subprocess.stderr.readableEncoding, null);228+ t.is(subprocess.stdio[3].readableEncoding, null);229+};230+231+test('Does not modify subprocess.std* encoding, "utf8"', testSubprocessEncoding, 'utf8');232+test('Does not modify subprocess.std* encoding, "utf16le"', testSubprocessEncoding, 'utf16le');233+test('Does not modify subprocess.std* encoding, "buffer"', testSubprocessEncoding, 'buffer');234+test('Does not modify subprocess.std* encoding, "hex"', testSubprocessEncoding, 'hex');235+test('Does not modify subprocess.std* encoding, "base64"', testSubprocessEncoding, 'base64');236+test('Does not modify subprocess.std* encoding, "base64url"', testSubprocessEncoding, 'base64url');237+test('Does not modify subprocess.std* encoding, "latin1"', testSubprocessEncoding, 'latin1');238+test('Does not modify subprocess.std* encoding, "ascii"', testSubprocessEncoding, 'ascii');modified:test/stdio/encoding-transform.js+99 added-35 removed
7 unmodified lines8 import {multibyteChar, multibyteString, multibyteUint8Array, breakingLength, brokenSymbol} from '../helpers/encoding.js';9 10 setFixtureDir();11 12-const getTypeofGenerator = (objectMode, binary) => ({12+const getTypeofGenerator = lines => (objectMode, binary) => ({13 * transform(line) {14- yield Object.prototype.toString.call(line);14+ lines.push(Object.prototype.toString.call(line));15+ yield '';16 },17 objectMode,18 binary,19 });20 20-const assertTypeofChunk = (t, output, encoding, expectedType) => {21- const typeofChunk = Buffer.from(output, encoding === 'buffer' ? undefined : encoding).toString().trim();22- t.is(typeofChunk, `[object ${expectedType}]`);21+const assertTypeofChunk = (t, lines, expectedType) => {22+ t.deepEqual(lines, [`[object ${expectedType}]`]);23 };24 25 // eslint-disable-next-line max-params26 const testGeneratorFirstEncoding = async (t, input, encoding, expectedType, objectMode, binary) => {27+ const lines = [];27- const subprocess = execa('stdin.js', {stdin: getTypeofGenerator(objectMode, binary), encoding});28+ const subprocess = execa('stdin.js', {stdin: getTypeofGenerator(lines)(objectMode, binary), encoding});29 subprocess.stdin.end(input);29- const {stdout} = await subprocess;30- assertTypeofChunk(t, stdout, encoding, expectedType);30+ await subprocess;31+ assertTypeofChunk(t, lines, expectedType);32 };33 33-test('First generator argument is string with default encoding, with string writes', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', false);34-test('First generator argument is string with default encoding, with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'utf8', 'String', false);35-test('First generator argument is string with default encoding, with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'utf8', 'String', false);36-test('First generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false);37-test('First generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'buffer', 'Uint8Array', false);38-test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'buffer', 'Uint8Array', false);39-test('First generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false);40-test('First generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'hex', 'Uint8Array', false);41-test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'hex', 'Uint8Array', false);42-test('First generator argument can be string with objectMode', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', true);43-test('First generator argument can be objects with objectMode', testGeneratorFirstEncoding, foobarObject, 'utf8', 'Object', true);34+test('First generator argument is string with default encoding, with string writes', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', false, undefined);35+test('First generator argument is string with default encoding, with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'utf8', 'String', false, undefined);36+test('First generator argument is string with default encoding, with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'utf8', 'String', false, undefined);37 test('First generator argument is string with default encoding, with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', false, false);38 test('First generator argument is Uint8Array with default encoding, with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'utf8', 'Uint8Array', false, true);39+test('First generator argument is string with encoding "utf16le", with string writes', testGeneratorFirstEncoding, foobarString, 'utf16le', 'String', false, undefined);40+test('First generator argument is string with encoding "utf16le", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'utf16le', 'String', false, undefined);41+test('First generator argument is string with encoding "utf16le", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'utf16le', 'String', false, undefined);42+test('First generator argument is string with encoding "utf16le", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'utf16le', 'String', false, false);43+test('First generator argument is Uint8Array with encoding "utf16le", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'utf16le', 'Uint8Array', false, true);44+test('First generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false, undefined);45+test('First generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'buffer', 'Uint8Array', false, undefined);46+test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'buffer', 'Uint8Array', false, undefined);47 test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false, false);48 test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'buffer', 'Uint8Array', false, true);49+test('First generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, undefined);50+test('First generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'hex', 'Uint8Array', false, undefined);51+test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'hex', 'Uint8Array', false, undefined);52 test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false"', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, false);53 test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true"', testGeneratorFirstEncoding, foobarString, 'hex', 'Uint8Array', false, true);54+test('First generator argument can be string with objectMode', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', true, undefined);55+test('First generator argument can be string with objectMode, "binary: false"', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', true, false);56+test('First generator argument can be string with objectMode, "binary: true"', testGeneratorFirstEncoding, foobarString, 'utf8', 'String', true, true);57+test('First generator argument can be objects with objectMode', testGeneratorFirstEncoding, foobarObject, 'utf8', 'Object', true, undefined);58+test('First generator argument can be objects with objectMode, "binary: false"', testGeneratorFirstEncoding, foobarObject, 'utf8', 'Object', true, false);59+test('First generator argument can be objects with objectMode, "binary: true"', testGeneratorFirstEncoding, foobarObject, 'utf8', 'Object', true, true);60 61 // eslint-disable-next-line max-params62 const testGeneratorFirstEncodingSync = (t, input, encoding, expectedType, objectMode, binary) => {53- const {stdout} = execaSync('stdin.js', {stdin: [[input], getTypeofGenerator(objectMode, binary)], encoding});54- assertTypeofChunk(t, stdout, encoding, expectedType);63+ const lines = [];64+ execaSync('stdin.js', {stdin: [[input], getTypeofGenerator(lines)(objectMode, binary)], encoding});65+ assertTypeofChunk(t, lines, expectedType);66 };67 57-test('First generator argument is string with default encoding, with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', false);58-test('First generator argument is string with default encoding, with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'utf8', 'String', false);59-test('First generator argument is Uint8Array with encoding "buffer", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false);60-test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'buffer', 'Uint8Array', false);61-test('First generator argument is Uint8Array with encoding "hex", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false);62-test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'hex', 'Uint8Array', false);63-test('First generator argument can be string with objectMode, sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', true);64-test('First generator argument can be objects with objectMode, sync', testGeneratorFirstEncodingSync, foobarObject, 'utf8', 'Object', true);68+test('First generator argument is string with default encoding, with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', false, undefined);69+test('First generator argument is string with default encoding, with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'utf8', 'String', false, undefined);70 test('First generator argument is string with default encoding, with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', false, false);71 test('First generator argument is Uint8Array with default encoding, with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'Uint8Array', false, true);72+test('First generator argument is string with encoding "utf16le", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'utf16le', 'String', false, undefined);73+test('First generator argument is string with encoding "utf16le", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'utf16le', 'String', false, undefined);74+test('First generator argument is string with encoding "utf16le", with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'utf16le', 'String', false, false);75+test('First generator argument is Uint8Array with encoding "utf16le", with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'utf16le', 'Uint8Array', false, true);76+test('First generator argument is Uint8Array with encoding "buffer", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false, undefined);77+test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'buffer', 'Uint8Array', false, undefined);78 test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false, false);79 test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'buffer', 'Uint8Array', false, true);80+test('First generator argument is Uint8Array with encoding "hex", with string writes, sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false, undefined);81+test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes, sync', testGeneratorFirstEncodingSync, foobarUint8Array, 'hex', 'Uint8Array', false, undefined);82 test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false, false);83 test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'hex', 'Uint8Array', false, true);84+test('First generator argument can be string with objectMode, sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', true, undefined);85+test('First generator argument can be string with objectMode, "binary: false", sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', true, false);86+test('First generator argument can be string with objectMode, "binary: true", sync', testGeneratorFirstEncodingSync, foobarString, 'utf8', 'String', true, true);87+test('First generator argument can be objects with objectMode, sync', testGeneratorFirstEncodingSync, foobarObject, 'utf8', 'Object', true, undefined);88+test('First generator argument can be objects with objectMode, "binary: false", sync', testGeneratorFirstEncodingSync, foobarObject, 'utf8', 'Object', true, false);89+test('First generator argument can be objects with objectMode, "binary: true", sync', testGeneratorFirstEncodingSync, foobarObject, 'utf8', 'Object', true, true);90 91 const testEncodingIgnored = async (t, encoding) => {92 const input = Buffer.from(foobarString).toString(encoding);93 const subprocess = execa('stdin.js', {stdin: noopGenerator(true)});8 unmodified lines102 test('Write call encoding "base64" is ignored with objectMode', testEncodingIgnored, 'base64');103 104 // eslint-disable-next-line max-params105 const testGeneratorNextEncoding = async (t, input, encoding, firstObjectMode, secondObjectMode, expectedType, execaMethod) => {106+ const lines = [];87- const {stdout} = await execaMethod('noop.js', ['other'], {107+ await execaMethod('noop.js', ['other'], {108 stdout: [109 getOutputGenerator(input)(firstObjectMode),90- getTypeofGenerator(secondObjectMode),110+ getTypeofGenerator(lines)(secondObjectMode),111 ],112 encoding,113 });94- const output = Array.isArray(stdout) ? stdout[0] : stdout;95- assertTypeofChunk(t, output, encoding, expectedType);114+ assertTypeofChunk(t, lines, expectedType);115 };116 117 test('Next generator argument is string with default encoding, with string writes', testGeneratorNextEncoding, foobarString, 'utf8', false, false, 'String', execa);118 test('Next generator argument is string with default encoding, with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'utf8', true, false, 'String', execa);119 test('Next generator argument is string with default encoding, with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String', execa);120 test('Next generator argument is string with default encoding, with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String', execa);121 test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'Uint8Array', execa);122 test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'Uint8Array', execa);123+test('Next generator argument is string with encoding "utf16le", with string writes', testGeneratorNextEncoding, foobarString, 'utf16le', false, false, 'String', execa);124+test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'utf16le', true, false, 'String', execa);125+test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'utf16le', true, true, 'String', execa);126+test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'utf16le', false, false, 'String', execa);127+test('Next generator argument is Uint8Array with encoding "utf16le",, with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'utf16le', true, false, 'Uint8Array', execa);128+test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'utf16le', true, true, 'Uint8Array', execa);129 test('Next generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array', execa);130 test('Next generator argument is string with encoding "buffer", with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'String', execa);131 test('Next generator argument is string with encoding "buffer", with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'String', execa);132 test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array', execa);8 unmodified lines141 test('Next generator argument is string with default encoding, with string writes, objectMode both, sync', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String', execaSync);142 test('Next generator argument is string with default encoding, with Uint8Array writes, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String', execaSync);143 test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'Uint8Array', execaSync);144 test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'Uint8Array', execaSync);145+test('Next generator argument is string with encoding "utf16le", with string writes, sync', testGeneratorNextEncoding, foobarString, 'utf16le', false, false, 'String', execaSync);146+test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode first, sync', testGeneratorNextEncoding, foobarString, 'utf16le', true, false, 'String', execaSync);147+test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode both, sync', testGeneratorNextEncoding, foobarString, 'utf16le', true, true, 'String', execaSync);148+test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf16le', false, false, 'String', execaSync);149+test('Next generator argument is Uint8Array with encoding "utf16le",, with Uint8Array writes, objectMode first, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf16le', true, false, 'Uint8Array', execaSync);150+test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes, objectMode both, sync', testGeneratorNextEncoding, foobarUint8Array, 'utf16le', true, true, 'Uint8Array', execaSync);151 test('Next generator argument is Uint8Array with encoding "buffer", with string writes, sync', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array', execaSync);152 test('Next generator argument is string with encoding "buffer", with string writes, objectMode first, sync', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'String', execaSync);153 test('Next generator argument is string with encoding "buffer", with string writes, objectMode both, sync', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'String', execaSync);154 test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array', execaSync);4 unmodified lines159 test('Next generator argument is object with default encoding, with object writes, objectMode first, sync', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object', execaSync);160 test('Next generator argument is object with default encoding, with object writes, objectMode both, sync', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object', execaSync);161 162 const testFirstOutputGeneratorArgument = async (t, fdNumber, execaMethod) => {132- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));133- t.deepEqual(stdio[fdNumber], ['[object String]']);163+ const lines = [];164+ await execaMethod('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(lines)(true)));165+ assertTypeofChunk(t, lines, 'String');166 };167 168 test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1, execa);169 test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2, execa);16 unmodified lines186 };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);43 unmodified linesmodified:test/stdio/generator.js+14 added-1 removed
97 unmodified lines98 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;102- t.is(stdout, 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']);629 unmodified linesmodified:test/stdio/lines.js+14 added-25 removed
96 unmodified lines97 test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, execa);98 test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, execaSync);99 100 // eslint-disable-next-line max-params101-const testBinaryEncoding = async (t, expectedOutput, encoding, stripFinalNewline, execaMethod) => {102- const {stdout} = await getSimpleChunkSubprocess(execaMethod, {encoding, stripFinalNewline});101+const testEncoding = async (t, input, expectedOutput, encoding, stripFinalNewline, execaMethod) => {102+ const {stdout} = await execaMethod('stdin.js', {lines: true, stripFinalNewline, encoding, input});103 t.deepEqual(stdout, expectedOutput);104 };105 106-test('"lines: true" is a noop with "encoding: buffer"', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execa);107-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execa);108-test('"lines: true" is a noop with "encoding: hex"', testBinaryEncoding, simpleFullHex, 'hex', false, execa);109-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testBinaryEncoding, simpleFullHex, 'hex', true, execa);110-test('"lines: true" is a noop with "encoding: buffer", sync', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execaSync);111-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execaSync);112-test('"lines: true" is a noop with "encoding: hex", sync', testBinaryEncoding, simpleFullHex, 'hex', false, execaSync);113-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testBinaryEncoding, simpleFullHex, 'hex', true, execaSync);106+test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execa);107+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execa);108+test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);109+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);110+test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', false, execa);111+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, execa);112+test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execaSync);113+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execaSync);114+test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);115+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);116+test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', false, execaSync);117+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, execaSync);118 115-const testTextEncoding = async (t, expectedLines, stripFinalNewline, execaMethod) => {116- const {stdout} = await execaMethod('stdin.js', {117- lines: true,118- stripFinalNewline,119- encoding: 'utf16le',120- input: simpleFullUtf16Uint8Array,121- });122- t.deepEqual(stdout, expectedLines);123-};124-125-test('"lines: true" is a noop with "encoding: utf16"', testTextEncoding, simpleLines, false, execa);126-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testTextEncoding, noNewlinesChunks, true, execa);127-test('"lines: true" is a noop with "encoding: utf16", sync', testTextEncoding, simpleLines, false, execaSync);128-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testTextEncoding, noNewlinesChunks, true, execaSync);129-119 const testLinesNoBuffer = async (t, execaMethod) => {120 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {buffer: false});121 t.is(stdout, undefined);122 };88 unmodified linesmodified:test/stdio/split.js+24 added-1 removed
11 unmodified lines12 import {13 simpleFull,14 simpleChunks,15 simpleFullUint8Array,16+ simpleFullUtf16Inverted,17+ simpleFullUtf16Uint8Array,18 simpleChunksUint8Array,19+ simpleFullEnd,20+ simpleFullEndUtf16Inverted,21 simpleFullHex,22 simpleLines,23 simpleFullEndLines,24 noNewlinesFull,1 unmodified line26 } from '../helpers/lines.js';27 28 setFixtureDir();29 26-const simpleFullEnd = `${simpleFull}\n`;30 const simpleFullEndChunks = [simpleFullEnd];31 const windowsFull = 'aaa\r\nbbb\r\nccc';32 const windowsFullEnd = `${windowsFull}\r\n`;33 const windowsChunks = [windowsFull];170 unmodified lines204 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);98 unmodified lines