Skip to content
Myr

encoding-transform.js

This file

Path

test/transform/encoding-transform.js

297 lines · 27.5 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 08eb743 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 2why, one step back
2import {Buffer} from 'node:buffer';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import test from 'node:test';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 4–12why, one step back
4import {execa, execaSync} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getStdio} from '../helpers/stdio.js';7import {8 foobarString,9 foobarUint8Array,10 foobarBuffer,11 foobarObject,12} from '../helpers/input.js';

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 13why, one step back
13import {noopGenerator, getOutputGenerator, uppercaseGenerator} from '../helpers/generator.js';

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 14–25why, one step back
14
15setFixtureDirectory();1617const getTypeofGenerator = lines => (objectMode, binary) => ({18 * transform(line) {19 lines.push(Object.prototype.toString.call(line));20 yield '';21 },22 objectMode,23 binary,24});25

TweaksSindre Sorhusbefore adoption698a1b8

lines 26–27why, one step back
26const assertTypeofChunk = (lines, expectedType) => {
27 assert.deepEqual(lines, [`[object ${expectedType}]`]);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 28–30why, one step back
28};
2930// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 31why, one step back
31const testGeneratorFirstEncoding = async (input, encoding, expectedType, objectMode, binary) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 32–35why, one step back
32 const lines = [];
33 const subprocess = execa('stdin.js', {stdin: getTypeofGenerator(lines)(objectMode, binary), encoding});34 subprocess.stdin.end(input);35 await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36 assertTypeofChunk(lines, expectedType);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 37–38why, one step back
37};
38

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–64why, one step back
39test('First generator argument is string with default encoding, with string writes', () => testGeneratorFirstEncoding(foobarString, 'utf8', 'String', false, undefined));
40test('First generator argument is string with default encoding, with Buffer writes', () => testGeneratorFirstEncoding(foobarBuffer, 'utf8', 'String', false, undefined));41test('First generator argument is string with default encoding, with Uint8Array writes', () => testGeneratorFirstEncoding(foobarUint8Array, 'utf8', 'String', false, undefined));42test('First generator argument is string with default encoding, with string writes, "binary: false"', () => testGeneratorFirstEncoding(foobarString, 'utf8', 'String', false, false));43test('First generator argument is Uint8Array with default encoding, with string writes, "binary: true"', () => testGeneratorFirstEncoding(foobarString, 'utf8', 'Uint8Array', false, true));44test('First generator argument is string with encoding "utf16le", with string writes', () => testGeneratorFirstEncoding(foobarString, 'utf16le', 'String', false, undefined));45test('First generator argument is string with encoding "utf16le", with Buffer writes', () => testGeneratorFirstEncoding(foobarBuffer, 'utf16le', 'String', false, undefined));46test('First generator argument is string with encoding "utf16le", with Uint8Array writes', () => testGeneratorFirstEncoding(foobarUint8Array, 'utf16le', 'String', false, undefined));47test('First generator argument is string with encoding "utf16le", with string writes, "binary: false"', () => testGeneratorFirstEncoding(foobarString, 'utf16le', 'String', false, false));48test('First generator argument is Uint8Array with encoding "utf16le", with string writes, "binary: true"', () => testGeneratorFirstEncoding(foobarString, 'utf16le', 'Uint8Array', false, true));49test('First generator argument is Uint8Array with encoding "buffer", with string writes', () => testGeneratorFirstEncoding(foobarString, 'buffer', 'Uint8Array', false, undefined));50test('First generator argument is Uint8Array with encoding "buffer", with Buffer writes', () => testGeneratorFirstEncoding(foobarBuffer, 'buffer', 'Uint8Array', false, undefined));51test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', () => testGeneratorFirstEncoding(foobarUint8Array, 'buffer', 'Uint8Array', false, undefined));52test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: false"', () => testGeneratorFirstEncoding(foobarString, 'buffer', 'Uint8Array', false, false));53test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true"', () => testGeneratorFirstEncoding(foobarString, 'buffer', 'Uint8Array', false, true));54test('First generator argument is Uint8Array with encoding "hex", with string writes', () => testGeneratorFirstEncoding(foobarString, 'hex', 'Uint8Array', false, undefined));55test('First generator argument is Uint8Array with encoding "hex", with Buffer writes', () => testGeneratorFirstEncoding(foobarBuffer, 'hex', 'Uint8Array', false, undefined));56test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes', () => testGeneratorFirstEncoding(foobarUint8Array, 'hex', 'Uint8Array', false, undefined));57test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false"', () => testGeneratorFirstEncoding(foobarString, 'hex', 'Uint8Array', false, false));58test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true"', () => testGeneratorFirstEncoding(foobarString, 'hex', 'Uint8Array', false, true));59test('First generator argument can be string with objectMode', () => testGeneratorFirstEncoding(foobarString, 'utf8', 'String', true, undefined));60test('First generator argument can be string with objectMode, "binary: false"', () => testGeneratorFirstEncoding(foobarString, 'utf8', 'String', true, false));61test('First generator argument can be string with objectMode, "binary: true"', () => testGeneratorFirstEncoding(foobarString, 'utf8', 'String', true, true));62test('First generator argument can be objects with objectMode', () => testGeneratorFirstEncoding(foobarObject, 'utf8', 'Object', true, undefined));63test('First generator argument can be objects with objectMode, "binary: false"', () => testGeneratorFirstEncoding(foobarObject, 'utf8', 'Object', true, false));64test('First generator argument can be objects with objectMode, "binary: true"', () => testGeneratorFirstEncoding(foobarObject, 'utf8', 'Object', true, true));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 65–66why, one step back
65
66// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 67why, one step back
67const testGeneratorFirstEncodingSync = (input, encoding, expectedType, objectMode, binary) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 68–69why, one step back
68 const lines = [];
69 execaSync('stdin.js', {stdin: [[input], getTypeofGenerator(lines)(objectMode, binary)], encoding});

