Skip to content
Myr

duplicate.js

This file

Path

test/stdio/duplicate.js

359 lines · 20.7 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 {once} from 'node:events';
3import {createReadStream, createWriteStream} from 'node:fs';

TweaksSindre Sorhusbefore adoption698a1b8

lines 4–10why, one step back
4import {
5 mkdir,6 readFile,7 writeFile,8 rm,9} from 'node:fs/promises';10import path from 'node:path';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 11–12why, one step back
11import {Readable, Writable} from 'node:stream';
12import {pathToFileURL} from 'node:url';

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 14why, one step back
14import tempfile from 'tempfile';

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15import {assertThrows} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 16–27why, one step back
16import {execa, execaSync} from '../../index.js';
17import {setFixtureDirectory} from '../helpers/fixtures-directory.js';18import {19 uppercaseGenerator,20 appendGenerator,21 appendAsyncGenerator,22 casedSuffix,23} from '../helpers/generator.js';24import {appendDuplex} from '../helpers/duplex.js';25import {appendWebTransform} from '../helpers/web-transform.js';26import {foobarString, foobarUint8Array, foobarUppercase} from '../helpers/input.js';27import {fullStdio} from '../helpers/stdio.js';

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 28why, one step back
28import {nestedSubprocess} from '../helpers/nested.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 29–60why, one step back
29import {getAbsolutePath} from '../helpers/file-path.js';
30import {noopDuplex} from '../helpers/stream.js';3132setFixtureDirectory();3334const getNativeStream = stream => stream;35const getNonNativeStream = stream => ['pipe', stream];36const getWebWritableStream = stream => Writable.toWeb(stream);3738const getDummyDuplex = () => ({transform: noopDuplex()});39const getDummyWebTransformStream = () => new TransformStream();4041const getDummyPath = async () => {42 const filePath = tempfile();43 await writeFile(filePath, '');44 return filePath;45};4647const getDummyFilePath = async () => ({file: await getDummyPath()});48const getDummyFileURL = async () => pathToFileURL((await getDummyPath()));49const duplexName = 'a Duplex stream';50const webTransformName = 'a web TransformStream';51const filePathName = 'a file path string';52const fileURLName = 'a file URL';5354const getDifferentInputs = stdioOption => ({stdio: [stdioOption, 'pipe', 'pipe', stdioOption]});55const getDifferentOutputs = stdioOption => ({stdout: stdioOption, stderr: stdioOption});56const getDifferentInputsOutputs = stdioOption => ({stdin: stdioOption, stdout: stdioOption});57const differentInputsName = '`stdin` and `stdio[3]`';58const differentOutputsName = '`stdout` and `stderr`';59const differentInputsOutputsName = '`stdin` and `stdout`';60

TweaksSindre Sorhusbefore adoption698a1b8

line 61why, one step back
61test('Can use multiple "pipe" on same input file descriptor', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 62–64why, one step back
62 const subprocess = execa('stdin.js', {stdin: ['pipe', 'pipe']});
63 subprocess.stdin.end(foobarString);64 const {stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 65why, one step back
65 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 66–67why, one step back
66});
67

TweaksSindre Sorhusbefore adoption698a1b8

line 68why, one step back
68const testTwoPipeOutput = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 69why, one step back
69 const {stdout} = await execaMethod('noop.js', [foobarString], {stdout: ['pipe', 'pipe']});

TweaksSindre Sorhusbefore adoption698a1b8

line 70why, one step back
70 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 73–74why, one step back
73test('Can use multiple "pipe" on same output file descriptor', () => testTwoPipeOutput(execa));
74test('Can use multiple "pipe" on same output file descriptor, sync', () => testTwoPipeOutput(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 75why, one step back
75

TweaksSindre Sorhusbefore adoption698a1b8

line 76why, one step back
76test('Can repeat same stream on same input file descriptor', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 77–78why, one step back
77 const stream = Readable.from([foobarString]);
78 const {stdout} = await execa('stdin.js', {stdin: ['pipe', stream, stream]});

TweaksSindre Sorhusbefore adoption698a1b8

line 79why, one step back
79 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 80–81why, one step back
80});
81

TweaksSindre Sorhusbefore adoption698a1b8

line 82why, one step back
82test('Can repeat same stream on same output file descriptor', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 83–90why, one step back
83 let stdout = '';
84 const stream = new Writable({85 write(chunk, encoding, done) {86 stdout += chunk.toString();87 done();88 },89 });90 await execa('noop-fd.js', ['1', foobarString], {stdout: ['pipe', stream, stream]});

TweaksSindre Sorhusbefore adoption698a1b8

line 91why, one step back
91 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 92–93why, one step back
92});
93

