split-transform.js
This file
Path
test/transform/split-transform.js
82 lines · 4.2 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than c6ce870 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–2why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 3–19why, one step back3import {execa, execaSync} from '../../index.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';6import {7 foobarString,8 foobarUint8Array,9 foobarObject,10 foobarObjectString,11} from '../helpers/input.js';1213setFixtureDirectory();1415const resultUint8ArrayGenerator = function * (lines, chunk) {16 lines.push(chunk);17 yield new TextEncoder().encode(chunk);18};19TweaksSindre Sorhusbefore adoption698a1b8
line 20why, one step back20const testStringToUint8Array = async (expectedOutput, objectMode, preserveNewlines, execaMethod) => {Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 21–29why, one step back21 const lines = [];22 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {23 stdout: {24 transform: resultUint8ArrayGenerator.bind(undefined, lines),25 objectMode,26 preserveNewlines,27 },28 lines: true,29 });TweaksSindre Sorhusbefore adoption698a1b8
lines 30–31why, one step back30 assert.deepEqual(lines, [foobarString]);31 assert.deepEqual(stdout, expectedOutput);Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 32–33why, one step back32};33TweaksSindre Sorhusbefore adoption698a1b8
lines 34–41why, one step back34test('Line splitting when converting from string to Uint8Array', () => testStringToUint8Array([foobarString], false, true, execa));35test('Line splitting when converting from string to Uint8Array, objectMode', () => testStringToUint8Array([foobarUint8Array], true, true, execa));36test('Line splitting when converting from string to Uint8Array, preserveNewlines', () => testStringToUint8Array([foobarString], false, false, execa));37test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines', () => testStringToUint8Array([foobarUint8Array], true, false, execa));38test('Line splitting when converting from string to Uint8Array, sync', () => testStringToUint8Array([foobarString], false, true, execaSync));39test('Line splitting when converting from string to Uint8Array, objectMode, sync', () => testStringToUint8Array([foobarUint8Array], true, true, execaSync));40test('Line splitting when converting from string to Uint8Array, preserveNewlines, sync', () => testStringToUint8Array([foobarString], false, false, execaSync));41test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines, sync', () => testStringToUint8Array([foobarUint8Array], true, false, execaSync));Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 42–47why, one step back4243const serializeResultGenerator = function * (lines, chunk) {44 lines.push(chunk);45 yield JSON.stringify(chunk);46};47TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48const testUnsetObjectMode = async (expectedOutput, preserveNewlines, execaMethod) => {Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 49–56why, one step back49 const lines = [];50 const {stdout} = await execaMethod('noop.js', {51 stdout: [52 getOutputsGenerator([foobarObject])(true),53 {transform: serializeResultGenerator.bind(undefined, lines), preserveNewlines, objectMode: false},54 ],55 stripFinalNewline: false,56 });TweaksSindre Sorhusbefore adoption698a1b8
lines 57–58why, one step back57 assert.deepEqual(lines, [foobarObject]);58 assert.equal(stdout, expectedOutput);Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 59–60why, one step back59};60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–64why, one step back61test('Can switch from objectMode to non-objectMode', () => testUnsetObjectMode(`${foobarObjectString}\n`, false, execa));62test('Can switch from objectMode to non-objectMode, preserveNewlines', () => testUnsetObjectMode(foobarObjectString, true, execa));63test('Can switch from objectMode to non-objectMode, sync', () => testUnsetObjectMode(`${foobarObjectString}\n`, false, execaSync));64test('Can switch from objectMode to non-objectMode, preserveNewlines, sync', () => testUnsetObjectMode(foobarObjectString, true, execaSync));Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
line 65why, one step back65TweaksSindre Sorhusbefore adoption698a1b8
line 66why, one step back66const testYieldArray = async (input, expectedLines, expectedOutput, execaMethod) => {Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 67–74why, one step back67 const lines = [];68 const {stdout} = await execaMethod('noop.js', {69 stdout: [70 getOutputsGenerator(input)(),71 resultGenerator(lines)(),72 ],73 stripFinalNewline: false,74 });TweaksSindre Sorhusbefore adoption698a1b8
lines 75–76why, one step back75 assert.deepEqual(lines, expectedLines);76 assert.deepEqual(stdout, expectedOutput);Remove `StdioOption` type (#1008)ehmickybefore adoptionc6ce870
lines 77–78why, one step back77};78TweaksSindre Sorhusbefore adoption698a1b8
lines 79–82why, one step back79test('Can use "yield* array" to produce multiple lines', () => testYieldArray([foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execa));80test('Can use "yield* array" to produce empty lines', () => testYieldArray([foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execa));81test('Can use "yield* array" to produce multiple lines, sync', () => testYieldArray([foobarString, foobarString], [foobarString, foobarString], `${foobarString}\n${foobarString}\n`, execaSync));82test('Can use "yield* array" to produce empty lines, sync', () => testYieldArray([foobarString, ''], [foobarString, ''], `${foobarString}\n\n`, execaSync));