Rename 2 files with wrong file names (#865)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 2ef9e86 · Browse files · 10 files·+491 added−491 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+491 added−491 removed
- tests:+384 added−384 removed
- other:+107 added−107 removed
Provenance
- Commit
4bd0fe3- Tree
82a4088- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
2ef9e86
10 files changed+491 added−491 removed
deleted:lib/stdio/encoding-end.js-49 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import {Buffer} from 'node:buffer';import {isUint8Array} from '../utils.js';
/*When using generators, add an internal generator that converts chunks from `Buffer` to `string` or `Uint8Array`.This allows generator functions to operate with those types instead.Chunks might be Buffer, Uint8Array or strings since:- `childProcess.stdout|stderr` emits Buffers- `childProcess.stdin.write()` accepts Buffer, Uint8Array or string- Previous generators might return Uint8Array or string
However, those are converted to Buffer:- on writes: `Duplex.writable` `decodeStrings: true` default option- on reads: `Duplex.readable` `readableEncoding: null` default option*/export const getEncodingStartGenerator = encoding => { if (encoding === 'buffer') { return {transform: encodingStartBufferGenerator.bind(undefined, new TextEncoder())}; }
const textDecoder = new TextDecoder(); return { transform: encodingStartStringGenerator.bind(undefined, textDecoder), final: encodingStartStringFinal.bind(undefined, textDecoder), };};
const encodingStartBufferGenerator = function * (textEncoder, chunk) { if (Buffer.isBuffer(chunk)) { yield new Uint8Array(chunk); } else if (typeof chunk === 'string') { yield textEncoder.encode(chunk); } else { yield chunk; }};
const encodingStartStringGenerator = function * (textDecoder, chunk) { yield Buffer.isBuffer(chunk) || isUint8Array(chunk) ? textDecoder.decode(chunk, {stream: true}) : chunk;};
const encodingStartStringFinal = function * (textDecoder) { const lastChunk = textDecoder.decode(); if (lastChunk !== '') { yield lastChunk; }};added:lib/stdio/encoding-final.js+55 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import {StringDecoder} from 'node:string_decoder';import {isUint8Array} from '../utils.js';import {willPipeStreams} from './forward.js';
// Apply the `encoding` option using an implicit generator.// This encodes the final output of `stdout`/`stderr`.export const handleStreamsEncoding = (stdioStreams, {encoding}, isSync) => { const newStdioStreams = stdioStreams.map(stdioStream => ({...stdioStream, encoding})); if (!shouldEncodeOutput(newStdioStreams, encoding, isSync)) { return newStdioStreams; }
const objectMode = newStdioStreams.findLast(({type}) => type === 'generator')?.value.objectMode === true; const stringDecoder = new StringDecoder(encoding); const generator = objectMode ? { transform: encodingObjectGenerator.bind(undefined, stringDecoder), } : { transform: encodingStringGenerator.bind(undefined, stringDecoder), final: encodingStringFinal.bind(undefined, stringDecoder), }; return [ ...newStdioStreams, { ...newStdioStreams[0], type: 'generator', value: {...generator, binary: true, objectMode}, encoding: 'buffer', }, ];};
const shouldEncodeOutput = (stdioStreams, encoding, isSync) => stdioStreams[0].direction === 'output' && !IGNORED_ENCODINGS.has(encoding) && !isSync && willPipeStreams(stdioStreams);
// eslint-disable-next-line unicorn/text-encoding-identifier-caseconst IGNORED_ENCODINGS = new Set(['utf8', 'utf-8', 'buffer']);
const encodingStringGenerator = function * (stringDecoder, chunk) { yield stringDecoder.write(chunk);};
const encodingStringFinal = function * (stringDecoder) { const lastChunk = stringDecoder.end(); if (lastChunk !== '') { yield lastChunk; }};
const encodingObjectGenerator = function * (stringDecoder, chunk) { yield isUint8Array(chunk) ? stringDecoder.end(chunk) : chunk;};deleted:lib/stdio/encoding-start.js-55 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import {StringDecoder} from 'node:string_decoder';import {isUint8Array} from '../utils.js';import {willPipeStreams} from './forward.js';
// Apply the `encoding` option using an implicit generator.// This encodes the final output of `stdout`/`stderr`.export const handleStreamsEncoding = (stdioStreams, {encoding}, isSync) => { const newStdioStreams = stdioStreams.map(stdioStream => ({...stdioStream, encoding})); if (!shouldEncodeOutput(newStdioStreams, encoding, isSync)) { return newStdioStreams; }
const objectMode = newStdioStreams.findLast(({type}) => type === 'generator')?.value.objectMode === true; const stringDecoder = new StringDecoder(encoding); const generator = objectMode ? { transform: encodingEndObjectGenerator.bind(undefined, stringDecoder), } : { transform: encodingEndStringGenerator.bind(undefined, stringDecoder), final: encodingEndStringFinal.bind(undefined, stringDecoder), }; return [ ...newStdioStreams, { ...newStdioStreams[0], type: 'generator', value: {...generator, binary: true, objectMode}, encoding: 'buffer', }, ];};
const shouldEncodeOutput = (stdioStreams, encoding, isSync) => stdioStreams[0].direction === 'output' && !IGNORED_ENCODINGS.has(encoding) && !isSync && willPipeStreams(stdioStreams);
// eslint-disable-next-line unicorn/text-encoding-identifier-caseconst IGNORED_ENCODINGS = new Set(['utf8', 'utf-8', 'buffer']);
const encodingEndStringGenerator = function * (stringDecoder, chunk) { yield stringDecoder.write(chunk);};
const encodingEndStringFinal = function * (stringDecoder) { const lastChunk = stringDecoder.end(); if (lastChunk !== '') { yield lastChunk; }};
const encodingEndObjectGenerator = function * (stringDecoder, chunk) { yield isUint8Array(chunk) ? stringDecoder.end(chunk) : chunk;};added:lib/stdio/encoding-transform.js+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import {Buffer} from 'node:buffer';import {isUint8Array} from '../utils.js';
/*When using generators, add an internal generator that converts chunks from `Buffer` to `string` or `Uint8Array`.This allows generator functions to operate with those types instead.Chunks might be Buffer, Uint8Array or strings since:- `childProcess.stdout|stderr` emits Buffers- `childProcess.stdin.write()` accepts Buffer, Uint8Array or string- Previous generators might return Uint8Array or string
However, those are converted to Buffer:- on writes: `Duplex.writable` `decodeStrings: true` default option- on reads: `Duplex.readable` `readableEncoding: null` default option*/export const getEncodingTransformGenerator = encoding => { if (encoding === 'buffer') { return {transform: encodingBufferGenerator.bind(undefined, new TextEncoder())}; }
const textDecoder = new TextDecoder(); return { transform: encodingStringGenerator.bind(undefined, textDecoder), final: encodingStringFinal.bind(undefined, textDecoder), };};
const encodingBufferGenerator = function * (textEncoder, chunk) { if (Buffer.isBuffer(chunk)) { yield new Uint8Array(chunk); } else if (typeof chunk === 'string') { yield textEncoder.encode(chunk); } else { yield chunk; }};
const encodingStringGenerator = function * (textDecoder, chunk) { yield Buffer.isBuffer(chunk) || isUint8Array(chunk) ? textDecoder.decode(chunk, {stream: true}) : chunk;};
const encodingStringFinal = function * (textDecoder) { const lastChunk = textDecoder.decode(); if (lastChunk !== '') { yield lastChunk; }};modified:lib/stdio/generator.js+2 added-2 removed
1 import {generatorsToTransform} from './transform.js';2-import {getEncodingStartGenerator} from './encoding-end.js';2+import {getEncodingTransformGenerator} from './encoding-transform.js';3 import {getLinesGenerator} from './lines.js';4 import {pipeStreams} from './pipeline.js';5 import {isGeneratorOptions, isAsyncGenerator} from './type.js';6 import {getValidateTransformReturn} from './validate.js';65 unmodified lines72 encoding,73 optionName,74 }) => {75 const generators = [76- getEncodingStartGenerator(encoding),76+ getEncodingTransformGenerator(encoding),77 getLinesGenerator(encoding, binary),78 {transform, final},79 {transform: getValidateTransformReturn(readableObjectMode, optionName)},80 ].filter(Boolean);23 unmodified linesmodified:lib/stdio/handle.js+1 added-1 removed
2 unmodified lines3 import {normalizeStdio} from './option.js';4 import {handleNativeStream} from './native.js';5 import {handleInputOptions} from './input.js';6 import {handleStreamsLines} from './lines.js';7-import {handleStreamsEncoding} from './encoding-start.js';7+import {handleStreamsEncoding} from './encoding-final.js';8 import {normalizeGenerators} from './generator.js';9 import {forwardStdio} from './forward.js';10 11 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode85 unmodified linesdeleted:test/stdio/encoding-end.js-196 removed
1-import {Buffer} from 'node:buffer';2-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';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, getChunksGenerator} from '../helpers/generator.js';11-import {foobarObject} from '../helpers/input.js';12-13-const pExec = promisify(exec);14-15-setFixtureDir();16-17-const checkEncoding = async (t, encoding, fdNumber, execaMethod) => {18- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});19- compareValues(t, stdio[fdNumber], encoding);20-21- if (execaMethod !== execaSync) {22- const childProcess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});23- const getStreamMethod = encoding === 'buffer' ? getStreamAsBuffer : getStream;24- const result = await getStreamMethod(childProcess.stdio[fdNumber]);25- compareValues(t, result, encoding);26- await childProcess;27- }28-29- if (fdNumber === 3) {30- return;31- }32-33- const {stdout, stderr} = await pExec(`node noop-fd.js ${fdNumber} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});34- compareValues(t, fdNumber === 1 ? stdout : stderr, encoding);35-};36-37-const compareValues = (t, value, encoding) => {38- if (encoding === 'buffer') {39- t.true(ArrayBuffer.isView(value));40- t.true(BUFFER_TO_ENCODE.equals(value));41- } else {42- t.is(value, BUFFER_TO_ENCODE.toString(encoding));43- }44-};45-46-// This string gives different outputs with each encoding type47-const STRING_TO_ENCODE = '\u1000.';48-const BUFFER_TO_ENCODE = Buffer.from(STRING_TO_ENCODE);49-50-/* eslint-disable unicorn/text-encoding-identifier-case */51-test('can pass encoding "buffer" to stdout', checkEncoding, 'buffer', 1, execa);52-test('can pass encoding "utf8" to stdout', checkEncoding, 'utf8', 1, execa);53-test('can pass encoding "utf-8" to stdout', checkEncoding, 'utf-8', 1, execa);54-test('can pass encoding "utf16le" to stdout', checkEncoding, 'utf16le', 1, execa);55-test('can pass encoding "utf-16le" to stdout', checkEncoding, 'utf-16le', 1, execa);56-test('can pass encoding "ucs2" to stdout', checkEncoding, 'ucs2', 1, execa);57-test('can pass encoding "ucs-2" to stdout', checkEncoding, 'ucs-2', 1, execa);58-test('can pass encoding "latin1" to stdout', checkEncoding, 'latin1', 1, execa);59-test('can pass encoding "binary" to stdout', checkEncoding, 'binary', 1, execa);60-test('can pass encoding "ascii" to stdout', checkEncoding, 'ascii', 1, execa);61-test('can pass encoding "hex" to stdout', checkEncoding, 'hex', 1, execa);62-test('can pass encoding "base64" to stdout', checkEncoding, 'base64', 1, execa);63-test('can pass encoding "base64url" to stdout', checkEncoding, 'base64url', 1, execa);64-test('can pass encoding "buffer" to stderr', checkEncoding, 'buffer', 2, execa);65-test('can pass encoding "utf8" to stderr', checkEncoding, 'utf8', 2, execa);66-test('can pass encoding "utf-8" to stderr', checkEncoding, 'utf-8', 2, execa);67-test('can pass encoding "utf16le" to stderr', checkEncoding, 'utf16le', 2, execa);68-test('can pass encoding "utf-16le" to stderr', checkEncoding, 'utf-16le', 2, execa);69-test('can pass encoding "ucs2" to stderr', checkEncoding, 'ucs2', 2, execa);70-test('can pass encoding "ucs-2" to stderr', checkEncoding, 'ucs-2', 2, execa);71-test('can pass encoding "latin1" to stderr', checkEncoding, 'latin1', 2, execa);72-test('can pass encoding "binary" to stderr', checkEncoding, 'binary', 2, execa);73-test('can pass encoding "ascii" to stderr', checkEncoding, 'ascii', 2, execa);74-test('can pass encoding "hex" to stderr', checkEncoding, 'hex', 2, execa);75-test('can pass encoding "base64" to stderr', checkEncoding, 'base64', 2, execa);76-test('can pass encoding "base64url" to stderr', checkEncoding, 'base64url', 2, execa);77-test('can pass encoding "buffer" to stdio[*]', checkEncoding, 'buffer', 3, execa);78-test('can pass encoding "utf8" to stdio[*]', checkEncoding, 'utf8', 3, execa);79-test('can pass encoding "utf-8" to stdio[*]', checkEncoding, 'utf-8', 3, execa);80-test('can pass encoding "utf16le" to stdio[*]', checkEncoding, 'utf16le', 3, execa);81-test('can pass encoding "utf-16le" to stdio[*]', checkEncoding, 'utf-16le', 3, execa);82-test('can pass encoding "ucs2" to stdio[*]', checkEncoding, 'ucs2', 3, execa);83-test('can pass encoding "ucs-2" to stdio[*]', checkEncoding, 'ucs-2', 3, execa);84-test('can pass encoding "latin1" to stdio[*]', checkEncoding, 'latin1', 3, execa);85-test('can pass encoding "binary" to stdio[*]', checkEncoding, 'binary', 3, execa);86-test('can pass encoding "ascii" to stdio[*]', checkEncoding, 'ascii', 3, execa);87-test('can pass encoding "hex" to stdio[*]', checkEncoding, 'hex', 3, execa);88-test('can pass encoding "base64" to stdio[*]', checkEncoding, 'base64', 3, execa);89-test('can pass encoding "base64url" to stdio[*]', checkEncoding, 'base64url', 3, execa);90-test('can pass encoding "buffer" to stdout - sync', checkEncoding, 'buffer', 1, execaSync);91-test('can pass encoding "utf8" to stdout - sync', checkEncoding, 'utf8', 1, execaSync);92-test('can pass encoding "utf-8" to stdout - sync', checkEncoding, 'utf-8', 1, execaSync);93-test('can pass encoding "utf16le" to stdout - sync', checkEncoding, 'utf16le', 1, execaSync);94-test('can pass encoding "utf-16le" to stdout - sync', checkEncoding, 'utf-16le', 1, execaSync);95-test('can pass encoding "ucs2" to stdout - sync', checkEncoding, 'ucs2', 1, execaSync);96-test('can pass encoding "ucs-2" to stdout - sync', checkEncoding, 'ucs-2', 1, execaSync);97-test('can pass encoding "latin1" to stdout - sync', checkEncoding, 'latin1', 1, execaSync);98-test('can pass encoding "binary" to stdout - sync', checkEncoding, 'binary', 1, execaSync);99-test('can pass encoding "ascii" to stdout - sync', checkEncoding, 'ascii', 1, execaSync);100-test('can pass encoding "hex" to stdout - sync', checkEncoding, 'hex', 1, execaSync);101-test('can pass encoding "base64" to stdout - sync', checkEncoding, 'base64', 1, execaSync);102-test('can pass encoding "base64url" to stdout - sync', checkEncoding, 'base64url', 1, execaSync);103-test('can pass encoding "buffer" to stderr - sync', checkEncoding, 'buffer', 2, execaSync);104-test('can pass encoding "utf8" to stderr - sync', checkEncoding, 'utf8', 2, execaSync);105-test('can pass encoding "utf-8" to stderr - sync', checkEncoding, 'utf-8', 2, execaSync);106-test('can pass encoding "utf16le" to stderr - sync', checkEncoding, 'utf16le', 2, execaSync);107-test('can pass encoding "utf-16le" to stderr - sync', checkEncoding, 'utf-16le', 2, execaSync);108-test('can pass encoding "ucs2" to stderr - sync', checkEncoding, 'ucs2', 2, execaSync);109-test('can pass encoding "ucs-2" to stderr - sync', checkEncoding, 'ucs-2', 2, execaSync);110-test('can pass encoding "latin1" to stderr - sync', checkEncoding, 'latin1', 2, execaSync);111-test('can pass encoding "binary" to stderr - sync', checkEncoding, 'binary', 2, execaSync);112-test('can pass encoding "ascii" to stderr - sync', checkEncoding, 'ascii', 2, execaSync);113-test('can pass encoding "hex" to stderr - sync', checkEncoding, 'hex', 2, execaSync);114-test('can pass encoding "base64" to stderr - sync', checkEncoding, 'base64', 2, execaSync);115-test('can pass encoding "base64url" to stderr - sync', checkEncoding, 'base64url', 2, execaSync);116-test('can pass encoding "buffer" to stdio[*] - sync', checkEncoding, 'buffer', 3, execaSync);117-test('can pass encoding "utf8" to stdio[*] - sync', checkEncoding, 'utf8', 3, execaSync);118-test('can pass encoding "utf-8" to stdio[*] - sync', checkEncoding, 'utf-8', 3, execaSync);119-test('can pass encoding "utf16le" to stdio[*] - sync', checkEncoding, 'utf16le', 3, execaSync);120-test('can pass encoding "utf-16le" to stdio[*] - sync', checkEncoding, 'utf-16le', 3, execaSync);121-test('can pass encoding "ucs2" to stdio[*] - sync', checkEncoding, 'ucs2', 3, execaSync);122-test('can pass encoding "ucs-2" to stdio[*] - sync', checkEncoding, 'ucs-2', 3, execaSync);123-test('can pass encoding "latin1" to stdio[*] - sync', checkEncoding, 'latin1', 3, execaSync);124-test('can pass encoding "binary" to stdio[*] - sync', checkEncoding, 'binary', 3, execaSync);125-test('can pass encoding "ascii" to stdio[*] - sync', checkEncoding, 'ascii', 3, execaSync);126-test('can pass encoding "hex" to stdio[*] - sync', checkEncoding, 'hex', 3, execaSync);127-test('can pass encoding "base64" to stdio[*] - sync', checkEncoding, 'base64', 3, execaSync);128-test('can pass encoding "base64url" to stdio[*] - sync', checkEncoding, 'base64url', 3, execaSync);129-/* eslint-enable unicorn/text-encoding-identifier-case */130-131-test('validate unknown encodings', t => {132- t.throws(() => {133- execa('noop.js', {encoding: 'unknownEncoding'});134- }, {code: 'ERR_UNKNOWN_ENCODING'});135-});136-137-const foobarArray = ['fo', 'ob', 'ar', '..'];138-139-test('Handle multibyte characters', async t => {140- const {stdout} = await execa('noop.js', {stdout: getChunksGenerator(foobarArray, false), encoding: 'base64'});141- t.is(stdout, btoa(foobarArray.join('')));142-});143-144-test('Handle multibyte characters, with objectMode', async t => {145- const {stdout} = await execa('noop.js', {stdout: getChunksGenerator(foobarArray, true), encoding: 'base64'});146- t.deepEqual(stdout, foobarArray.map(chunk => btoa(chunk)));147-});148-149-test('Other encodings work with transforms that return objects', async t => {150- const {stdout} = await execa('noop.js', {stdout: outputObjectGenerator, encoding: 'base64'});151- t.deepEqual(stdout, [foobarObject]);152-});153-154-const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options) => {155- const {stdout} = await execa('empty.js', {stdout: stdoutOption, ...options});156- t.is(stdout === undefined, isUndefined);157-};158-159-const base64Options = {encoding: 'base64'};160-const linesOptions = {lines: true};161-test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options);162-test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options);163-test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options);164-test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options);165-test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options);166-test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options);167-test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options);168-test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options);169-test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options);170-test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options);171-test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options);172-test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options);173-test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options);174-test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options);175-test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options);176-test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options);177-test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options);178-test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions);179-test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions);180-test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions);181-test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions);182-test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions);183-test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions);184-test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions);185-test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions);186-test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions);187-test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions);188-test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions);189-test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions);190-test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions);191-test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions);192-test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions);193-test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions);194-test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions);195-test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions});196-test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions});added:test/stdio/encoding-final.js+196 added
1+import {Buffer} from 'node:buffer';2+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';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, getChunksGenerator} from '../helpers/generator.js';11+import {foobarObject} from '../helpers/input.js';12+13+const pExec = promisify(exec);14+15+setFixtureDir();16+17+const checkEncoding = async (t, encoding, fdNumber, execaMethod) => {18+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});19+ compareValues(t, stdio[fdNumber], encoding);20+21+ if (execaMethod !== execaSync) {22+ const childProcess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});23+ const getStreamMethod = encoding === 'buffer' ? getStreamAsBuffer : getStream;24+ const result = await getStreamMethod(childProcess.stdio[fdNumber]);25+ compareValues(t, result, encoding);26+ await childProcess;27+ }28+29+ if (fdNumber === 3) {30+ return;31+ }32+33+ const {stdout, stderr} = await pExec(`node noop-fd.js ${fdNumber} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});34+ compareValues(t, fdNumber === 1 ? stdout : stderr, encoding);35+};36+37+const compareValues = (t, value, encoding) => {38+ if (encoding === 'buffer') {39+ t.true(ArrayBuffer.isView(value));40+ t.true(BUFFER_TO_ENCODE.equals(value));41+ } else {42+ t.is(value, BUFFER_TO_ENCODE.toString(encoding));43+ }44+};45+46+// This string gives different outputs with each encoding type47+const STRING_TO_ENCODE = '\u1000.';48+const BUFFER_TO_ENCODE = Buffer.from(STRING_TO_ENCODE);49+50+/* eslint-disable unicorn/text-encoding-identifier-case */51+test('can pass encoding "buffer" to stdout', checkEncoding, 'buffer', 1, execa);52+test('can pass encoding "utf8" to stdout', checkEncoding, 'utf8', 1, execa);53+test('can pass encoding "utf-8" to stdout', checkEncoding, 'utf-8', 1, execa);54+test('can pass encoding "utf16le" to stdout', checkEncoding, 'utf16le', 1, execa);55+test('can pass encoding "utf-16le" to stdout', checkEncoding, 'utf-16le', 1, execa);56+test('can pass encoding "ucs2" to stdout', checkEncoding, 'ucs2', 1, execa);57+test('can pass encoding "ucs-2" to stdout', checkEncoding, 'ucs-2', 1, execa);58+test('can pass encoding "latin1" to stdout', checkEncoding, 'latin1', 1, execa);59+test('can pass encoding "binary" to stdout', checkEncoding, 'binary', 1, execa);60+test('can pass encoding "ascii" to stdout', checkEncoding, 'ascii', 1, execa);61+test('can pass encoding "hex" to stdout', checkEncoding, 'hex', 1, execa);62+test('can pass encoding "base64" to stdout', checkEncoding, 'base64', 1, execa);63+test('can pass encoding "base64url" to stdout', checkEncoding, 'base64url', 1, execa);64+test('can pass encoding "buffer" to stderr', checkEncoding, 'buffer', 2, execa);65+test('can pass encoding "utf8" to stderr', checkEncoding, 'utf8', 2, execa);66+test('can pass encoding "utf-8" to stderr', checkEncoding, 'utf-8', 2, execa);67+test('can pass encoding "utf16le" to stderr', checkEncoding, 'utf16le', 2, execa);68+test('can pass encoding "utf-16le" to stderr', checkEncoding, 'utf-16le', 2, execa);69+test('can pass encoding "ucs2" to stderr', checkEncoding, 'ucs2', 2, execa);70+test('can pass encoding "ucs-2" to stderr', checkEncoding, 'ucs-2', 2, execa);71+test('can pass encoding "latin1" to stderr', checkEncoding, 'latin1', 2, execa);72+test('can pass encoding "binary" to stderr', checkEncoding, 'binary', 2, execa);73+test('can pass encoding "ascii" to stderr', checkEncoding, 'ascii', 2, execa);74+test('can pass encoding "hex" to stderr', checkEncoding, 'hex', 2, execa);75+test('can pass encoding "base64" to stderr', checkEncoding, 'base64', 2, execa);76+test('can pass encoding "base64url" to stderr', checkEncoding, 'base64url', 2, execa);77+test('can pass encoding "buffer" to stdio[*]', checkEncoding, 'buffer', 3, execa);78+test('can pass encoding "utf8" to stdio[*]', checkEncoding, 'utf8', 3, execa);79+test('can pass encoding "utf-8" to stdio[*]', checkEncoding, 'utf-8', 3, execa);80+test('can pass encoding "utf16le" to stdio[*]', checkEncoding, 'utf16le', 3, execa);81+test('can pass encoding "utf-16le" to stdio[*]', checkEncoding, 'utf-16le', 3, execa);82+test('can pass encoding "ucs2" to stdio[*]', checkEncoding, 'ucs2', 3, execa);83+test('can pass encoding "ucs-2" to stdio[*]', checkEncoding, 'ucs-2', 3, execa);84+test('can pass encoding "latin1" to stdio[*]', checkEncoding, 'latin1', 3, execa);85+test('can pass encoding "binary" to stdio[*]', checkEncoding, 'binary', 3, execa);86+test('can pass encoding "ascii" to stdio[*]', checkEncoding, 'ascii', 3, execa);87+test('can pass encoding "hex" to stdio[*]', checkEncoding, 'hex', 3, execa);88+test('can pass encoding "base64" to stdio[*]', checkEncoding, 'base64', 3, execa);89+test('can pass encoding "base64url" to stdio[*]', checkEncoding, 'base64url', 3, execa);90+test('can pass encoding "buffer" to stdout - sync', checkEncoding, 'buffer', 1, execaSync);91+test('can pass encoding "utf8" to stdout - sync', checkEncoding, 'utf8', 1, execaSync);92+test('can pass encoding "utf-8" to stdout - sync', checkEncoding, 'utf-8', 1, execaSync);93+test('can pass encoding "utf16le" to stdout - sync', checkEncoding, 'utf16le', 1, execaSync);94+test('can pass encoding "utf-16le" to stdout - sync', checkEncoding, 'utf-16le', 1, execaSync);95+test('can pass encoding "ucs2" to stdout - sync', checkEncoding, 'ucs2', 1, execaSync);96+test('can pass encoding "ucs-2" to stdout - sync', checkEncoding, 'ucs-2', 1, execaSync);97+test('can pass encoding "latin1" to stdout - sync', checkEncoding, 'latin1', 1, execaSync);98+test('can pass encoding "binary" to stdout - sync', checkEncoding, 'binary', 1, execaSync);99+test('can pass encoding "ascii" to stdout - sync', checkEncoding, 'ascii', 1, execaSync);100+test('can pass encoding "hex" to stdout - sync', checkEncoding, 'hex', 1, execaSync);101+test('can pass encoding "base64" to stdout - sync', checkEncoding, 'base64', 1, execaSync);102+test('can pass encoding "base64url" to stdout - sync', checkEncoding, 'base64url', 1, execaSync);103+test('can pass encoding "buffer" to stderr - sync', checkEncoding, 'buffer', 2, execaSync);104+test('can pass encoding "utf8" to stderr - sync', checkEncoding, 'utf8', 2, execaSync);105+test('can pass encoding "utf-8" to stderr - sync', checkEncoding, 'utf-8', 2, execaSync);106+test('can pass encoding "utf16le" to stderr - sync', checkEncoding, 'utf16le', 2, execaSync);107+test('can pass encoding "utf-16le" to stderr - sync', checkEncoding, 'utf-16le', 2, execaSync);108+test('can pass encoding "ucs2" to stderr - sync', checkEncoding, 'ucs2', 2, execaSync);109+test('can pass encoding "ucs-2" to stderr - sync', checkEncoding, 'ucs-2', 2, execaSync);110+test('can pass encoding "latin1" to stderr - sync', checkEncoding, 'latin1', 2, execaSync);111+test('can pass encoding "binary" to stderr - sync', checkEncoding, 'binary', 2, execaSync);112+test('can pass encoding "ascii" to stderr - sync', checkEncoding, 'ascii', 2, execaSync);113+test('can pass encoding "hex" to stderr - sync', checkEncoding, 'hex', 2, execaSync);114+test('can pass encoding "base64" to stderr - sync', checkEncoding, 'base64', 2, execaSync);115+test('can pass encoding "base64url" to stderr - sync', checkEncoding, 'base64url', 2, execaSync);116+test('can pass encoding "buffer" to stdio[*] - sync', checkEncoding, 'buffer', 3, execaSync);117+test('can pass encoding "utf8" to stdio[*] - sync', checkEncoding, 'utf8', 3, execaSync);118+test('can pass encoding "utf-8" to stdio[*] - sync', checkEncoding, 'utf-8', 3, execaSync);119+test('can pass encoding "utf16le" to stdio[*] - sync', checkEncoding, 'utf16le', 3, execaSync);120+test('can pass encoding "utf-16le" to stdio[*] - sync', checkEncoding, 'utf-16le', 3, execaSync);121+test('can pass encoding "ucs2" to stdio[*] - sync', checkEncoding, 'ucs2', 3, execaSync);122+test('can pass encoding "ucs-2" to stdio[*] - sync', checkEncoding, 'ucs-2', 3, execaSync);123+test('can pass encoding "latin1" to stdio[*] - sync', checkEncoding, 'latin1', 3, execaSync);124+test('can pass encoding "binary" to stdio[*] - sync', checkEncoding, 'binary', 3, execaSync);125+test('can pass encoding "ascii" to stdio[*] - sync', checkEncoding, 'ascii', 3, execaSync);126+test('can pass encoding "hex" to stdio[*] - sync', checkEncoding, 'hex', 3, execaSync);127+test('can pass encoding "base64" to stdio[*] - sync', checkEncoding, 'base64', 3, execaSync);128+test('can pass encoding "base64url" to stdio[*] - sync', checkEncoding, 'base64url', 3, execaSync);129+/* eslint-enable unicorn/text-encoding-identifier-case */130+131+test('validate unknown encodings', t => {132+ t.throws(() => {133+ execa('noop.js', {encoding: 'unknownEncoding'});134+ }, {code: 'ERR_UNKNOWN_ENCODING'});135+});136+137+const foobarArray = ['fo', 'ob', 'ar', '..'];138+139+test('Handle multibyte characters', async t => {140+ const {stdout} = await execa('noop.js', {stdout: getChunksGenerator(foobarArray, false), encoding: 'base64'});141+ t.is(stdout, btoa(foobarArray.join('')));142+});143+144+test('Handle multibyte characters, with objectMode', async t => {145+ const {stdout} = await execa('noop.js', {stdout: getChunksGenerator(foobarArray, true), encoding: 'base64'});146+ t.deepEqual(stdout, foobarArray.map(chunk => btoa(chunk)));147+});148+149+test('Other encodings work with transforms that return objects', async t => {150+ const {stdout} = await execa('noop.js', {stdout: outputObjectGenerator, encoding: 'base64'});151+ t.deepEqual(stdout, [foobarObject]);152+});153+154+const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options) => {155+ const {stdout} = await execa('empty.js', {stdout: stdoutOption, ...options});156+ t.is(stdout === undefined, isUndefined);157+};158+159+const base64Options = {encoding: 'base64'};160+const linesOptions = {lines: true};161+test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options);162+test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options);163+test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options);164+test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options);165+test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options);166+test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options);167+test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options);168+test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options);169+test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options);170+test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options);171+test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options);172+test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options);173+test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options);174+test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options);175+test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options);176+test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options);177+test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options);178+test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions);179+test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions);180+test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions);181+test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions);182+test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions);183+test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions);184+test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions);185+test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions);186+test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions);187+test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions);188+test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions);189+test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions);190+test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions);191+test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions);192+test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions);193+test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions);194+test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions);195+test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions});196+test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions});deleted:test/stdio/encoding-start.js-188 removed
1-import {Buffer} from 'node:buffer';2-import {scheduler} from 'node:timers/promises';3-import test from 'ava';4-import {execa} from '../../index.js';5-import {setFixtureDir} from '../helpers/fixtures-dir.js';6-import {getStdio} from '../helpers/stdio.js';7-import {foobarString, foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';8-import {noopGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';9-10-setFixtureDir();11-12-const textEncoder = new TextEncoder();13-14-const getTypeofGenerator = objectMode => ({15- * transform(line) {16- yield Object.prototype.toString.call(line);17- },18- objectMode,19-});20-21-// eslint-disable-next-line max-params22-const testGeneratorFirstEncoding = async (t, input, encoding, output, objectMode) => {23- const childProcess = execa('stdin.js', {stdin: getTypeofGenerator(objectMode), encoding});24- childProcess.stdin.end(input);25- const {stdout} = await childProcess;26- const result = Buffer.from(stdout, encoding).toString();27- t.is(result, output);28-};29-30-test('First generator argument is string with default encoding, with string writes', testGeneratorFirstEncoding, foobarString, 'utf8', '[object String]', false);31-test('First generator argument is string with default encoding, with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'utf8', '[object String]', false);32-test('First generator argument is string with default encoding, with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'utf8', '[object String]', false);33-test('First generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorFirstEncoding, foobarString, 'buffer', '[object Uint8Array]', false);34-test('First generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'buffer', '[object Uint8Array]', false);35-test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'buffer', '[object Uint8Array]', false);36-test('First generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorFirstEncoding, foobarString, 'hex', '[object String]', false);37-test('First generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'hex', '[object String]', false);38-test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'hex', '[object String]', false);39-test('First generator argument can be string with objectMode', testGeneratorFirstEncoding, foobarString, 'utf8', '[object String]', true);40-test('First generator argument can be objects with objectMode', testGeneratorFirstEncoding, foobarObject, 'utf8', '[object Object]', true);41-42-const testEncodingIgnored = async (t, encoding) => {43- const input = Buffer.from(foobarString).toString(encoding);44- const childProcess = execa('stdin.js', {stdin: noopGenerator(true)});45- childProcess.stdin.end(input, encoding);46- const {stdout} = await childProcess;47- t.is(stdout, input);48-};49-50-test('Write call encoding "utf8" is ignored with objectMode', testEncodingIgnored, 'utf8');51-test('Write call encoding "utf16le" is ignored with objectMode', testEncodingIgnored, 'utf16le');52-test('Write call encoding "hex" is ignored with objectMode', testEncodingIgnored, 'hex');53-test('Write call encoding "base64" is ignored with objectMode', testEncodingIgnored, 'base64');54-55-// eslint-disable-next-line max-params56-const testGeneratorNextEncoding = async (t, input, encoding, firstObjectMode, secondObjectMode, expectedType) => {57- const {stdout} = await execa('noop.js', ['other'], {58- stdout: [59- getOutputGenerator(input, firstObjectMode),60- getTypeofGenerator(secondObjectMode),61- ],62- encoding,63- });64- const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;65- const output = Buffer.from(typeofChunk, encoding === 'buffer' ? undefined : encoding).toString();66- t.is(output, `[object ${expectedType}]`);67-};68-69-test('Next generator argument is string with default encoding, with string writes', testGeneratorNextEncoding, foobarString, 'utf8', false, false, 'String');70-test('Next generator argument is string with default encoding, with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'utf8', true, false, 'String');71-test('Next generator argument is string with default encoding, with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String');72-test('Next generator argument is string with default encoding, with Buffer writes', testGeneratorNextEncoding, foobarBuffer, 'utf8', false, false, 'String');73-test('Next generator argument is string with default encoding, with Buffer writes, objectMode first', testGeneratorNextEncoding, foobarBuffer, 'utf8', true, false, 'String');74-test('Next generator argument is string with default encoding, with Buffer writes, objectMode both', testGeneratorNextEncoding, foobarBuffer, 'utf8', true, true, 'String');75-test('Next generator argument is string with default encoding, with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String');76-test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'String');77-test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'String');78-test('Next generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array');79-test('Next generator argument is Uint8Array with encoding "buffer", with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'Uint8Array');80-test('Next generator argument is Uint8Array with encoding "buffer", with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'Uint8Array');81-test('Next generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorNextEncoding, foobarBuffer, 'buffer', false, false, 'Uint8Array');82-test('Next generator argument is Uint8Array with encoding "buffer", with Buffer writes, objectMode first', testGeneratorNextEncoding, foobarBuffer, 'buffer', true, false, 'Uint8Array');83-test('Next generator argument is Uint8Array with encoding "buffer", with Buffer writes, objectMode both', testGeneratorNextEncoding, foobarBuffer, 'buffer', true, true, 'Uint8Array');84-test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array');85-test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, false, 'Uint8Array');86-test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, true, 'Uint8Array');87-test('Next generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'String');88-test('Next generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorNextEncoding, foobarBuffer, 'hex', false, false, 'String');89-test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'String');90-test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object');91-test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object');92-93-const testFirstOutputGeneratorArgument = async (t, fdNumber) => {94- const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));95- t.deepEqual(stdio[fdNumber], ['[object String]']);96-};97-98-test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1);99-test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2);100-test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 3);101-102-// eslint-disable-next-line max-params103-const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final) => {104- const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';105- const {stdout} = await execa(fixtureName, ['1', 'other'], {106- stdout: convertTransformToFinal(getOutputGenerator(input, objectMode), final),107- encoding,108- reject,109- });110- const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;111- const output = Buffer.from(typeofChunk, encoding === 'buffer' ? undefined : encoding).toString();112- t.is(output, foobarString);113-};114-115-test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false);116-test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false);117-test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false);118-test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false);119-test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false);120-test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false);121-test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false);122-test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false);123-test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false);124-test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false);125-test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false);126-test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false);127-test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false);128-test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false);129-test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false);130-test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false);131-test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false);132-test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false);133-test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false);134-test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false);135-test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false);136-test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false);137-test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false);138-test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false);139-test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true);140-test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true);141-test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true);142-test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true);143-test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true);144-test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true);145-test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true);146-test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true);147-test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true);148-test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true);149-test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true);150-test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true);151-test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true);152-test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true);153-test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true);154-test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true);155-test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true);156-test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true);157-test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true);158-test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true);159-test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true);160-test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true);161-test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true);162-test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true);163-164-const multibyteChar = '\u{1F984}';165-const multibyteString = `${multibyteChar}${multibyteChar}`;166-const multibyteUint8Array = textEncoder.encode(multibyteString);167-const breakingLength = multibyteUint8Array.length * 0.75;168-const brokenSymbol = '\uFFFD';169-170-const testMultibyte = async (t, objectMode) => {171- const childProcess = execa('stdin.js', {stdin: noopGenerator(objectMode)});172- childProcess.stdin.write(multibyteUint8Array.slice(0, breakingLength));173- await scheduler.yield();174- childProcess.stdin.end(multibyteUint8Array.slice(breakingLength));175- const {stdout} = await childProcess;176- t.is(stdout, multibyteString);177-};178-179-test('Generator handles multibyte characters with Uint8Array', testMultibyte, false);180-test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true);181-182-const testMultibytePartial = async (t, objectMode) => {183- const {stdout} = await execa('stdin.js', {stdin: [multibyteUint8Array.slice(0, breakingLength), noopGenerator(objectMode)]});184- t.is(stdout, `${multibyteChar}${brokenSymbol}`);185-};186-187-test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false);188-test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true);added:test/stdio/encoding-transform.js+188 added
1+import {Buffer} from 'node:buffer';2+import {scheduler} from 'node:timers/promises';3+import test from 'ava';4+import {execa} from '../../index.js';5+import {setFixtureDir} from '../helpers/fixtures-dir.js';6+import {getStdio} from '../helpers/stdio.js';7+import {foobarString, foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';8+import {noopGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';9+10+setFixtureDir();11+12+const textEncoder = new TextEncoder();13+14+const getTypeofGenerator = objectMode => ({15+ * transform(line) {16+ yield Object.prototype.toString.call(line);17+ },18+ objectMode,19+});20+21+// eslint-disable-next-line max-params22+const testGeneratorFirstEncoding = async (t, input, encoding, output, objectMode) => {23+ const childProcess = execa('stdin.js', {stdin: getTypeofGenerator(objectMode), encoding});24+ childProcess.stdin.end(input);25+ const {stdout} = await childProcess;26+ const result = Buffer.from(stdout, encoding).toString();27+ t.is(result, output);28+};29+30+test('First generator argument is string with default encoding, with string writes', testGeneratorFirstEncoding, foobarString, 'utf8', '[object String]', false);31+test('First generator argument is string with default encoding, with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'utf8', '[object String]', false);32+test('First generator argument is string with default encoding, with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'utf8', '[object String]', false);33+test('First generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorFirstEncoding, foobarString, 'buffer', '[object Uint8Array]', false);34+test('First generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'buffer', '[object Uint8Array]', false);35+test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'buffer', '[object Uint8Array]', false);36+test('First generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorFirstEncoding, foobarString, 'hex', '[object String]', false);37+test('First generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorFirstEncoding, foobarBuffer, 'hex', '[object String]', false);38+test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorFirstEncoding, foobarUint8Array, 'hex', '[object String]', false);39+test('First generator argument can be string with objectMode', testGeneratorFirstEncoding, foobarString, 'utf8', '[object String]', true);40+test('First generator argument can be objects with objectMode', testGeneratorFirstEncoding, foobarObject, 'utf8', '[object Object]', true);41+42+const testEncodingIgnored = async (t, encoding) => {43+ const input = Buffer.from(foobarString).toString(encoding);44+ const childProcess = execa('stdin.js', {stdin: noopGenerator(true)});45+ childProcess.stdin.end(input, encoding);46+ const {stdout} = await childProcess;47+ t.is(stdout, input);48+};49+50+test('Write call encoding "utf8" is ignored with objectMode', testEncodingIgnored, 'utf8');51+test('Write call encoding "utf16le" is ignored with objectMode', testEncodingIgnored, 'utf16le');52+test('Write call encoding "hex" is ignored with objectMode', testEncodingIgnored, 'hex');53+test('Write call encoding "base64" is ignored with objectMode', testEncodingIgnored, 'base64');54+55+// eslint-disable-next-line max-params56+const testGeneratorNextEncoding = async (t, input, encoding, firstObjectMode, secondObjectMode, expectedType) => {57+ const {stdout} = await execa('noop.js', ['other'], {58+ stdout: [59+ getOutputGenerator(input, firstObjectMode),60+ getTypeofGenerator(secondObjectMode),61+ ],62+ encoding,63+ });64+ const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;65+ const output = Buffer.from(typeofChunk, encoding === 'buffer' ? undefined : encoding).toString();66+ t.is(output, `[object ${expectedType}]`);67+};68+69+test('Next generator argument is string with default encoding, with string writes', testGeneratorNextEncoding, foobarString, 'utf8', false, false, 'String');70+test('Next generator argument is string with default encoding, with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'utf8', true, false, 'String');71+test('Next generator argument is string with default encoding, with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'utf8', true, true, 'String');72+test('Next generator argument is string with default encoding, with Buffer writes', testGeneratorNextEncoding, foobarBuffer, 'utf8', false, false, 'String');73+test('Next generator argument is string with default encoding, with Buffer writes, objectMode first', testGeneratorNextEncoding, foobarBuffer, 'utf8', true, false, 'String');74+test('Next generator argument is string with default encoding, with Buffer writes, objectMode both', testGeneratorNextEncoding, foobarBuffer, 'utf8', true, true, 'String');75+test('Next generator argument is string with default encoding, with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'utf8', false, false, 'String');76+test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, false, 'String');77+test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'utf8', true, true, 'String');78+test('Next generator argument is Uint8Array with encoding "buffer", with string writes', testGeneratorNextEncoding, foobarString, 'buffer', false, false, 'Uint8Array');79+test('Next generator argument is Uint8Array with encoding "buffer", with string writes, objectMode first', testGeneratorNextEncoding, foobarString, 'buffer', true, false, 'Uint8Array');80+test('Next generator argument is Uint8Array with encoding "buffer", with string writes, objectMode both', testGeneratorNextEncoding, foobarString, 'buffer', true, true, 'Uint8Array');81+test('Next generator argument is Uint8Array with encoding "buffer", with Buffer writes', testGeneratorNextEncoding, foobarBuffer, 'buffer', false, false, 'Uint8Array');82+test('Next generator argument is Uint8Array with encoding "buffer", with Buffer writes, objectMode first', testGeneratorNextEncoding, foobarBuffer, 'buffer', true, false, 'Uint8Array');83+test('Next generator argument is Uint8Array with encoding "buffer", with Buffer writes, objectMode both', testGeneratorNextEncoding, foobarBuffer, 'buffer', true, true, 'Uint8Array');84+test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'buffer', false, false, 'Uint8Array');85+test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, false, 'Uint8Array');86+test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both', testGeneratorNextEncoding, foobarUint8Array, 'buffer', true, true, 'Uint8Array');87+test('Next generator argument is Uint8Array with encoding "hex", with string writes', testGeneratorNextEncoding, foobarString, 'hex', false, false, 'String');88+test('Next generator argument is Uint8Array with encoding "hex", with Buffer writes', testGeneratorNextEncoding, foobarBuffer, 'hex', false, false, 'String');89+test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', testGeneratorNextEncoding, foobarUint8Array, 'hex', false, false, 'String');90+test('Next generator argument is object with default encoding, with object writes, objectMode first', testGeneratorNextEncoding, foobarObject, 'utf8', true, false, 'Object');91+test('Next generator argument is object with default encoding, with object writes, objectMode both', testGeneratorNextEncoding, foobarObject, 'utf8', true, true, 'Object');92+93+const testFirstOutputGeneratorArgument = async (t, fdNumber) => {94+ const {stdio} = await execa('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(true)));95+ t.deepEqual(stdio[fdNumber], ['[object String]']);96+};97+98+test('The first generator with result.stdout does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 1);99+test('The first generator with result.stderr does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 2);100+test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', testFirstOutputGeneratorArgument, 3);101+102+// eslint-disable-next-line max-params103+const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final) => {104+ const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';105+ const {stdout} = await execa(fixtureName, ['1', 'other'], {106+ stdout: convertTransformToFinal(getOutputGenerator(input, objectMode), final),107+ encoding,108+ reject,109+ });110+ const typeofChunk = Array.isArray(stdout) ? stdout[0] : stdout;111+ const output = Buffer.from(typeofChunk, encoding === 'buffer' ? undefined : encoding).toString();112+ t.is(output, foobarString);113+};114+115+test('Generator can return string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, false);116+test('Generator can return Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, false);117+test('Generator can return string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, false);118+test('Generator can return Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, false);119+test('Generator can return string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, false);120+test('Generator can return Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, false);121+test('Generator can return string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, false);122+test('Generator can return Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, false);123+test('Generator can return string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, false);124+test('Generator can return Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, false);125+test('Generator can return string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, false);126+test('Generator can return Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, false);127+test('Generator can return string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, false);128+test('Generator can return Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, false);129+test('Generator can return string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, false);130+test('Generator can return Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, false);131+test('Generator can return string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, false);132+test('Generator can return Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, false);133+test('Generator can return string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, false);134+test('Generator can return Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, false);135+test('Generator can return string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, false);136+test('Generator can return Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, false);137+test('Generator can return string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, false);138+test('Generator can return Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, false);139+test('Generator can return final string with default encoding', testGeneratorReturnType, foobarString, 'utf8', true, false, true);140+test('Generator can return final Uint8Array with default encoding', testGeneratorReturnType, foobarUint8Array, 'utf8', true, false, true);141+test('Generator can return final string with encoding "buffer"', testGeneratorReturnType, foobarString, 'buffer', true, false, true);142+test('Generator can return final Uint8Array with encoding "buffer"', testGeneratorReturnType, foobarUint8Array, 'buffer', true, false, true);143+test('Generator can return final string with encoding "hex"', testGeneratorReturnType, foobarString, 'hex', true, false, true);144+test('Generator can return final Uint8Array with encoding "hex"', testGeneratorReturnType, foobarUint8Array, 'hex', true, false, true);145+test('Generator can return final string with default encoding, failure', testGeneratorReturnType, foobarString, 'utf8', false, false, true);146+test('Generator can return final Uint8Array with default encoding, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, false, true);147+test('Generator can return final string with encoding "buffer", failure', testGeneratorReturnType, foobarString, 'buffer', false, false, true);148+test('Generator can return final Uint8Array with encoding "buffer", failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, false, true);149+test('Generator can return final string with encoding "hex", failure', testGeneratorReturnType, foobarString, 'hex', false, false, true);150+test('Generator can return final Uint8Array with encoding "hex", failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, false, true);151+test('Generator can return final string with default encoding, objectMode', testGeneratorReturnType, foobarString, 'utf8', true, true, true);152+test('Generator can return final Uint8Array with default encoding, objectMode', testGeneratorReturnType, foobarUint8Array, 'utf8', true, true, true);153+test('Generator can return final string with encoding "buffer", objectMode', testGeneratorReturnType, foobarString, 'buffer', true, true, true);154+test('Generator can return final Uint8Array with encoding "buffer", objectMode', testGeneratorReturnType, foobarUint8Array, 'buffer', true, true, true);155+test('Generator can return final string with encoding "hex", objectMode', testGeneratorReturnType, foobarString, 'hex', true, true, true);156+test('Generator can return final Uint8Array with encoding "hex", objectMode', testGeneratorReturnType, foobarUint8Array, 'hex', true, true, true);157+test('Generator can return final string with default encoding, objectMode, failure', testGeneratorReturnType, foobarString, 'utf8', false, true, true);158+test('Generator can return final Uint8Array with default encoding, objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'utf8', false, true, true);159+test('Generator can return final string with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarString, 'buffer', false, true, true);160+test('Generator can return final Uint8Array with encoding "buffer", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'buffer', false, true, true);161+test('Generator can return final string with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarString, 'hex', false, true, true);162+test('Generator can return final Uint8Array with encoding "hex", objectMode, failure', testGeneratorReturnType, foobarUint8Array, 'hex', false, true, true);163+164+const multibyteChar = '\u{1F984}';165+const multibyteString = `${multibyteChar}${multibyteChar}`;166+const multibyteUint8Array = textEncoder.encode(multibyteString);167+const breakingLength = multibyteUint8Array.length * 0.75;168+const brokenSymbol = '\uFFFD';169+170+const testMultibyte = async (t, objectMode) => {171+ const childProcess = execa('stdin.js', {stdin: noopGenerator(objectMode)});172+ childProcess.stdin.write(multibyteUint8Array.slice(0, breakingLength));173+ await scheduler.yield();174+ childProcess.stdin.end(multibyteUint8Array.slice(breakingLength));175+ const {stdout} = await childProcess;176+ t.is(stdout, multibyteString);177+};178+179+test('Generator handles multibyte characters with Uint8Array', testMultibyte, false);180+test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true);181+182+const testMultibytePartial = async (t, objectMode) => {183+ const {stdout} = await execa('stdin.js', {stdin: [multibyteUint8Array.slice(0, breakingLength), noopGenerator(objectMode)]});184+ t.is(stdout, `${multibyteChar}${brokenSymbol}`);185+};186+187+test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false);188+test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true);