TweaksSindre Sorhusbefore adoption698a1b8

line 94why, one step back
94const testTwoGenerators = async (producesTwo, execaMethod, firstGenerator, secondGenerator = firstGenerator) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 95–96why, one step back
95 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {stdout: [firstGenerator, secondGenerator]});
96 const expectedSuffix = producesTwo ? `${casedSuffix}${casedSuffix}` : casedSuffix;

TweaksSindre Sorhusbefore adoption698a1b8

line 97why, one step back
97 assert.equal(stdout, `${foobarString}${expectedSuffix}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 98–99why, one step back
98};
99

TweaksSindre Sorhusbefore adoption698a1b8

lines 100–110why, one step back
100test('Can use multiple identical generators', () => testTwoGenerators(true, execa, appendGenerator().transform));
101test('Can use multiple identical generators, options object', () => testTwoGenerators(true, execa, appendGenerator()));102test('Can use multiple identical generators, async', () => testTwoGenerators(true, execa, appendAsyncGenerator().transform));103test('Can use multiple identical generators, options object, async', () => testTwoGenerators(true, execa, appendAsyncGenerator()));104test('Can use multiple identical generators, sync', () => testTwoGenerators(true, execaSync, appendGenerator().transform));105test('Can use multiple identical generators, options object, sync', () => testTwoGenerators(true, execaSync, appendGenerator()));106test('Ignore duplicate identical duplexes', () => testTwoGenerators(false, execa, appendDuplex()));107test('Ignore duplicate identical webTransforms', () => testTwoGenerators(false, execa, appendWebTransform()));108test('Can use multiple generators with duplexes', () => testTwoGenerators(true, execa, appendGenerator(false, false, true), appendDuplex()));109test('Can use multiple generators with webTransforms', () => testTwoGenerators(true, execa, appendGenerator(false, false, true), appendWebTransform()));110test('Can use multiple duplexes with webTransforms', () => testTwoGenerators(true, execa, appendDuplex(), appendWebTransform()));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 111why, one step back
111

TweaksSindre Sorhusbefore adoption698a1b8

line 112why, one step back
112const testMultiplePipeOutput = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 113why, one step back
113 const {stdout, stderr} = await execaMethod('noop-both.js', [foobarString], fullStdio);

TweaksSindre Sorhusbefore adoption698a1b8

lines 114–115why, one step back
114 assert.equal(stdout, foobarString);
115 assert.equal(stderr, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 116–117why, one step back
116};
117

TweaksSindre Sorhusbefore adoption698a1b8

lines 118–119why, one step back
118test('Can use multiple "pipe" on different output file descriptors', () => testMultiplePipeOutput(execa));
119test('Can use multiple "pipe" on different output file descriptors, sync', () => testMultiplePipeOutput(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 120why, one step back
120

TweaksSindre Sorhusbefore adoption698a1b8

line 121why, one step back
121test('Can re-use same generator on different input file descriptors', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 122why, one step back
122 const {stdout} = await execa('stdin-fd-both.js', ['3'], getDifferentInputs([foobarUint8Array, uppercaseGenerator(false, false, true)]));

TweaksSindre Sorhusbefore adoption698a1b8

line 123why, one step back
123 assert.equal(stdout, `${foobarUppercase}${foobarUppercase}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 124–125why, one step back
124});
125

TweaksSindre Sorhusbefore adoption698a1b8

