Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 2–3why, one step back
2import {readFile, writeFile, rm} from 'node:fs/promises';
3import {PassThrough} from 'node:stream';

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–16why, one step back
5import 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();16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17const testInputOption = async (type, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19 assert.equal(stdout, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 20–21why, one step back
20};
21

TweaksSindre Sorhusbefore adoption698a1b8

lines 22–25why, one step back
22test('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 back
26

TweaksSindre Sorhusbefore adoption698a1b8

line 27why, one step back
27const testInputFile = async (stdinOption, useInputFile, reversed, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 28–34why, one step back
28 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 back
35 assert.equal(stdout, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 36–38why, one step back
36 await rm(filePath);
37};38

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–50why, one step back
39test('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 back
51

TweaksSindre Sorhusbefore adoption698a1b8

line 52why, one step back
52const testOutputFile = async (reversed, type, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 53–56why, one step back
53 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 back
57 assert.equal(stdout, foobarUppercase);
58 assert.equal(await readFile(filePath, 'utf8'), foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 59–61why, one step back
59 await rm(filePath);
60};61

TweaksSindre Sorhusbefore adoption698a1b8

lines 62–69why, one step back
62test('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 back
70

TweaksSindre Sorhusbefore adoption698a1b8

line 71why, one step back
71const testWritableDestination = async type => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 72–76why, one step back
72 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 back
77 assert.equal(stdout, foobarUppercase);
78 assert.equal(streamOutput, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 79–80why, one step back
79};
80

TweaksSindre Sorhusbefore adoption698a1b8

lines 81–83why, one step back
81test('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 back
84

TweaksSindre Sorhusbefore adoption698a1b8

line 85why, one step back
85const testReadableSource = async type => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 86–89why, one step back
86 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 back
90 assert.equal(stdout, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 91–92why, one step back
91};
92

TweaksSindre Sorhusbefore adoption698a1b8

lines 93–95why, one step back
93test('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 back
96

TweaksSindre Sorhusbefore adoption698a1b8

line 97why, one step back
97const testInherit = async type => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 98why, one step back
98 const {stdout} = await execa('nested-inherit.js', [type]);

TweaksSindre Sorhusbefore adoption698a1b8

line 99why, one step back
99 assert.equal(stdout, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 100–101why, one step back
100};
101

TweaksSindre Sorhusbefore adoption698a1b8

lines 102–104why, one step back
102test('Can use generators with "inherit"', () => testInherit('generator'));
103test('Can use duplexes with "inherit"', () => testInherit('duplex'));104test('Can use webTransforms with "inherit"', () => testInherit('webTransform'));