generator-mixed.js
This file
Path
test/transform/generator-mixed.js
104 lines · 6.0 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 2–3why, one step back2import {readFile, writeFile, rm} from 'node:fs/promises';3import {PassThrough} from 'node:stream';TweaksSindre Sorhusbefore adoption698a1b8
line 4why, one step back4import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–16why, one step back5import getStream from 'get-stream';6import tempfile from 'tempfile';7import {execa, execaSync} from '../../index.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {foobarString, foobarUppercase, foobarUint8Array} from '../helpers/input.js';10import {uppercaseGenerator} from '../helpers/generator.js';11import {uppercaseBufferDuplex} from '../helpers/duplex.js';12import {uppercaseBufferWebTransform} from '../helpers/web-transform.js';13import {generatorsMap} from '../helpers/map.js';1415setFixtureDirectory();16TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17const testInputOption = async (type, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 18why, one step back18 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});TweaksSindre Sorhusbefore adoption698a1b8
line 19why, one step back19 assert.equal(stdout, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 20–21why, one step back20};21TweaksSindre Sorhusbefore adoption698a1b8
lines 22–25why, one step back22test('Can use generators with input option', () => testInputOption('generator', execa));23test('Can use generators with input option, sync', () => testInputOption('generator', execaSync));24test('Can use duplexes with input option', () => testInputOption('duplex', execa));25test('Can use webTransforms with input option', () => testInputOption('webTransform', execa));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 26why, one step back26TweaksSindre Sorhusbefore adoption698a1b8
line 27why, one step back27const testInputFile = async (stdinOption, useInputFile, reversed, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–34why, one step back28 const filePath = tempfile();29 await writeFile(filePath, foobarString);30 const options = useInputFile31 ? {inputFile: filePath, stdin: stdinOption}32 : {stdin: [{file: filePath}, stdinOption]};33 options.stdin = reversed ? options.stdin.reverse() : options.stdin;34 const {stdout} = await execaMethod('stdin-fd.js', ['0'], options);TweaksSindre Sorhusbefore adoption698a1b8
line 35why, one step back35 assert.equal(stdout, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 36–38why, one step back36 await rm(filePath);37};38TweaksSindre Sorhusbefore adoption698a1b8
lines 39–50why, one step back39test('Can use generators with a file as input', () => testInputFile(uppercaseGenerator(), false, false, execa));40test('Can use generators with a file as input, reversed', () => testInputFile(uppercaseGenerator(), false, true, execa));41test('Can use generators with inputFile option', () => testInputFile(uppercaseGenerator(), true, false, execa));42test('Can use generators with a file as input, sync', () => testInputFile(uppercaseGenerator(), false, false, execaSync));43test('Can use generators with a file as input, reversed, sync', () => testInputFile(uppercaseGenerator(), false, true, execaSync));44test('Can use generators with inputFile option, sync', () => testInputFile(uppercaseGenerator(), true, false, execaSync));45test('Can use duplexes with a file as input', () => testInputFile(uppercaseBufferDuplex(), false, false, execa));46test('Can use duplexes with a file as input, reversed', () => testInputFile(uppercaseBufferDuplex(), false, true, execa));47test('Can use duplexes with inputFile option', () => testInputFile(uppercaseBufferDuplex(), true, false, execa));48test('Can use webTransforms with a file as input', () => testInputFile(uppercaseBufferWebTransform(), false, false, execa));49test('Can use webTransforms with a file as input, reversed', () => testInputFile(uppercaseBufferWebTransform(), false, true, execa));50test('Can use webTransforms with inputFile option', () => testInputFile(uppercaseBufferWebTransform(), true, false, execa));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 51why, one step back51TweaksSindre Sorhusbefore adoption698a1b8
line 52why, one step back52const testOutputFile = async (reversed, type, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 53–56why, one step back53 const filePath = tempfile();54 const stdoutOption = [generatorsMap[type].uppercaseBuffer(false, true), {file: filePath}];55 const reversedStdoutOption = reversed ? stdoutOption.reverse() : stdoutOption;56 const {stdout} = await execaMethod('noop-fd.js', ['1'], {stdout: reversedStdoutOption});TweaksSindre Sorhusbefore adoption698a1b8
lines 57–58why, one step back57 assert.equal(stdout, foobarUppercase);58 assert.equal(await readFile(filePath, 'utf8'), foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 59–61why, one step back59 await rm(filePath);60};61TweaksSindre Sorhusbefore adoption698a1b8
lines 62–69why, one step back62test('Can use generators with a file as output', () => testOutputFile(false, 'generator', execa));63test('Can use generators with a file as output, reversed', () => testOutputFile(true, 'generator', execa));64test('Can use generators with a file as output, sync', () => testOutputFile(false, 'generator', execaSync));65test('Can use generators with a file as output, reversed, sync', () => testOutputFile(true, 'generator', execaSync));66test('Can use duplexes with a file as output', () => testOutputFile(false, 'duplex', execa));67test('Can use duplexes with a file as output, reversed', () => testOutputFile(true, 'duplex', execa));68test('Can use webTransforms with a file as output', () => testOutputFile(false, 'webTransform', execa));69test('Can use webTransforms with a file as output, reversed', () => testOutputFile(true, 'webTransform', execa));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 70why, one step back70TweaksSindre Sorhusbefore adoption698a1b8
line 71why, one step back71const testWritableDestination = async type => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 72–76why, one step back72 const passThrough = new PassThrough();73 const [{stdout}, streamOutput] = await Promise.all([74 execa('noop-fd.js', ['1', foobarString], {stdout: [generatorsMap[type].uppercaseBuffer(false, true), passThrough]}),75 getStream(passThrough),76 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 77–78why, one step back77 assert.equal(stdout, foobarUppercase);78 assert.equal(streamOutput, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 79–80why, one step back79};80TweaksSindre Sorhusbefore adoption698a1b8
lines 81–83why, one step back81test('Can use generators to a Writable stream', () => testWritableDestination('generator'));82test('Can use duplexes to a Writable stream', () => testWritableDestination('duplex'));83test('Can use webTransforms to a Writable stream', () => testWritableDestination('webTransform'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 84why, one step back84TweaksSindre Sorhusbefore adoption698a1b8
line 85why, one step back85const testReadableSource = async type => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 86–89why, one step back86 const passThrough = new PassThrough();87 const subprocess = execa('stdin-fd.js', ['0'], {stdin: [passThrough, generatorsMap[type].uppercase()]});88 passThrough.end(foobarString);89 const {stdout} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 90why, one step back90 assert.equal(stdout, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 91–92why, one step back91};92TweaksSindre Sorhusbefore adoption698a1b8
lines 93–95why, one step back93test('Can use generators from a Readable stream', () => testReadableSource('generator'));94test('Can use duplexes from a Readable stream', () => testReadableSource('duplex'));95test('Can use webTransforms from a Readable stream', () => testReadableSource('webTransform'));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 96why, one step back96TweaksSindre Sorhusbefore adoption698a1b8
line 97why, one step back97const testInherit = async type => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 98why, one step back98 const {stdout} = await execa('nested-inherit.js', [type]);TweaksSindre Sorhusbefore adoption698a1b8
line 99why, one step back99 assert.equal(stdout, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 100–101why, one step back100};101TweaksSindre Sorhusbefore adoption698a1b8
lines 102–104why, one step back102test('Can use generators with "inherit"', () => testInherit('generator'));103test('Can use duplexes with "inherit"', () => testInherit('duplex'));104test('Can use webTransforms with "inherit"', () => testInherit('webTransform'));