line 126why, one step back
126test('Can re-use same generator on different output file descriptors', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 127why, one step back
127 const {stdout, stderr} = await execa('noop-both.js', [foobarString], getDifferentOutputs(uppercaseGenerator(false, false, true)));

TweaksSindre Sorhusbefore adoption698a1b8

lines 128–129why, one step back
128 assert.equal(stdout, foobarUppercase);
129 assert.equal(stderr, foobarUppercase);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 130–131why, one step back
130});
131

TweaksSindre Sorhusbefore adoption698a1b8

line 132why, one step back
132test('Can re-use same non-native Readable stream on different input file descriptors', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 133–137why, one step back
133 const filePath = tempfile();
134 await writeFile(filePath, foobarString);135 const stream = createReadStream(filePath);136 await once(stream, 'open');137 const {stdout} = await execa('stdin-fd-both.js', ['3'], getDifferentInputs([new Uint8Array(0), stream]));

TweaksSindre Sorhusbefore adoption698a1b8

line 138why, one step back
138 assert.equal(stdout, `${foobarString}${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 139–141why, one step back
139 await rm(filePath);
140});141

TweaksSindre Sorhusbefore adoption698a1b8

line 142why, one step back
142const testMultipleStreamOutput = async getStreamOption => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 143–146why, one step back
143 const filePath = tempfile();
144 const stream = createWriteStream(filePath);145 await once(stream, 'open');146 await execa('noop-both.js', [foobarString], getDifferentOutputs(getStreamOption(stream)));

TweaksSindre Sorhusbefore adoption698a1b8

line 147why, one step back
147 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 148–150why, one step back
148 await rm(filePath);
149};150

TweaksSindre Sorhusbefore adoption698a1b8

lines 151–153why, one step back
151test('Can re-use same native Writable stream on different output file descriptors', () => testMultipleStreamOutput(getNativeStream));
152test('Can re-use same non-native Writable stream on different output file descriptors', () => testMultipleStreamOutput(getNonNativeStream));153test('Can re-use same web Writable stream on different output file descriptors', () => testMultipleStreamOutput(getWebWritableStream));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 154why, one step back
154

TweaksSindre Sorhusbefore adoption698a1b8

line 155why, one step back
155const testMultipleInheritOutput = async isSync => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 156why, one step back
156 const {stdout} = await nestedSubprocess('noop-both.js', [foobarString], {...getDifferentOutputs(1), isSync});

TweaksSindre Sorhusbefore adoption698a1b8

line 157why, one step back
157 assert.equal(stdout, `${foobarString}\n${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 158–159why, one step back
158};
159

TweaksSindre Sorhusbefore adoption698a1b8

lines 160–161why, one step back
160test('Can re-use same parent file descriptor on different output file descriptors', () => testMultipleInheritOutput(false));
161test('Can re-use same parent file descriptor on different output file descriptors, sync', () => testMultipleInheritOutput(true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 162why, one step back
162

TweaksSindre Sorhusbefore adoption698a1b8

line 163why, one step back
163const testMultipleFileInput = async mapFile => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 164–166why, one step back
164 const filePath = tempfile();
165 await writeFile(filePath, foobarString);166 const {stdout} = await execa('stdin-fd-both.js', ['3'], getDifferentInputs([new Uint8Array(0), mapFile(filePath)]));

TweaksSindre Sorhusbefore adoption698a1b8

line 167why, one step back
167 assert.equal(stdout, `${foobarString}${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 168–170why, one step back
168 await rm(filePath);
169};170

TweaksSindre Sorhusbefore adoption698a1b8

lines 171–172why, one step back
171test('Can re-use same file path on different input file descriptors', () => testMultipleFileInput(getAbsolutePath));
172test('Can re-use same file URL on different input file descriptors', () => testMultipleFileInput(pathToFileURL));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 173why, one step back
173

TweaksSindre Sorhusbefore adoption698a1b8

line 174why, one step back
174const testMultipleFileOutput = async (mapFile, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 175–176why, one step back
175 const filePath = tempfile();
176 await execaMethod('noop-both.js', [foobarString], getDifferentOutputs(mapFile(filePath)));

TweaksSindre Sorhusbefore adoption698a1b8

line 177why, one step back
177 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 178–180why, one step back
178 await rm(filePath);
179};180

TweaksSindre Sorhusbefore adoption698a1b8

lines 181–184why, one step back
181test('Can re-use same file path on different output file descriptors', () => testMultipleFileOutput(getAbsolutePath, execa));
182test('Can re-use same file path on different output file descriptors, sync', () => testMultipleFileOutput(getAbsolutePath, execaSync));183test('Can re-use same file URL on different output file descriptors', () => testMultipleFileOutput(pathToFileURL, execa));184test('Can re-use same file URL on different output file descriptors, sync', () => testMultipleFileOutput(pathToFileURL, execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 185why, one step back
185

TweaksSindre Sorhusbefore adoption698a1b8

lines 186–187why, one step back
186// When file descriptors target the same file with different `append` values, the first one decides
187const testDifferentAppend = async (execaMethod, stdoutAppend, stderrAppend, expectedPrefix) => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 188why, one step back
188 const filePath = tempfile();

TweaksSindre Sorhusbefore adoption698a1b8

lines 189–195why, one step back
189 await writeFile(filePath, 'base\n');
190 await execaMethod('noop-both.js', [foobarString], {191 stdout: {file: filePath, append: stdoutAppend},192 stderr: {file: filePath, append: stderrAppend},193 });194 assert.equal(await readFile(filePath, 'utf8'), `${expectedPrefix}${foobarString}\n${foobarString}\n`);195 await rm(filePath);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 196–197why, one step back
196};
197

TweaksSindre Sorhusbefore adoption698a1b8

lines 198–201why, one step back
198test('The first file descriptor decides `append` on the same output file path', () => testDifferentAppend(execa, undefined, true, ''));
199test('The first file descriptor decides `append` on the same output file path, reversed', () => testDifferentAppend(execa, true, undefined, 'base\n'));200test('The first file descriptor decides `append` on the same output file path, sync', () => testDifferentAppend(execaSync, undefined, true, ''));201test('The first file descriptor decides `append` on the same output file path, reversed, sync', () => testDifferentAppend(execaSync, true, undefined, 'base\n'));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 202why, one step back
202

TweaksSindre Sorhusbefore adoption698a1b8

line 203why, one step back
203// Two items of a single file descriptor are written once, and the first one decides too

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 204–205why, one step back
204const sameFdName = '`stdout` and `stdout`';
205

TweaksSindre Sorhusbefore adoption698a1b8

line 206why, one step back
206const testDifferentAppendSameFd = async (execaMethod, appendOne, appendTwo, expectedPrefix) => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 207why, one step back
207 const filePath = tempfile();

TweaksSindre Sorhusbefore adoption698a1b8

lines 208–211why, one step back
208 await writeFile(filePath, 'base\n');
209 await execaMethod('noop.js', [foobarString], {stdout: [{file: filePath, append: appendOne}, {file: filePath, append: appendTwo}]});210 assert.equal(await readFile(filePath, 'utf8'), `${expectedPrefix}${foobarString}\n`);211 await rm(filePath);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 212–213why, one step back
212};
213

TweaksSindre Sorhusbefore adoption698a1b8

lines 214–217why, one step back
214test('The first item decides `append` on the same output file path in the same file descriptor', () => testDifferentAppendSameFd(execa, undefined, true, ''));
215test('The first item decides `append` on the same output file path in the same file descriptor, reversed', () => testDifferentAppendSameFd(execa, true, undefined, 'base\n'));216test('The first item decides `append` on the same output file path in the same file descriptor, sync', () => testDifferentAppendSameFd(execaSync, undefined, true, ''));217test('The first item decides `append` on the same output file path in the same file descriptor, reversed, sync', () => testDifferentAppendSameFd(execaSync, true, undefined, 'base\n'));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 218why, one step back
218

TweaksSindre Sorhusbefore adoption698a1b8

line 219why, one step back
219const testSameAppend = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 220–222why, one step back
220 const filePath = tempfile();
221 await writeFile(filePath, 'base\n');222 await execaMethod('noop-both.js', [foobarString], {stdout: {file: filePath, append: true}, stderr: {file: filePath, append: true}});

TweaksSindre Sorhusbefore adoption698a1b8

line 223why, one step back
223 assert.equal(await readFile(filePath, 'utf8'), `base\n${foobarString}\n${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 224–226why, one step back
224 await rm(filePath);
225};226

TweaksSindre Sorhusbefore adoption698a1b8

lines 227–228why, one step back
227test('Can use the same `append: true` value on the same output file path', () => testSameAppend(execa));
228test('Can use the same `append: true` value on the same output file path, sync', () => testSameAppend(execaSync));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 229why, one step back
229

TweaksSindre Sorhusbefore adoption698a1b8

line 230why, one step back
230const testFalsyAppend = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 231–232why, one step back
231 const filePath = tempfile();
232 await execaMethod('noop-both.js', [foobarString], {stdout: {file: filePath}, stderr: {file: filePath, append: false}});

TweaksSindre Sorhusbefore adoption698a1b8

line 233why, one step back
233 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 234–236why, one step back
234 await rm(filePath);
235};236

TweaksSindre Sorhusbefore adoption698a1b8

lines 237–238why, one step back
237test('Falsy `append` values are the same on the same output file path', () => testFalsyAppend(execa));
238test('Falsy `append` values are the same on the same output file path, sync', () => testFalsyAppend(execaSync));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 239why, one step back
239

TweaksSindre Sorhusbefore adoption698a1b8

line 240why, one step back
240const testMultipleFileInputOutput = async (mapFile, execaMethod) => {

Fix using files in both input and output (#1058)ehmickybefore adoption39790a4

lines 241–244why, one step back
241 const inputFilePath = tempfile();
242 const outputFilePath = tempfile();243 await writeFile(inputFilePath, foobarString);244 await execaMethod('stdin.js', {stdin: mapFile(inputFilePath), stdout: mapFile(outputFilePath)});

TweaksSindre Sorhusbefore adoption698a1b8

line 245why, one step back
245 assert.equal(await readFile(outputFilePath, 'utf8'), foobarString);

Fix using files in both input and output (#1058)ehmickybefore adoption39790a4

lines 246–248why, one step back
246 await Promise.all([rm(inputFilePath), rm(outputFilePath)]);
247};248

TweaksSindre Sorhusbefore adoption698a1b8

lines 249–252why, one step back
249test('Can use different file paths on different input/output file descriptors', () => testMultipleFileInputOutput(getAbsolutePath, execa));
250test('Can use different file paths on different input/output file descriptors, sync', () => testMultipleFileInputOutput(getAbsolutePath, execaSync));251test('Can use different file URL on different input/output file descriptors', () => testMultipleFileInputOutput(pathToFileURL, execa));252test('Can use different file URL on different input/output file descriptors, sync', () => testMultipleFileInputOutput(pathToFileURL, execaSync));

Fix using files in both input and output (#1058)ehmickybefore adoption39790a4

line 253why, one step back
253

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 254why, one step back
254// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 255why, one step back
255const testMultipleInvalid = async (getDummyStream, typeName, getStdio, fdName, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 256why, one step back
256 const stdioOption = await getDummyStream();

TweaksSindre Sorhusbefore adoption698a1b8

line 257why, one step back
257 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 258–260why, one step back
258 execaMethod('empty.js', getStdio(stdioOption));
259 }, {message: `The ${fdName} options must not target ${typeName} that is the same.`});260 if (stdioOption.transform !== undefined) {

TweaksSindre Sorhusbefore adoption698a1b8

line 261why, one step back
261 assert.equal(stdioOption.transform.destroyed, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 262–264why, one step back
262 }
263};264

TweaksSindre Sorhusbefore adoption698a1b8

lines 265–274why, one step back
265test('Cannot use same Duplex on different input file descriptors', () => testMultipleInvalid(getDummyDuplex, duplexName, getDifferentInputs, differentInputsName, execa));
266test('Cannot use same Duplex on different output file descriptors', () => testMultipleInvalid(getDummyDuplex, duplexName, getDifferentOutputs, differentOutputsName, execa));267test('Cannot use same Duplex on both input and output file descriptors', () => testMultipleInvalid(getDummyDuplex, duplexName, getDifferentInputsOutputs, differentInputsOutputsName, execa));268test('Cannot use same TransformStream on different input file descriptors', () => testMultipleInvalid(getDummyWebTransformStream, webTransformName, getDifferentInputs, differentInputsName, execa));269test('Cannot use same TransformStream on different output file descriptors', () => testMultipleInvalid(getDummyWebTransformStream, webTransformName, getDifferentOutputs, differentOutputsName, execa));270test('Cannot use same TransformStream on both input and output file descriptors', () => testMultipleInvalid(getDummyWebTransformStream, webTransformName, getDifferentInputsOutputs, differentInputsOutputsName, execa));271test('Cannot use same file path on both input and output file descriptors', () => testMultipleInvalid(getDummyFilePath, filePathName, getDifferentInputsOutputs, differentInputsOutputsName, execa));272test('Cannot use same file URL on both input and output file descriptors', () => testMultipleInvalid(getDummyFileURL, fileURLName, getDifferentInputsOutputs, differentInputsOutputsName, execa));273test('Cannot use same file path on both input and output file descriptors, sync', () => testMultipleInvalid(getDummyFilePath, filePathName, getDifferentInputsOutputs, differentInputsOutputsName, execaSync));274test('Cannot use same file URL on both input and output file descriptors, sync', () => testMultipleInvalid(getDummyFileURL, fileURLName, getDifferentInputsOutputs, differentInputsOutputsName, execaSync));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 275–277why, one step back
275
276// Piping a Duplex or a web TransformStream into itself would feed it its own output forever.277// Each item uses a distinct wrapper object, around the same stream, so that `filterDuplicates()` does not merge them.

TweaksSindre Sorhusbefore adoption698a1b8

line 278why, one step back
278const testSameStreamSameFd = (getStream, typeName) => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 279why, one step back
279 const stream = getStream();

TweaksSindre Sorhusbefore adoption698a1b8

line 280why, one step back
280 assertThrows(() => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 281–284why, one step back
281 execa('empty.js', {stdout: [{transform: stream}, {transform: stream}]});
282 }, {message: `The ${sameFdName} options must not target ${typeName} that is the same.`});283};284

TweaksSindre Sorhusbefore adoption698a1b8

lines 285–286why, one step back
285test('Cannot use same Duplex twice on the same output file descriptor', () => testSameStreamSameFd(noopDuplex, duplexName));
286test('Cannot use same TransformStream twice on the same output file descriptor', () => testSameStreamSameFd(() => new TransformStream(), webTransformName));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 287–288why, one step back
287
288// The streams created for the earlier items must be destroyed when a later one is rejected, otherwise they are leaked

TweaksSindre Sorhusbefore adoption698a1b8

line 289why, one step back
289test('Earlier streams are destroyed when a later item of the same file descriptor is rejected', () => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 290why, one step back
290 const stream = noopDuplex();

TweaksSindre Sorhusbefore adoption698a1b8

line 291why, one step back
291 assertThrows(() => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 292–293why, one step back
292 execa('empty.js', {stdout: [{transform: stream}, {transform: stream}]});
293 }, {message: `The ${sameFdName} options must not target ${duplexName} that is the same.`});

TweaksSindre Sorhusbefore adoption698a1b8

line 294why, one step back
294 assert.equal(stream.destroyed, true);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 295–297why, one step back
295});
296297// `{file: './output.txt'}` and a `file:` URL are two ways to target the same file

TweaksSindre Sorhusbefore adoption698a1b8

line 298why, one step back
298const testFilePathAndUrl = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 299–300why, one step back
299 const filePath = tempfile();
300 await execaMethod('noop-both.js', [foobarString], {stdout: {file: filePath}, stderr: pathToFileURL(filePath)});

TweaksSindre Sorhusbefore adoption698a1b8

line 301why, one step back
301 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 302–304why, one step back
302 await rm(filePath);
303};304

TweaksSindre Sorhusbefore adoption698a1b8

line 305why, one step back
305const testFileUrlAndPath = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 306–307why, one step back
306 const filePath = tempfile();
307 await execaMethod('noop-both.js', [foobarString], {stdout: pathToFileURL(filePath), stderr: {file: filePath}});

TweaksSindre Sorhusbefore adoption698a1b8

line 308why, one step back
308 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 309–311why, one step back
309 await rm(filePath);
310};311

