Skip to content
Myr

Fix using both `objectMode` and `encoding` options (#736)

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

authored by ehmicky · committed by GitHub · parent fcc8e11 · Browse files · 3 files+40 added−21 removed
This commit

State

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

Diff stats

3 files+40 added−21 removed

  • tests:+29 added−19 removed
  • other:+11 added−2 removed

3 files+40 added−21 removed

modified:lib/stdio/encoding.js+11 added-2 removed
modified:test/helpers/generator.js+15 added
modified:test/stdio/encoding.js+14 added-19 removed
1import {Buffer} from 'node:buffer';2import {exec} from 'node:child_process';3import {setImmediate} from 'node:timers/promises';3import {promisify} from 'node:util';4import test from 'ava';5import getStream, {getStreamAsBuffer} from 'get-stream';6import {execa, execaSync} from '../../index.js';7import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';8import {fullStdio} from '../helpers/stdio.js';9import {outputObjectGenerator, getChunksGenerator} from '../helpers/generator.js';10import {foobarObject} from '../helpers/input.js';1112const pExec = promisify(exec);1314setFixtureDir();
117 unmodified lines
132});133134const foobarArray = ['fo', 'ob', 'ar', '..'];135135const delayedGenerator = async function * (lines) {136 // eslint-disable-next-line no-unused-vars137 for await (const line of lines) {138 yield foobarArray[0];139 await setImmediate();140 yield foobarArray[1];141 await setImmediate();142 yield foobarArray[2];143 await setImmediate();144 yield foobarArray[3];145 }146};136test('Handle multibyte characters', async t => {137 const {stdout} = await execa('noop.js', {stdout: getChunksGenerator(foobarArray, false), encoding: 'base64'});138 t.is(stdout, btoa(foobarArray.join('')));139});140148const testMultiByteCharacter = async (t, objectMode) => {149 const {stdout} = await execa('noop.js', {stdout: {transform: delayedGenerator, objectMode}, encoding: 'base64'});150 t.is(objectMode ? stdout.join('') : stdout, btoa(foobarArray.join('')));151};141test('Handle multibyte characters, with objectMode', async t => {142 const {stdout} = await execa('noop.js', {stdout: getChunksGenerator(foobarArray, true), encoding: 'base64'});143 t.deepEqual(stdout, foobarArray.map(chunk => btoa(chunk)));144});145153test('Handle multibyte characters', testMultiByteCharacter, false);154test('Handle multibyte characters, with objectMode', testMultiByteCharacter, true);146test('Other encodings work with transforms that return objects', async t => {147 const {stdout} = await execa('noop.js', {stdout: outputObjectGenerator, encoding: 'base64'});148 t.deepEqual(stdout, [foobarObject]);149});