TweaksSindre Sorhusbefore adoption698a1b8

line 70why, one step back
70 assertTypeofChunk(lines, expectedType);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 71–72why, one step back
71};
72

TweaksSindre Sorhusbefore adoption698a1b8

lines 73–94why, one step back
73test('First generator argument is string with default encoding, with string writes, sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf8', 'String', false, undefined));
74test('First generator argument is string with default encoding, with Uint8Array writes, sync', () => testGeneratorFirstEncodingSync(foobarUint8Array, 'utf8', 'String', false, undefined));75test('First generator argument is string with default encoding, with string writes, "binary: false", sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf8', 'String', false, false));76test('First generator argument is Uint8Array with default encoding, with string writes, "binary: true", sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf8', 'Uint8Array', false, true));77test('First generator argument is string with encoding "utf16le", with string writes, sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf16le', 'String', false, undefined));78test('First generator argument is string with encoding "utf16le", with Uint8Array writes, sync', () => testGeneratorFirstEncodingSync(foobarUint8Array, 'utf16le', 'String', false, undefined));79test('First generator argument is string with encoding "utf16le", with string writes, "binary: false", sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf16le', 'String', false, false));80test('First generator argument is Uint8Array with encoding "utf16le", with string writes, "binary: true", sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf16le', 'Uint8Array', false, true));81test('First generator argument is Uint8Array with encoding "buffer", with string writes, sync', () => testGeneratorFirstEncodingSync(foobarString, 'buffer', 'Uint8Array', false, undefined));82test('First generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', () => testGeneratorFirstEncodingSync(foobarUint8Array, 'buffer', 'Uint8Array', false, undefined));83test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: false", sync', () => testGeneratorFirstEncodingSync(foobarString, 'buffer', 'Uint8Array', false, false));84test('First generator argument is Uint8Array with encoding "buffer", with string writes, "binary: true", sync', () => testGeneratorFirstEncodingSync(foobarString, 'buffer', 'Uint8Array', false, true));85test('First generator argument is Uint8Array with encoding "hex", with string writes, sync', () => testGeneratorFirstEncodingSync(foobarString, 'hex', 'Uint8Array', false, undefined));86test('First generator argument is Uint8Array with encoding "hex", with Uint8Array writes, sync', () => testGeneratorFirstEncodingSync(foobarUint8Array, 'hex', 'Uint8Array', false, undefined));87test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: false", sync', () => testGeneratorFirstEncodingSync(foobarString, 'hex', 'Uint8Array', false, false));88test('First generator argument is Uint8Array with encoding "hex", with string writes, "binary: true", sync', () => testGeneratorFirstEncodingSync(foobarString, 'hex', 'Uint8Array', false, true));89test('First generator argument can be string with objectMode, sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf8', 'String', true, undefined));90test('First generator argument can be string with objectMode, "binary: false", sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf8', 'String', true, false));91test('First generator argument can be string with objectMode, "binary: true", sync', () => testGeneratorFirstEncodingSync(foobarString, 'utf8', 'String', true, true));92test('First generator argument can be objects with objectMode, sync', () => testGeneratorFirstEncodingSync(foobarObject, 'utf8', 'Object', true, undefined));93test('First generator argument can be objects with objectMode, "binary: false", sync', () => testGeneratorFirstEncodingSync(foobarObject, 'utf8', 'Object', true, false));94test('First generator argument can be objects with objectMode, "binary: true", sync', () => testGeneratorFirstEncodingSync(foobarObject, 'utf8', 'Object', true, true));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 95why, one step back
95

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 96why, one step back
96/*

TweaksSindre Sorhusbefore adoption698a1b8

line 97why, one step back
97The `encoding` option only applies to the output, so binary `stdin` input is decoded with UTF-8 before being passed to a transform, whichever text encoding that option uses.

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 98–107why, one step back
98Unlike the tests above, this checks the chunk's value, not only its type.
99This must be the same with both asynchronous and synchronous methods.100*/101const getChunkGenerator = chunks => ({102 * transform(chunk) {103 chunks.push(chunk);104 yield chunk;105 },106});107