TweaksSindre Sorhusbefore adoption698a1b8

lines 312–315why, one step back
312test('Can use a file path and a file URL on different output file descriptors', () => testFilePathAndUrl(execa));
313test('Can use a file URL and a file path on different output file descriptors', () => testFileUrlAndPath(execa));314test('Can use a file path and a file URL on different output file descriptors, sync', () => testFilePathAndUrl(execaSync));315test('Can use a file URL and a file path on different output file descriptors, sync', () => testFileUrlAndPath(execaSync));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 316–317why, one step back
316
317// A single file descriptor can target the same file twice. Its output is a single stream, so it must only be written once.

TweaksSindre Sorhusbefore adoption698a1b8

line 318why, one step back
318const testSameFileSameFd = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 319–320why, one step back
319 const filePath = tempfile();
320 await execaMethod('noop.js', [foobarString], {stdout: [{file: filePath}, {file: filePath}]});

TweaksSindre Sorhusbefore adoption698a1b8

line 321why, one step back
321 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 322–324why, one step back
322 await rm(filePath);
323};324

TweaksSindre Sorhusbefore adoption698a1b8

lines 325–326why, one step back
325test('Can use the same file path twice on the same output file descriptor', () => testSameFileSameFd(execa));
326test('Can use the same file path twice on the same output file descriptor, sync', () => testSameFileSameFd(execaSync));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 327–328why, one step back
327
328// A file path is resolved before being compared, so equivalent spellings of the same file are detected

