duplicate.js
This file
Path
test/stdio/duplicate.js
359 lines · 20.7 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 {once} from 'node:events';3import {createReadStream, createWriteStream} from 'node:fs';TweaksSindre Sorhusbefore adoption698a1b8
lines 4–10why, one step back4import {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 back11import {Readable, Writable} from 'node:stream';12import {pathToFileURL} from 'node:url';TweaksSindre Sorhusbefore adoption698a1b8
line 13why, one step back13import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 14why, one step back14import tempfile from 'tempfile';TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15import {assertThrows} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 16–27why, one step back16import {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 back28import {nestedSubprocess} from '../helpers/nested.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 29–60why, one step back29import {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`';60TweaksSindre Sorhusbefore adoption698a1b8
line 61why, one step back61test('Can use multiple "pipe" on same input file descriptor', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 62–64why, one step back62 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 back65 assert.equal(stdout, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 66–67why, one step back66});67TweaksSindre Sorhusbefore adoption698a1b8
line 68why, one step back68const testTwoPipeOutput = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 69why, one step back69 const {stdout} = await execaMethod('noop.js', [foobarString], {stdout: ['pipe', 'pipe']});TweaksSindre Sorhusbefore adoption698a1b8
line 70why, one step back70 assert.equal(stdout, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 71–72why, one step back71};72TweaksSindre Sorhusbefore adoption698a1b8
lines 73–74why, one step back73test('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 back75TweaksSindre Sorhusbefore adoption698a1b8
line 76why, one step back76test('Can repeat same stream on same input file descriptor', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 77–78why, one step back77 const stream = Readable.from([foobarString]);78 const {stdout} = await execa('stdin.js', {stdin: ['pipe', stream, stream]});TweaksSindre Sorhusbefore adoption698a1b8
line 79why, one step back79 assert.equal(stdout, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 80–81why, one step back80});81TweaksSindre Sorhusbefore adoption698a1b8
line 82why, one step back82test('Can repeat same stream on same output file descriptor', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 83–90why, one step back83 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 back91 assert.equal(stdout, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 92–93why, one step back92});93TweaksSindre Sorhusbefore adoption698a1b8
line 94why, one step back94const testTwoGenerators = async (producesTwo, execaMethod, firstGenerator, secondGenerator = firstGenerator) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 95–96why, one step back95 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 back97 assert.equal(stdout, `${foobarString}${expectedSuffix}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 98–99why, one step back98};99TweaksSindre Sorhusbefore adoption698a1b8
lines 100–110why, one step back100test('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 back111TweaksSindre Sorhusbefore adoption698a1b8
line 112why, one step back112const testMultiplePipeOutput = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 113why, one step back113 const {stdout, stderr} = await execaMethod('noop-both.js', [foobarString], fullStdio);TweaksSindre Sorhusbefore adoption698a1b8
lines 114–115why, one step back114 assert.equal(stdout, foobarString);115 assert.equal(stderr, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 116–117why, one step back116};117TweaksSindre Sorhusbefore adoption698a1b8
lines 118–119why, one step back118test('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 back120TweaksSindre Sorhusbefore adoption698a1b8
line 121why, one step back121test('Can re-use same generator on different input file descriptors', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 122why, one step back122 const {stdout} = await execa('stdin-fd-both.js', ['3'], getDifferentInputs([foobarUint8Array, uppercaseGenerator(false, false, true)]));TweaksSindre Sorhusbefore adoption698a1b8
line 123why, one step back123 assert.equal(stdout, `${foobarUppercase}${foobarUppercase}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 124–125why, one step back124});125TweaksSindre Sorhusbefore adoption698a1b8
line 126why, one step back126test('Can re-use same generator on different output file descriptors', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 127why, one step back127 const {stdout, stderr} = await execa('noop-both.js', [foobarString], getDifferentOutputs(uppercaseGenerator(false, false, true)));TweaksSindre Sorhusbefore adoption698a1b8
lines 128–129why, one step back128 assert.equal(stdout, foobarUppercase);129 assert.equal(stderr, foobarUppercase);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 130–131why, one step back130});131TweaksSindre Sorhusbefore adoption698a1b8
line 132why, one step back132test('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 back133 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 back138 assert.equal(stdout, `${foobarString}${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 139–141why, one step back139 await rm(filePath);140});141TweaksSindre Sorhusbefore adoption698a1b8
line 142why, one step back142const testMultipleStreamOutput = async getStreamOption => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 143–146why, one step back143 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 back147 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 148–150why, one step back148 await rm(filePath);149};150TweaksSindre Sorhusbefore adoption698a1b8
lines 151–153why, one step back151test('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 back154TweaksSindre Sorhusbefore adoption698a1b8
line 155why, one step back155const testMultipleInheritOutput = async isSync => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 156why, one step back156 const {stdout} = await nestedSubprocess('noop-both.js', [foobarString], {...getDifferentOutputs(1), isSync});TweaksSindre Sorhusbefore adoption698a1b8
line 157why, one step back157 assert.equal(stdout, `${foobarString}\n${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 158–159why, one step back158};159TweaksSindre Sorhusbefore adoption698a1b8
lines 160–161why, one step back160test('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 back162TweaksSindre Sorhusbefore adoption698a1b8
line 163why, one step back163const testMultipleFileInput = async mapFile => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 164–166why, one step back164 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 back167 assert.equal(stdout, `${foobarString}${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 168–170why, one step back168 await rm(filePath);169};170TweaksSindre Sorhusbefore adoption698a1b8
lines 171–172why, one step back171test('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 back173TweaksSindre Sorhusbefore adoption698a1b8
line 174why, one step back174const testMultipleFileOutput = async (mapFile, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 175–176why, one step back175 const filePath = tempfile();176 await execaMethod('noop-both.js', [foobarString], getDifferentOutputs(mapFile(filePath)));TweaksSindre Sorhusbefore adoption698a1b8
line 177why, one step back177 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 178–180why, one step back178 await rm(filePath);179};180TweaksSindre Sorhusbefore adoption698a1b8
lines 181–184why, one step back181test('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 back185TweaksSindre Sorhusbefore adoption698a1b8
lines 186–187why, one step back186// When file descriptors target the same file with different `append` values, the first one decides187const testDifferentAppend = async (execaMethod, stdoutAppend, stderrAppend, expectedPrefix) => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
line 188why, one step back188 const filePath = tempfile();TweaksSindre Sorhusbefore adoption698a1b8
lines 189–195why, one step back189 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 back196};197TweaksSindre Sorhusbefore adoption698a1b8
lines 198–201why, one step back198test('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 back202TweaksSindre Sorhusbefore adoption698a1b8
line 203why, one step back203// Two items of a single file descriptor are written once, and the first one decides tooFix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 204–205why, one step back204const sameFdName = '`stdout` and `stdout`';205TweaksSindre Sorhusbefore adoption698a1b8
line 206why, one step back206const testDifferentAppendSameFd = async (execaMethod, appendOne, appendTwo, expectedPrefix) => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
line 207why, one step back207 const filePath = tempfile();TweaksSindre Sorhusbefore adoption698a1b8
lines 208–211why, one step back208 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 back212};213TweaksSindre Sorhusbefore adoption698a1b8
lines 214–217why, one step back214test('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 back218TweaksSindre Sorhusbefore adoption698a1b8
line 219why, one step back219const testSameAppend = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 220–222why, one step back220 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 back223 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 back224 await rm(filePath);225};226TweaksSindre Sorhusbefore adoption698a1b8
lines 227–228why, one step back227test('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 back229TweaksSindre Sorhusbefore adoption698a1b8
line 230why, one step back230const testFalsyAppend = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 231–232why, one step back231 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 back233 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 234–236why, one step back234 await rm(filePath);235};236TweaksSindre Sorhusbefore adoption698a1b8
lines 237–238why, one step back237test('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 back239TweaksSindre Sorhusbefore adoption698a1b8
line 240why, one step back240const testMultipleFileInputOutput = async (mapFile, execaMethod) => {Fix using files in both input and output (#1058)ehmickybefore adoption39790a4
lines 241–244why, one step back241 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 back245 assert.equal(await readFile(outputFilePath, 'utf8'), foobarString);Fix using files in both input and output (#1058)ehmickybefore adoption39790a4
lines 246–248why, one step back246 await Promise.all([rm(inputFilePath), rm(outputFilePath)]);247};248TweaksSindre Sorhusbefore adoption698a1b8
lines 249–252why, one step back249test('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 back253100% test coverage (#1018)ehmickybefore adoption9f65b86
line 254why, one step back254// eslint-disable-next-line max-paramsTweaksSindre Sorhusbefore adoption698a1b8
line 255why, one step back255const testMultipleInvalid = async (getDummyStream, typeName, getStdio, fdName, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 256why, one step back256 const stdioOption = await getDummyStream();TweaksSindre Sorhusbefore adoption698a1b8
line 257why, one step back257 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 258–260why, one step back258 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 back261 assert.equal(stdioOption.transform.destroyed, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 262–264why, one step back262 }263};264TweaksSindre Sorhusbefore adoption698a1b8
lines 265–274why, one step back265test('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 back275276// 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 back278const testSameStreamSameFd = (getStream, typeName) => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
line 279why, one step back279 const stream = getStream();TweaksSindre Sorhusbefore adoption698a1b8
line 280why, one step back280 assertThrows(() => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 281–284why, one step back281 execa('empty.js', {stdout: [{transform: stream}, {transform: stream}]});282 }, {message: `The ${sameFdName} options must not target ${typeName} that is the same.`});283};284TweaksSindre Sorhusbefore adoption698a1b8
lines 285–286why, one step back285test('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 back287288// The streams created for the earlier items must be destroyed when a later one is rejected, otherwise they are leakedTweaksSindre Sorhusbefore adoption698a1b8
line 289why, one step back289test('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 back290 const stream = noopDuplex();TweaksSindre Sorhusbefore adoption698a1b8
line 291why, one step back291 assertThrows(() => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 292–293why, one step back292 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 back294 assert.equal(stream.destroyed, true);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 295–297why, one step back295});296297// `{file: './output.txt'}` and a `file:` URL are two ways to target the same fileTweaksSindre Sorhusbefore adoption698a1b8
line 298why, one step back298const testFilePathAndUrl = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 299–300why, one step back299 const filePath = tempfile();300 await execaMethod('noop-both.js', [foobarString], {stdout: {file: filePath}, stderr: pathToFileURL(filePath)});TweaksSindre Sorhusbefore adoption698a1b8
line 301why, one step back301 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 302–304why, one step back302 await rm(filePath);303};304TweaksSindre Sorhusbefore adoption698a1b8
line 305why, one step back305const testFileUrlAndPath = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 306–307why, one step back306 const filePath = tempfile();307 await execaMethod('noop-both.js', [foobarString], {stdout: pathToFileURL(filePath), stderr: {file: filePath}});TweaksSindre Sorhusbefore adoption698a1b8
line 308why, one step back308 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 309–311why, one step back309 await rm(filePath);310};311TweaksSindre Sorhusbefore adoption698a1b8
lines 312–315why, one step back312test('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 back316317// 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 back318const testSameFileSameFd = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 319–320why, one step back319 const filePath = tempfile();320 await execaMethod('noop.js', [foobarString], {stdout: [{file: filePath}, {file: filePath}]});TweaksSindre Sorhusbefore adoption698a1b8
line 321why, one step back321 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n`);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 322–324why, one step back322 await rm(filePath);323};324TweaksSindre Sorhusbefore adoption698a1b8
lines 325–326why, one step back325test('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 back327328// A file path is resolved before being compared, so equivalent spellings of the same file are detectedTweaksSindre Sorhusbefore adoption698a1b8
line 329why, one step back329const testFilePathNormalized = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 330–331why, one step back330 const directory = tempfile();331 await mkdir(directory);TweaksSindre Sorhusbefore adoption698a1b8
lines 332–334why, one step back332 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 `..` segmentFix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 335–337why, one step back335 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 back338 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 339–341why, one step back339 await rm(directory, {recursive: true});340};341TweaksSindre Sorhusbefore adoption698a1b8
lines 342–343why, one step back342test('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 back344TweaksSindre Sorhusbefore adoption698a1b8
line 345why, one step back345const testFilePathAndUrlNormalized = async execaMethod => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 346–347why, one step back346 const directory = tempfile();347 await mkdir(directory);TweaksSindre Sorhusbefore adoption698a1b8
lines 348–350why, one step back348 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 `..` segmentFix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 351–353why, one step back351 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 back354 assert.equal(await readFile(filePath, 'utf8'), `${foobarString}\n${foobarString}\n`);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 355–357why, one step back355 await rm(directory, {recursive: true});356};357TweaksSindre Sorhusbefore adoption698a1b8
lines 358–359why, one step back358test('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));