TweaksSindre Sorhusbefore adoption698a1b8

line 108why, one step back
108const testStdinEncodingValue = async encoding => {

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 109–110why, one step back
109 const chunks = [];
110 const subprocess = execa('stdin.js', {stdin: getChunkGenerator(chunks), encoding});

TweaksSindre Sorhusbefore adoption698a1b8

line 111why, one step back
111 subprocess.stdin.end(foobarUint8Array);

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 112why, one step back
112 await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 113why, one step back
113 assert.deepEqual(chunks, [foobarString]);

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 114–115why, one step back
114};
115

TweaksSindre Sorhusbefore adoption698a1b8

lines 116–117why, one step back
116test('First generator argument is decoded with UTF-8 with encoding "utf8", stdin', () => testStdinEncodingValue('utf8'));
117test('First generator argument is decoded with UTF-8 with encoding "utf16le", stdin', () => testStdinEncodingValue('utf16le'));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 118why, one step back
118

TweaksSindre Sorhusbefore adoption698a1b8

line 119why, one step back
119const testStdinEncodingValueSync = encoding => {

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 120why, one step back
120 const chunks = [];

TweaksSindre Sorhusbefore adoption698a1b8

lines 121–122why, one step back
121 execaSync('stdin.js', {stdin: [[foobarUint8Array], getChunkGenerator(chunks)], encoding});
122 assert.deepEqual(chunks, [foobarString]);

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 123–124why, one step back
123};
124

TweaksSindre Sorhusbefore adoption698a1b8

lines 125–126why, one step back
125test('First generator argument is decoded with UTF-8 with encoding "utf8", stdin, sync', () => testStdinEncodingValueSync('utf8'));
126test('First generator argument is decoded with UTF-8 with encoding "utf16le", stdin, sync', () => testStdinEncodingValueSync('utf16le'));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 127why, one step back
127

TweaksSindre Sorhusbefore adoption698a1b8

line 128why, one step back
128const testEncodingIgnored = async encoding => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 129–132why, one step back
129 const input = Buffer.from(foobarString).toString(encoding);
130 const subprocess = execa('stdin.js', {stdin: noopGenerator(true)});131 subprocess.stdin.end(input, encoding);132 const {stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 133why, one step back
133 assert.equal(stdout, input);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 134–135why, one step back
134};
135

TweaksSindre Sorhusbefore adoption698a1b8

