streaming.js
This file
Path
test/pipe/streaming.js
538 lines · 22.6 KiB · JavaScript
Last changed by
Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
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
line 2why, one step back2import {once} from 'node:events';Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
line 3why, one step back3import {setTimeout} from 'node:timers/promises';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 4why, one step back4import {PassThrough} from 'node:stream';TweaksSindre Sorhusbefore adoption698a1b8
lines 5–6why, one step back5import test from 'node:test';6import {assertRejects, assertLike} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 7–11why, one step back7import {execa} from '../../index.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {foobarString} from '../helpers/input.js';10import {assertMaxListeners} from '../helpers/listeners.js';11import {fullReadableStdio} from '../helpers/stdio.js';Refactor parallel tests (#1084)ehmickybefore adoption5cf6312
line 12why, one step back12import {PARALLEL_COUNT} from '../helpers/parallel.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 13–15why, one step back1314setFixtureDirectory();15TweaksSindre Sorhusbefore adoption698a1b8
line 16why, one step back16test('Can pipe two sources to same destination', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 17–22why, one step back17 const source = execa('noop.js', [foobarString]);18 const secondSource = execa('noop.js', [foobarString]);19 const destination = execa('stdin.js');20 const pipePromise = source.pipe(destination);21 const secondPipePromise = secondSource.pipe(destination);22TweaksSindre Sorhusbefore adoption698a1b8
lines 23–27why, one step back23 assertLike(await source, {stdout: foobarString});24 assertLike(await secondSource, {stdout: foobarString});25 assertLike(await destination, {stdout: `${foobarString}\n${foobarString}`});26 assert.equal(await pipePromise, await destination);27 assert.equal(await secondPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–29why, one step back28});29TweaksSindre Sorhusbefore adoption698a1b8
line 30why, one step back30test('Can pipe three sources to same destination', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 31–38why, one step back31 const source = execa('noop.js', [foobarString]);32 const secondSource = execa('noop.js', [foobarString]);33 const thirdSource = execa('noop.js', [foobarString]);34 const destination = execa('stdin.js');35 const pipePromise = source.pipe(destination);36 const secondPipePromise = secondSource.pipe(destination);37 const thirdPromise = thirdSource.pipe(destination);38TweaksSindre Sorhusbefore adoption698a1b8
lines 39–45why, one step back39 assertLike(await source, {stdout: foobarString});40 assertLike(await secondSource, {stdout: foobarString});41 assertLike(await thirdSource, {stdout: foobarString});42 assertLike(await destination, {stdout: `${foobarString}\n${foobarString}\n${foobarString}`});43 assert.equal(await pipePromise, await destination);44 assert.equal(await secondPipePromise, await destination);45 assert.equal(await thirdPromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 46–47why, one step back46});47TweaksSindre Sorhusbefore adoption698a1b8
lines 48–49why, one step back48test('Can pipe many sources to same destination', async () => {49 const checkMaxListeners = assertMaxListeners();100% test coverage (#1018)ehmickybefore adoption9f65b86
line 50why, one step back50Refactor parallel tests (#1084)ehmickybefore adoption5cf6312
line 51why, one step back51 const expectedResults = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`).sort();100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 52–56why, one step back52 const sources = expectedResults.map(expectedResult => execa('noop.js', [expectedResult]));53 const destination = execa('stdin.js');54 const pipePromises = sources.map(source => source.pipe(destination));5556 const results = await Promise.all(sources);TweaksSindre Sorhusbefore adoption698a1b8
line 57why, one step back57 assert.deepEqual(results.map(({stdout}) => stdout), expectedResults);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 58why, one step back58 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
lines 59–60why, one step back59 assert.deepEqual(destinationResult.stdout.split('\n').sort(), expectedResults);60 assert.deepEqual(await Promise.all(pipePromises), sources.map(() => destinationResult));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 61–64why, one step back6162 checkMaxListeners();63});64TweaksSindre Sorhusbefore adoption698a1b8
lines 65–66why, one step back65test('Can pipe same source to many destinations', async () => {66 const checkMaxListeners = assertMaxListeners();100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 67–68why, one step back6768 const source = execa('noop-fd.js', ['1', foobarString]);Refactor parallel tests (#1084)ehmickybefore adoption5cf6312
line 69why, one step back69 const expectedResults = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 70–72why, one step back70 const destinations = expectedResults.map(expectedResult => execa('noop-stdin-double.js', [expectedResult]));71 const pipePromises = destinations.map(destination => source.pipe(destination));72TweaksSindre Sorhusbefore adoption698a1b8
line 73why, one step back73 assertLike(await source, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 74why, one step back74 const results = await Promise.all(destinations);TweaksSindre Sorhusbefore adoption698a1b8
lines 75–76why, one step back75 assert.deepEqual(results.map(({stdout}) => stdout), expectedResults.map(result => `${foobarString} ${result}`));76 assert.deepEqual(await Promise.all(pipePromises), results);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 77–80why, one step back7778 checkMaxListeners();79});80TweaksSindre Sorhusbefore adoption698a1b8
line 81why, one step back81test('Can pipe two streams from same subprocess to same destination', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 82–86why, one step back82 const source = execa('noop-both.js', [foobarString]);83 const destination = execa('stdin.js');84 const pipePromise = source.pipe(destination);85 const secondPipePromise = source.pipe(destination, {from: 'stderr'});86TweaksSindre Sorhusbefore adoption698a1b8
lines 87–90why, one step back87 assertLike(await source, {stdout: foobarString, stderr: foobarString});88 assertLike(await destination, {stdout: `${foobarString}\n${foobarString}`});89 assert.equal(await pipePromise, await destination);90 assert.equal(await secondPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 91–92why, one step back91});92TweaksSindre Sorhusbefore adoption698a1b8
line 93why, one step back93test('Can pipe same source to two streams from same subprocess', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 94–98why, one step back94 const source = execa('noop-fd.js', ['1', foobarString]);95 const destination = execa('stdin-fd-both.js', ['3'], fullReadableStdio());96 const pipePromise = source.pipe(destination);97 const secondPipePromise = source.pipe(destination, {to: 'fd3'});98TweaksSindre Sorhusbefore adoption698a1b8
lines 99–102why, one step back99 assertLike(await source, {stdout: foobarString});100 assertLike(await destination, {stdout: `${foobarString}${foobarString}`});101 assert.equal(await pipePromise, await destination);102 assert.equal(await secondPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 103–104why, one step back103});104TweaksSindre Sorhusbefore adoption698a1b8
line 105why, one step back105test('Can pipe a new source to same destination after some source has already written', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 106–112why, one step back106 const passThroughStream = new PassThrough();107 const source = execa('stdin.js', {stdin: ['pipe', passThroughStream]});108 const destination = execa('stdin.js');109 const pipePromise = source.pipe(destination);110111 passThroughStream.write('foo');112 const firstWrite = await once(destination.stdout, 'data');TweaksSindre Sorhusbefore adoption698a1b8
line 113why, one step back113 assert.equal(firstWrite.toString(), 'foo');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 114–118why, one step back114115 const secondSource = execa('noop.js', ['bar']);116 const secondPipePromise = secondSource.pipe(destination);117 passThroughStream.end();118TweaksSindre Sorhusbefore adoption698a1b8
lines 119–123why, one step back119 assertLike(await source, {stdout: 'foo'});120 assertLike(await secondSource, {stdout: 'bar'});121 assertLike(await destination, {stdout: 'foobar'});122 assert.equal(await pipePromise, await destination);123 assert.equal(await secondPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 124–125why, one step back124});125TweaksSindre Sorhusbefore adoption698a1b8
line 126why, one step back126test('Can pipe a second source to same destination after destination has already ended', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 127–130why, one step back127 const source = execa('noop.js', [foobarString]);128 const destination = execa('stdin.js');129 const pipePromise = source.pipe(destination);130TweaksSindre Sorhusbefore adoption698a1b8
lines 131–133why, one step back131 assertLike(await source, {stdout: foobarString});132 assertLike(await destination, {stdout: foobarString});133 assert.equal(await pipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 134–137why, one step back134135 const secondSource = execa('noop.js', [foobarString]);136 const secondPipePromise = secondSource.pipe(destination);137TweaksSindre Sorhusbefore adoption698a1b8
lines 138–139why, one step back138 assertLike(await secondSource, {stdout: ''});139 assert.equal(await secondPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 140–141why, one step back140});141TweaksSindre Sorhusbefore adoption698a1b8
line 142why, one step back142test('Can pipe same source to a second destination after source has already ended', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 143–146why, one step back143 const source = execa('noop.js', [foobarString]);144 const destination = execa('stdin.js');145 const pipePromise = source.pipe(destination);146TweaksSindre Sorhusbefore adoption698a1b8
lines 147–149why, one step back147 assertLike(await source, {stdout: foobarString});148 assertLike(await destination, {stdout: foobarString});149 assert.equal(await pipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 150–153why, one step back150151 const secondDestination = execa('stdin.js');152 const secondPipePromise = source.pipe(secondDestination);153TweaksSindre Sorhusbefore adoption698a1b8
lines 154–155why, one step back154 assertLike(await secondDestination, {stdout: ''});155 assert.equal(await secondPipePromise, await secondDestination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 156–157why, one step back156});157TweaksSindre Sorhusbefore adoption698a1b8
line 158why, one step back158test('Can pipe a new source to same destination after some but not all sources have ended', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 159–165why, one step back159 const source = execa('noop.js', [foobarString]);160 const passThroughStream = new PassThrough();161 const secondSource = execa('stdin.js', {stdin: ['pipe', passThroughStream]});162 const destination = execa('stdin.js');163 const pipePromise = source.pipe(destination);164 const secondPipePromise = secondSource.pipe(destination);165TweaksSindre Sorhusbefore adoption698a1b8
line 166why, one step back166 assertLike(await source, {stdout: foobarString});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 167–171why, one step back167168 const thirdSource = execa('noop.js', [foobarString]);169 const thirdPipePromise = thirdSource.pipe(destination);170 passThroughStream.end(`${foobarString}\n`);171TweaksSindre Sorhusbefore adoption698a1b8
lines 172–177why, one step back172 assertLike(await secondSource, {stdout: foobarString});173 assertLike(await thirdSource, {stdout: foobarString});174 assertLike(await destination, {stdout: `${foobarString}\n${foobarString}\n${foobarString}`});175 assert.equal(await pipePromise, await destination);176 assert.equal(await secondPipePromise, await destination);177 assert.equal(await thirdPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 178–179why, one step back178});179TweaksSindre Sorhusbefore adoption698a1b8
line 180why, one step back180test('Can pipe two subprocesses already ended', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 181–186why, one step back181 const source = execa('noop.js', [foobarString]);182 const destination = execa('stdin.js');183 destination.stdin.end('.');184 await Promise.all([source, destination]);185 const pipePromise = source.pipe(destination);186TweaksSindre Sorhusbefore adoption698a1b8
lines 187–189why, one step back187 assertLike(await source, {stdout: foobarString});188 assertLike(await destination, {stdout: '.'});189 assert.equal(await pipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 190–191why, one step back190});191TweaksSindre Sorhusbefore adoption698a1b8
line 192why, one step back192test('Can pipe to same destination through multiple paths', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 193–199why, one step back193 const source = execa('noop.js', [foobarString]);194 const destination = execa('stdin.js');195 const secondDestination = execa('stdin.js');196 const pipePromise = source.pipe(destination);197 const secondPipePromise = pipePromise.pipe(secondDestination);198 const thirdPipePromise = source.pipe(secondDestination);199TweaksSindre Sorhusbefore adoption698a1b8
lines 200–205why, one step back200 assertLike(await source, {stdout: foobarString});201 assertLike(await destination, {stdout: foobarString});202 assertLike(await secondDestination, {stdout: `${foobarString}\n${foobarString}`});203 assert.equal(await pipePromise, await destination);204 assert.equal(await secondPipePromise, await secondDestination);205 assert.equal(await thirdPipePromise, await secondDestination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 206–207why, one step back206});207TweaksSindre Sorhusbefore adoption698a1b8
line 208why, one step back208test('Can pipe two sources to same destination in objectMode', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 209–216why, one step back209 const stdoutTransform = {210 * transform() {211 yield [foobarString];212 },213 objectMode: true,214 };215 const source = execa('noop.js', [''], {stdout: stdoutTransform});216 const secondSource = execa('noop.js', [''], {stdout: stdoutTransform});TweaksSindre Sorhusbefore adoption698a1b8
lines 217–218why, one step back217 assert.equal(source.stdout.readableObjectMode, true);218 assert.equal(secondSource.stdout.readableObjectMode, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 219–229why, one step back219220 const stdinTransform = {221 * transform([chunk]) {222 yield chunk;223 },224 objectMode: true,225 };226 const destination = execa('stdin.js', {stdin: stdinTransform});227 const pipePromise = source.pipe(destination);228 const secondPipePromise = secondSource.pipe(destination);229TweaksSindre Sorhusbefore adoption698a1b8
lines 230–234why, one step back230 assertLike(await source, {stdout: [[foobarString]]});231 assertLike(await secondSource, {stdout: [[foobarString]]});232 assertLike(await destination, {stdout: `${foobarString}\n${foobarString}`});233 assert.equal(await pipePromise, await destination);234 assert.equal(await secondPipePromise, await destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 235–236why, one step back235});236TweaksSindre Sorhusbefore adoption698a1b8
line 237why, one step back237test('Can pipe one source to two destinations', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 238–243why, one step back238 const source = execa('noop.js', [foobarString]);239 const destination = execa('stdin.js');240 const secondDestination = execa('stdin.js');241 const pipePromise = source.pipe(destination);242 const secondPipePromise = source.pipe(secondDestination);243TweaksSindre Sorhusbefore adoption698a1b8
lines 244–248why, one step back244 assertLike(await source, {stdout: foobarString});245 assertLike(await destination, {stdout: foobarString});246 assertLike(await secondDestination, {stdout: foobarString});247 assert.equal(await pipePromise, await destination);248 assert.equal(await secondPipePromise, await secondDestination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 249–250why, one step back249});250TweaksSindre Sorhusbefore adoption698a1b8
line 251why, one step back251test('Can pipe one source to three destinations', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 252–259why, one step back252 const source = execa('noop.js', [foobarString]);253 const destination = execa('stdin.js');254 const secondDestination = execa('stdin.js');255 const thirdDestination = execa('stdin.js');256 const pipePromise = source.pipe(destination);257 const secondPipePromise = source.pipe(secondDestination);258 const thirdPipePromise = source.pipe(thirdDestination);259TweaksSindre Sorhusbefore adoption698a1b8
lines 260–266why, one step back260 assertLike(await source, {stdout: foobarString});261 assertLike(await destination, {stdout: foobarString});262 assertLike(await secondDestination, {stdout: foobarString});263 assertLike(await thirdDestination, {stdout: foobarString});264 assert.equal(await pipePromise, await destination);265 assert.equal(await secondPipePromise, await secondDestination);266 assert.equal(await thirdPipePromise, await thirdDestination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 267–268why, one step back267});268TweaksSindre Sorhusbefore adoption698a1b8
line 269why, one step back269test('Can create a series of pipes', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 270–275why, one step back270 const source = execa('noop.js', [foobarString]);271 const destination = execa('stdin.js');272 const secondDestination = execa('stdin.js');273 const pipePromise = source.pipe(destination);274 const secondPipePromise = pipePromise.pipe(secondDestination);275TweaksSindre Sorhusbefore adoption698a1b8
lines 276–280why, one step back276 assertLike(await source, {stdout: foobarString});277 assertLike(await destination, {stdout: foobarString});278 assertLike(await secondDestination, {stdout: foobarString});279 assert.equal(await pipePromise, await destination);280 assert.equal(await secondPipePromise, await secondDestination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 281–282why, one step back281});282TweaksSindre Sorhusbefore adoption698a1b8
line 283why, one step back283test('Returns pipedFrom on success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 284–288why, one step back284 const source = execa('noop.js', [foobarString]);285 const destination = execa('stdin.js');286 const pipePromise = source.pipe(destination);287288 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
line 289why, one step back289 assert.deepEqual(destinationResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 290–291why, one step back290 const sourceResult = await source;291TweaksSindre Sorhusbefore adoption698a1b8
lines 292–294why, one step back292 assertLike(await pipePromise, {pipedFrom: [sourceResult]});293 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);294 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 295–296why, one step back295});296TweaksSindre Sorhusbefore adoption698a1b8
line 297why, one step back297test('Returns pipedFrom on deep success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 298–304why, one step back298 const source = execa('noop.js', [foobarString]);299 const destination = execa('stdin.js');300 const secondDestination = execa('stdin.js');301 const pipePromise = source.pipe(destination);302 const secondPipePromise = pipePromise.pipe(secondDestination);303304 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
line 305why, one step back305 assert.deepEqual(destinationResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 306why, one step back306 const secondDestinationResult = await secondDestination;TweaksSindre Sorhusbefore adoption698a1b8
line 307why, one step back307 assert.deepEqual(secondDestinationResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 308–309why, one step back308 const sourceResult = await source;309TweaksSindre Sorhusbefore adoption698a1b8
lines 310–314why, one step back310 assertLike(await secondPipePromise, {pipedFrom: [destinationResult]});311 assert.deepEqual(secondDestinationResult.pipedFrom, [destinationResult]);312 assertLike(await pipePromise, {pipedFrom: [sourceResult]});313 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);314 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 315–316why, one step back315});316TweaksSindre Sorhusbefore adoption698a1b8
line 317why, one step back317test('Returns pipedFrom on source failure', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 318–322why, one step back318 const source = execa('noop-fail.js', ['1', foobarString]);319 const destination = execa('stdin.js');320 const pipePromise = source.pipe(destination);321322 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
lines 323–324why, one step back323 assert.deepEqual(destinationResult.pipedFrom, []);324 const sourceResult = await assertRejects(source);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 325why, one step back325TweaksSindre Sorhusbefore adoption698a1b8
lines 326–328why, one step back326 assertLike(await assertRejects(pipePromise), {pipedFrom: []});327 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);328 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 329–330why, one step back329});330TweaksSindre Sorhusbefore adoption698a1b8
line 331why, one step back331test('Returns pipedFrom on destination failure', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 332–335why, one step back332 const source = execa('noop.js', [foobarString]);333 const destination = execa('stdin-fail.js');334 const pipePromise = source.pipe(destination);335TweaksSindre Sorhusbefore adoption698a1b8
line 336why, one step back336 const destinationResult = await assertRejects(destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 337–338why, one step back337 const sourceResult = await source;338TweaksSindre Sorhusbefore adoption698a1b8
lines 339–341why, one step back339 assertLike(await assertRejects(pipePromise), {pipedFrom: [sourceResult]});340 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);341 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 342–343why, one step back342});343TweaksSindre Sorhusbefore adoption698a1b8
line 344why, one step back344test('Returns pipedFrom on source + destination failure', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 345–348why, one step back345 const source = execa('noop-fail.js', ['1', foobarString]);346 const destination = execa('stdin-fail.js');347 const pipePromise = source.pipe(destination);348TweaksSindre Sorhusbefore adoption698a1b8
lines 349–350why, one step back349 const destinationResult = await assertRejects(destination);350 const sourceResult = await assertRejects(source);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 351why, one step back351TweaksSindre Sorhusbefore adoption698a1b8
lines 352–354why, one step back352 assertLike(await assertRejects(pipePromise), {pipedFrom: [sourceResult]});353 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);354 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 355–356why, one step back355});356TweaksSindre Sorhusbefore adoption698a1b8
line 357why, one step back357test('Returns pipedFrom on deep failure', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 358–363why, one step back358 const source = execa('noop-fail.js', ['1', foobarString]);359 const destination = execa('stdin-fail.js');360 const secondDestination = execa('stdin.js');361 const pipePromise = source.pipe(destination);362 const secondPipePromise = pipePromise.pipe(secondDestination);363TweaksSindre Sorhusbefore adoption698a1b8
line 364why, one step back364 const destinationResult = await assertRejects(destination);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 365why, one step back365 const secondDestinationResult = await secondDestination;TweaksSindre Sorhusbefore adoption698a1b8
lines 366–367why, one step back366 assert.deepEqual(secondDestinationResult.pipedFrom, []);367 const sourceResult = await assertRejects(source);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 368why, one step back368TweaksSindre Sorhusbefore adoption698a1b8
lines 369–373why, one step back369 assertLike(await assertRejects(secondPipePromise), {pipedFrom: [sourceResult]});370 assert.deepEqual(secondDestinationResult.pipedFrom, [destinationResult]);371 assertLike(await assertRejects(pipePromise), {pipedFrom: [sourceResult]});372 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);373 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 374–375why, one step back374});375Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
lines 376–403why, one step back376// The second destination is piped from the first destination, not from the source which failed377test('Returns pipedFrom on deep source failure', async () => {378 const source = execa('noop-fail.js', ['1', foobarString]);379 const destination = execa('stdin.js');380 const secondDestination = execa('stdin.js');381 const pipePromise = source.pipe(destination);382 const secondPipePromise = pipePromise.pipe(secondDestination);383384 const destinationResult = await destination;385 const secondDestinationResult = await secondDestination;386 const sourceResult = await assertRejects(source);387388 assert.equal(await assertRejects(secondPipePromise), sourceResult);389 assert.deepEqual(secondDestinationResult.pipedFrom, [destinationResult]);390 assert.equal(await assertRejects(pipePromise), sourceResult);391 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);392 assert.deepEqual(sourceResult.pipedFrom, []);393});394395test('Returns pipedFrom on deep success, with a template string', async () => {396 const pipePromise = execa('noop.js', [foobarString]).pipe`stdin.js`.pipe`stdin.js`;397 const {stdout, pipedFrom} = await pipePromise;398 assert.equal(stdout, foobarString);399 const [destinationResult] = pipedFrom;400 assert.equal(destinationResult.command, 'stdin.js');401 assert.equal(destinationResult.pipedFrom[0].command, `noop.js ${foobarString}`);402});403TweaksSindre Sorhusbefore adoption698a1b8
line 404why, one step back404test('Returns pipedFrom from multiple sources', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 405–411why, one step back405 const source = execa('noop.js', [foobarString]);406 const secondSource = execa('noop.js', [foobarString]);407 const destination = execa('stdin.js');408 const pipePromise = source.pipe(destination);409 const secondPipePromise = secondSource.pipe(destination);410411 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
line 412why, one step back412 assert.deepEqual(destinationResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 413–415why, one step back413 const sourceResult = await source;414 const secondSourceResult = await secondSource;415TweaksSindre Sorhusbefore adoption698a1b8
lines 416–420why, one step back416 assertLike(await pipePromise, {pipedFrom: [sourceResult, secondSourceResult]});417 assertLike(await secondPipePromise, {pipedFrom: [sourceResult, secondSourceResult]});418 assert.deepEqual(destinationResult.pipedFrom, [sourceResult, secondSourceResult]);419 assert.deepEqual(sourceResult.pipedFrom, []);420 assert.deepEqual(secondSourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 421–422why, one step back421});422TweaksSindre Sorhusbefore adoption698a1b8
line 423why, one step back423test('Returns pipedFrom from already ended subprocesses', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 424–430why, one step back424 const source = execa('noop.js', [foobarString]);425 const destination = execa('stdin.js');426 destination.stdin.end('.');427 await Promise.all([source, destination]);428 const pipePromise = source.pipe(destination);429430 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
line 431why, one step back431 assert.deepEqual(destinationResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 432why, one step back432 const sourceResult = await source;TweaksSindre Sorhusbefore adoption698a1b8
line 433why, one step back433 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 434why, one step back434TweaksSindre Sorhusbefore adoption698a1b8
lines 435–437why, one step back435 assertLike(await pipePromise, {pipedFrom: [sourceResult]});436 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);437 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 438–439why, one step back438});439TweaksSindre Sorhusbefore adoption698a1b8
line 440why, one step back440test('Does not return nor set pipedFrom on signal abort', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 441–446why, one step back441 const abortController = new AbortController();442 const source = execa('empty.js');443 const destination = execa('empty.js');444 const pipePromise = source.pipe(destination, {unpipeSignal: abortController.signal});445446 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 447why, one step back447 assertLike(await assertRejects(pipePromise), {pipedFrom: []});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 448why, one step back448 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
line 449why, one step back449 assert.deepEqual(destinationResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 450why, one step back450 const sourceResult = await source;TweaksSindre Sorhusbefore adoption698a1b8
line 451why, one step back451 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 452–453why, one step back452});453TweaksSindre Sorhusbefore adoption698a1b8
line 454why, one step back454test('Can pipe same source to same destination twice', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 455–460why, one step back455 const source = execa('noop.js', [foobarString]);456 const destination = execa('stdin.js');457 const pipePromise = source.pipe(destination);458 const secondPipePromise = source.pipe(destination);459460 const destinationResult = await destination;TweaksSindre Sorhusbefore adoption698a1b8
line 461why, one step back461 assertLike(destinationResult, {pipedFrom: []});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 462why, one step back462 const sourceResult = await source;TweaksSindre Sorhusbefore adoption698a1b8
line 463why, one step back463 assertLike(sourceResult, {pipedFrom: []});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 464why, one step back464TweaksSindre Sorhusbefore adoption698a1b8
lines 465–470why, one step back465 assertLike(await source, {stdout: foobarString});466 assertLike(await destination, {stdout: foobarString});467 assert.equal(await pipePromise, destinationResult);468 assert.equal(await secondPipePromise, destinationResult);469 assert.deepEqual(destinationResult.pipedFrom, [sourceResult]);470 assert.deepEqual(sourceResult.pipedFrom, []);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 471why, one step back471});Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9
lines 472–473why, one step back472473// `to: 'fd3'` and higher requires the `stdio` option, which cannot be combined with the `stdin` option that piping sets by defaultTweaksSindre Sorhusbefore adoption698a1b8
line 474why, one step back474test('Can pipe to an additional file descriptor of a destination with the "stdio" option', async () => {Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9
lines 475–479why, one step back475 const source = execa('noop.js', [foobarString]);476 const {stdout} = await source.pipe('stdin-fd.js', ['3'], {477 to: 'fd3',478 stdio: ['pipe', 'pipe', 'pipe', {value: 'pipe', input: true}],479 });TweaksSindre Sorhusbefore adoption698a1b8
line 480why, one step back480 assert.equal(stdout, foobarString);Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
lines 481–537why, one step back481});482483// `noop-repeat.js` writes every 10ms. `noop.js` exits right away, since it does not read its `stdin`.484const testNoStarvation = async ({pipeOptions, sourceOptions, getExitingDestination = () => execa('noop.js')}) => {485 const source = execa('noop-repeat.js', ['1', `${foobarString}\n`], sourceOptions);486 const exitingDestination = getExitingDestination();487 const receivingDestination = execa('stdin.js');488 source.pipe(exitingDestination, pipeOptions).catch(() => {});489 source.pipe(receivingDestination, pipeOptions).catch(() => {});490491 await exitingDestination;492 await setTimeout(100);493 source.kill();494 // The source is not aborted with `EPIPE` when the first destination exits495 const {isTerminated} = await assertRejects(source);496 assert.ok(isTerminated);497 const {stdout} = await receivingDestination;498 assert.ok(stdout.split('\n').length > 2);499};500501test('One destination exiting does not starve the other destinations', () => testNoStarvation({}));502test('One destination exiting does not starve the other destinations, from "all"', () => testNoStarvation({sourceOptions: {all: true}, pipeOptions: {from: 'all'}}));503// `stdin.js` exits when its `stdin` ends, while `noop-repeat.js` keeps running504test('One destination ending its stdin does not starve the other destinations', () => testNoStarvation({505 getExitingDestination() {506 const destination = execa('stdin.js');507 destination.stdin.end();508 return destination;509 },510}));511512test('The source is aborted when all its destinations exit', async () => {513 const source = execa('noop-repeat.js', ['1', `${foobarString}\n`]);514 source.pipe(execa('noop.js')).catch(() => {});515 source.pipe(execa('noop.js')).catch(() => {});516 const {isTerminated, exitCode} = await assertRejects(source);517 assert.ok(!isTerminated);518 assert.equal(exitCode, 1);519});520521test('The other sources of an exiting destination are aborted, unless they have other destinations', async () => {522 const source = execa('noop-repeat.js', ['1', `${foobarString}\n`]);523 const secondSource = execa('noop-repeat.js', ['1', `${foobarString}\n`]);524 const exitingDestination = execa('noop.js');525 const receivingDestination = execa('stdin.js');526 source.pipe(exitingDestination).catch(() => {});527 secondSource.pipe(exitingDestination).catch(() => {});528 source.pipe(receivingDestination).catch(() => {});529530 const {exitCode} = await assertRejects(secondSource);531 assert.equal(exitCode, 1);532 await setTimeout(200);533 source.kill();534 const {isTerminated} = await assertRejects(source);535 assert.ok(isTerminated);536 const {stdout} = await receivingDestination;537 assert.ok(stdout.split('\n').length > 2);Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9
line 538why, one step back538});