TweaksSindre Sorhusbefore adoption698a1b8

line 329why, one step back
329const testFilePathNormalized = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 330–331why, one step back
330 const directory = tempfile();
331 await mkdir(directory);

TweaksSindre Sorhusbefore adoption698a1b8

lines 332–334why, one step back
332 await mkdir(path.join(directory, 'subdirectory'));
333 const filePath = path.join(directory, 'output.txt');334 // `path.join()` would normalize this away, but a raw string keeps the `..` segment

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 335–337why, one step back
335 const equivalentFilePath = `${directory}/subdirectory/../output.txt`;
336337 await execaMethod('noop-both.js', [foobarString], {stdout: {file: filePath}, stderr: {file: equivalentFilePath}});

TweaksSindre Sorhusbefore adoption698a1b8

line 338why, one step back
338 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 339–341why, one step back
339 await rm(directory, {recursive: true});
340};341

TweaksSindre Sorhusbefore adoption698a1b8

lines 342–343why, one step back
342test('Can use equivalent file paths on different output file descriptors', () => testFilePathNormalized(execa));
343test('Can use equivalent file paths on different output file descriptors, sync', () => testFilePathNormalized(execaSync));

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 344why, one step back
344

TweaksSindre Sorhusbefore adoption698a1b8

line 345why, one step back
345const testFilePathAndUrlNormalized = async execaMethod => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 346–347why, one step back
346 const directory = tempfile();
347 await mkdir(directory);

TweaksSindre Sorhusbefore adoption698a1b8

lines 348–350why, one step back
348 await mkdir(path.join(directory, 'subdirectory'));
349 const filePath = path.join(directory, 'output.txt');350 // `path.join()` would normalize this away, but a raw string keeps the `..` segment

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 351–353why, one step back
351 const equivalentFilePath = `${directory}/subdirectory/../output.txt`;
352353 await execaMethod('noop-both.js', [foobarString], {stdout: {file: filePath}, stderr: pathToFileURL(equivalentFilePath)});

TweaksSindre Sorhusbefore adoption698a1b8

line 354why, one step back
354 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 355–357why, one step back
355 await rm(directory, {recursive: true});
356};357

TweaksSindre Sorhusbefore adoption698a1b8

lines 358–359why, one step back
358test('Can use an equivalent file URL on different output file descriptors', () => testFilePathAndUrlNormalized(execa));
359test('Can use an equivalent file URL on a different output file descriptor, sync', () => testFilePathAndUrlNormalized(execaSync));