lines 136–139why, one step back
136test('Write call encoding "utf8" is ignored with objectMode', () => testEncodingIgnored('utf8'));
137test('Write call encoding "utf16le" is ignored with objectMode', () => testEncodingIgnored('utf16le'));138test('Write call encoding "hex" is ignored with objectMode', () => testEncodingIgnored('hex'));139test('Write call encoding "base64" is ignored with objectMode', () => testEncodingIgnored('base64'));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 140–141why, one step back
140
141// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 142why, one step back
142const testGeneratorNextEncoding = async (input, encoding, firstObjectMode, secondObjectMode, expectedType, execaMethod) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 143–150why, one step back
143 const lines = [];
144 await execaMethod('noop.js', ['other'], {145 stdout: [146 getOutputGenerator(input)(firstObjectMode),147 getTypeofGenerator(lines)(secondObjectMode),148 ],149 encoding,150 });

TweaksSindre Sorhusbefore adoption698a1b8

line 151why, one step back
151 assertTypeofChunk(lines, expectedType);

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 152–153why, one step back
152};
153

TweaksSindre Sorhusbefore adoption698a1b8

lines 154–197why, one step back
154test('Next generator argument is string with default encoding, with string writes', () => testGeneratorNextEncoding(foobarString, 'utf8', false, false, 'String', execa));
155test('Next generator argument is string with default encoding, with string writes, objectMode first', () => testGeneratorNextEncoding(foobarString, 'utf8', true, false, 'String', execa));156test('Next generator argument is string with default encoding, with string writes, objectMode both', () => testGeneratorNextEncoding(foobarString, 'utf8', true, true, 'String', execa));157test('Next generator argument is string with default encoding, with Uint8Array writes', () => testGeneratorNextEncoding(foobarUint8Array, 'utf8', false, false, 'String', execa));158test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first', () => testGeneratorNextEncoding(foobarUint8Array, 'utf8', true, false, 'Uint8Array', execa));159test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both', () => testGeneratorNextEncoding(foobarUint8Array, 'utf8', true, true, 'Uint8Array', execa));160test('Next generator argument is string with encoding "utf16le", with string writes', () => testGeneratorNextEncoding(foobarString, 'utf16le', false, false, 'String', execa));161test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode first', () => testGeneratorNextEncoding(foobarString, 'utf16le', true, false, 'String', execa));162test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode both', () => testGeneratorNextEncoding(foobarString, 'utf16le', true, true, 'String', execa));163test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes', () => testGeneratorNextEncoding(foobarUint8Array, 'utf16le', false, false, 'String', execa));164test('Next generator argument is Uint8Array with encoding "utf16le",, with Uint8Array writes, objectMode first', () => testGeneratorNextEncoding(foobarUint8Array, 'utf16le', true, false, 'Uint8Array', execa));165test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes, objectMode both', () => testGeneratorNextEncoding(foobarUint8Array, 'utf16le', true, true, 'Uint8Array', execa));166test('Next generator argument is Uint8Array with encoding "buffer", with string writes', () => testGeneratorNextEncoding(foobarString, 'buffer', false, false, 'Uint8Array', execa));167test('Next generator argument is string with encoding "buffer", with string writes, objectMode first', () => testGeneratorNextEncoding(foobarString, 'buffer', true, false, 'String', execa));168test('Next generator argument is string with encoding "buffer", with string writes, objectMode both', () => testGeneratorNextEncoding(foobarString, 'buffer', true, true, 'String', execa));169test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes', () => testGeneratorNextEncoding(foobarUint8Array, 'buffer', false, false, 'Uint8Array', execa));170test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first', () => testGeneratorNextEncoding(foobarUint8Array, 'buffer', true, false, 'Uint8Array', execa));171test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both', () => testGeneratorNextEncoding(foobarUint8Array, 'buffer', true, true, 'Uint8Array', execa));172test('Next generator argument is Uint8Array with encoding "hex", with string writes', () => testGeneratorNextEncoding(foobarString, 'hex', false, false, 'Uint8Array', execa));173test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes', () => testGeneratorNextEncoding(foobarUint8Array, 'hex', false, false, 'Uint8Array', execa));174test('Next generator argument is object with default encoding, with object writes, objectMode first', () => testGeneratorNextEncoding(foobarObject, 'utf8', true, false, 'Object', execa));175test('Next generator argument is object with default encoding, with object writes, objectMode both', () => testGeneratorNextEncoding(foobarObject, 'utf8', true, true, 'Object', execa));176test('Next generator argument is string with default encoding, with string writes, sync', () => testGeneratorNextEncoding(foobarString, 'utf8', false, false, 'String', execaSync));177test('Next generator argument is string with default encoding, with string writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarString, 'utf8', true, false, 'String', execaSync));178test('Next generator argument is string with default encoding, with string writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarString, 'utf8', true, true, 'String', execaSync));179test('Next generator argument is string with default encoding, with Uint8Array writes, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'utf8', false, false, 'String', execaSync));180test('Next generator argument is Uint8Array with default encoding, with Uint8Array writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'utf8', true, false, 'Uint8Array', execaSync));181test('Next generator argument is string with default encoding, with Uint8Array writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'utf8', true, true, 'Uint8Array', execaSync));182test('Next generator argument is string with encoding "utf16le", with string writes, sync', () => testGeneratorNextEncoding(foobarString, 'utf16le', false, false, 'String', execaSync));183test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarString, 'utf16le', true, false, 'String', execaSync));184test('Next generator argument is string with encoding "utf16le",, with string writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarString, 'utf16le', true, true, 'String', execaSync));185test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'utf16le', false, false, 'String', execaSync));186test('Next generator argument is Uint8Array with encoding "utf16le",, with Uint8Array writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'utf16le', true, false, 'Uint8Array', execaSync));187test('Next generator argument is string with encoding "utf16le",, with Uint8Array writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'utf16le', true, true, 'Uint8Array', execaSync));188test('Next generator argument is Uint8Array with encoding "buffer", with string writes, sync', () => testGeneratorNextEncoding(foobarString, 'buffer', false, false, 'Uint8Array', execaSync));189test('Next generator argument is string with encoding "buffer", with string writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarString, 'buffer', true, false, 'String', execaSync));190test('Next generator argument is string with encoding "buffer", with string writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarString, 'buffer', true, true, 'String', execaSync));191test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'buffer', false, false, 'Uint8Array', execaSync));192test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'buffer', true, false, 'Uint8Array', execaSync));193test('Next generator argument is Uint8Array with encoding "buffer", with Uint8Array writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'buffer', true, true, 'Uint8Array', execaSync));194test('Next generator argument is Uint8Array with encoding "hex", with string writes, sync', () => testGeneratorNextEncoding(foobarString, 'hex', false, false, 'Uint8Array', execaSync));195test('Next generator argument is Uint8Array with encoding "hex", with Uint8Array writes, sync', () => testGeneratorNextEncoding(foobarUint8Array, 'hex', false, false, 'Uint8Array', execaSync));196test('Next generator argument is object with default encoding, with object writes, objectMode first, sync', () => testGeneratorNextEncoding(foobarObject, 'utf8', true, false, 'Object', execaSync));197test('Next generator argument is object with default encoding, with object writes, objectMode both, sync', () => testGeneratorNextEncoding(foobarObject, 'utf8', true, true, 'Object', execaSync));

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 198why, one step back
198

TweaksSindre Sorhusbefore adoption698a1b8

line 199why, one step back
199const testFirstOutputGeneratorArgument = async (fdNumber, execaMethod) => {

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 200–201why, one step back
200 const lines = [];
201 await execaMethod('noop-fd.js', [`${fdNumber}`], getStdio(fdNumber, getTypeofGenerator(lines)(true)));

TweaksSindre Sorhusbefore adoption698a1b8

line 202why, one step back
202 assertTypeofChunk(lines, 'String');

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 203–204why, one step back
203};
204

TweaksSindre Sorhusbefore adoption698a1b8

lines 205–210why, one step back
205test('The first generator with result.stdout does not receive an object argument even in objectMode', () => testFirstOutputGeneratorArgument(1, execa));
206test('The first generator with result.stderr does not receive an object argument even in objectMode', () => testFirstOutputGeneratorArgument(2, execa));207test('The first generator with result.stdio[*] does not receive an object argument even in objectMode', () => testFirstOutputGeneratorArgument(3, execa));208test('The first generator with result.stdout does not receive an object argument even in objectMode, sync', () => testFirstOutputGeneratorArgument(1, execaSync));209test('The first generator with result.stderr does not receive an object argument even in objectMode, sync', () => testFirstOutputGeneratorArgument(2, execaSync));210test('The first generator with result.stdio[*] does not receive an object argument even in objectMode, sync', () => testFirstOutputGeneratorArgument(3, execaSync));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 211–218why, one step back
211
212// When the `encoding` option is binary, the whole pipeline is byte-oriented: a transform yielding a213// string has it encoded as UTF-8, then those bytes are serialized using the `encoding` option.214// This is the only coherent rule, since a yielded string like 'foobar' is neither valid hex nor valid base64.215// A non-ASCII string is used, so UTF-8 and the binary encoding differ.216const nonAsciiString = 'ré😀';217const nonAsciiBuffer = Buffer.from(nonAsciiString, 'utf8');218

TweaksSindre Sorhusbefore adoption698a1b8

line 219why, one step back
219const testYieldStringBinaryEncoding = async (encoding, execaMethod) => {

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 220–223why, one step back
220 const {stdout} = await execaMethod('noop.js', {
221 stdout: getOutputGenerator(nonAsciiString)(false, true),222 encoding,223 });

TweaksSindre Sorhusbefore adoption698a1b8

line 224why, one step back
224 assert.equal(stdout, nonAsciiBuffer.toString(encoding));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 225–226why, one step back
225};
226

TweaksSindre Sorhusbefore adoption698a1b8

lines 227–232why, one step back
227test('Transforms yielding a string are UTF-8 encoded, latin1', () => testYieldStringBinaryEncoding('latin1', execa));
228test('Transforms yielding a string are UTF-8 encoded, latin1, sync', () => testYieldStringBinaryEncoding('latin1', execaSync));229test('Transforms yielding a string are UTF-8 encoded, hex', () => testYieldStringBinaryEncoding('hex', execa));230test('Transforms yielding a string are UTF-8 encoded, hex, sync', () => testYieldStringBinaryEncoding('hex', execaSync));231test('Transforms yielding a string are UTF-8 encoded, base64', () => testYieldStringBinaryEncoding('base64', execa));232test('Transforms yielding a string are UTF-8 encoded, base64, sync', () => testYieldStringBinaryEncoding('base64', execaSync));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 233–234why, one step back
233
234// A transform yielding the bytes it received must round-trip them unchanged

TweaksSindre Sorhusbefore adoption698a1b8

line 235why, one step back
235const testYieldBytesBinaryEncoding = async execaMethod => {

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 236–239why, one step back
236 const {stdout} = await execaMethod('noop-fd.js', ['1', nonAsciiString], {
237 stdout: noopGenerator(false, true),238 encoding: 'latin1',239 });

TweaksSindre Sorhusbefore adoption698a1b8

line 240why, one step back
240 assert.equal(stdout, nonAsciiBuffer.toString('latin1'));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 241–242why, one step back
241};
242

TweaksSindre Sorhusbefore adoption698a1b8

lines 243–244why, one step back
243test('Transforms yielding Uint8Array keep the bytes unchanged', () => testYieldBytesBinaryEncoding(execa));
244test('Transforms yielding Uint8Array keep the bytes unchanged, sync', () => testYieldBytesBinaryEncoding(execaSync));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 245–251why, one step back
245
246/*247With a text encoding, a transform receives text decoded with it, so a string it yields must be encoded back with it.248Otherwise that string would be encoded as UTF-8, then decoded with the `encoding` option, which corrupts it.249*/250const nonAsciiUtf16Uint8Array = new Uint8Array(Buffer.from(nonAsciiString, 'utf16le'));251

TweaksSindre Sorhusbefore adoption698a1b8

line 252why, one step back
252const testYieldStringTextEncoding = async (transform, expectedOutput, execaMethod) => {

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 253–256why, one step back
253 const {stdout} = await execaMethod('noop.js', {
254 stdout: [getOutputGenerator(nonAsciiUtf16Uint8Array)(false, true), transform],255 encoding: 'utf16le',256 });

TweaksSindre Sorhusbefore adoption698a1b8

line 257why, one step back
257 assert.equal(stdout, expectedOutput);

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 258–259why, one step back
258};
259

TweaksSindre Sorhusbefore adoption698a1b8

lines 260–265why, one step back
260test('Transforms yielding a string are encoded with encoding "utf16le"', () => testYieldStringTextEncoding(noopGenerator(), nonAsciiString, execa));
261test('Transforms yielding a string are encoded with encoding "utf16le", sync', () => testYieldStringTextEncoding(noopGenerator(), nonAsciiString, execaSync));262test('Transforms modifying a string are encoded with encoding "utf16le"', () => testYieldStringTextEncoding(uppercaseGenerator(), nonAsciiString.toUpperCase(), execa));263test('Transforms modifying a string are encoded with encoding "utf16le", sync', () => testYieldStringTextEncoding(uppercaseGenerator(), nonAsciiString.toUpperCase(), execaSync));264test('Transforms yielding a Uint8Array keep the bytes unchanged with encoding "utf16le"', () => testYieldStringTextEncoding(getOutputGenerator(nonAsciiUtf16Uint8Array)(false, true), nonAsciiString, execa));265test('Transforms yielding a Uint8Array keep the bytes unchanged with encoding "utf16le", sync', () => testYieldStringTextEncoding(getOutputGenerator(nonAsciiUtf16Uint8Array)(false, true), nonAsciiString, execaSync));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 266why, one step back
266

TweaksSindre Sorhusbefore adoption698a1b8

lines 267–270why, one step back
267// With the `binary` transform option, a string is encoded with UTF-8, including when it is passed to the next transform
268const testYieldStringBinaryNextTransform = async execaMethod => {269 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {270 stdout: [getOutputGenerator(foobarString)(false, true), noopGenerator()],

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 271–272why, one step back
271 encoding: 'utf16le',
272 });

TweaksSindre Sorhusbefore adoption698a1b8

line 273why, one step back
273 assert.equal(stdout, Buffer.from(foobarString).toString('utf16le'));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 274–275why, one step back
274};
275

TweaksSindre Sorhusbefore adoption698a1b8

lines 276–277why, one step back
276test('Transforms with "binary: true" yielding a string to the next transform are encoded with UTF-8 with encoding "utf16le"', () => testYieldStringBinaryNextTransform(execa));
277test('Transforms with "binary: true" yielding a string to the next transform are encoded with UTF-8 with encoding "utf16le", sync', () => testYieldStringBinaryNextTransform(execaSync));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 278why, one step back
278

TweaksSindre Sorhusbefore adoption698a1b8

lines 279–283why, one step back
279/*
280A `stdin` transform receives and yields text encoded with UTF-8, since the `encoding` option only applies to the output.281Since the subprocess echoes its input, its output is those UTF-8 bytes decoded as UTF-16.282*/283const unicornsString = '🦄🦄.';

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 284why, one step back
284

TweaksSindre Sorhusbefore adoption698a1b8

line 285why, one step back
285const testStdinTransformUtf8 = async (input, execaMethod) => {

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

line 286why, one step back
286 const {stdout} = await execaMethod('stdin.js', {

TweaksSindre Sorhusbefore adoption698a1b8

line 287why, one step back
287 stdin: [[input], noopGenerator()],

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 288–290why, one step back
288 encoding: 'utf16le',
289 stripFinalNewline: false,290 });

TweaksSindre Sorhusbefore adoption698a1b8

line 291why, one step back
291 assert.equal(stdout, Buffer.from(`${Buffer.from(input).toString()}\n`).toString('utf16le'));

Fix the `encoding` option and line splitting in transformsSindre Sorhusbefore adoption6adb3c3

lines 292–293why, one step back
292};
293

TweaksSindre Sorhusbefore adoption698a1b8

lines 294–297why, one step back
294test('Transforms yielding a string are encoded with UTF-8 with encoding "utf16le", stdin', () => testStdinTransformUtf8(new Uint8Array(Buffer.from(unicornsString)), execa));
295test('Transforms yielding a string are encoded with UTF-8 with encoding "utf16le", stdin, sync', () => testStdinTransformUtf8(new Uint8Array(Buffer.from(unicornsString)), execaSync));296test('String input is encoded with UTF-8 with encoding "utf16le", stdin', () => testStdinTransformUtf8(unicornsString, execa));297test('String input is encoded with UTF-8 with encoding "utf16le", stdin, sync', () => testStdinTransformUtf8(unicornsString, execaSync));