methods.js
This file
Path
test/pipe/methods.js
462 lines · 16.1 KiB · JavaScript
Last changed by
Fix IPC edge casesSindre Sorhusbefore adoption5f80cde
History of this fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 2why, one step back2import {setTimeout} from 'node:timers/promises';Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
line 3why, one step back3import {Readable, Writable} from 'node:stream';Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 4why, one step back4import {text} from 'node:stream/consumers';TweaksSindre Sorhusbefore adoption698a1b8
lines 5–6why, one step back5import test from 'node:test';6import {assertThrows, assertRejects} from '../helpers/assert.js';Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 7–10why, one step back7import {execa} from '../../index.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {simpleFull, noNewlinesFull, noNewlinesChunks} from '../helpers/lines.js';10import {foobarString, foobarArray} from '../helpers/input.js';TweaksSindre Sorhusbefore adoption698a1b8
line 11why, one step back11/* eslint-disable node-test/no-conditional-assertion -- shared helper functions are called from conditional paths on purpose */Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 12–21why, one step back1213setFixtureDirectory();1415const timeoutSymbol = Symbol('timeout');1617// `stdin.js` pipes its stdin to its stdout, so the piped output equals the source output18const pipeSimple = () => execa('noop-fd.js', ['1', simpleFull]).pipe('stdin.js');19const pipeAll = () => execa('noop-fd.js', ['1', simpleFull]).pipe('stdin.js', {all: true});20const pipeDistinctBoth = () => execa('noop-fd.js', ['1', simpleFull]).pipe('stdin-distinct-both.js');21TweaksSindre Sorhusbefore adoption698a1b8
line 22why, one step back22const assertSettles = async (promise, timeout = 1000) => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 23–28why, one step back23 const result = await Promise.race([24 promise,25 // Several pipe cancellation tests are specifically checking that a pending reader does not hang.26 setTimeout(timeout, timeoutSymbol, {ref: false}),27 ]);28TweaksSindre Sorhusbefore adoption698a1b8
line 29why, one step back29 assert.notEqual(result, timeoutSymbol);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 30–41why, one step back30 return result;31};3233const cleanupSubprocesses = async (...subprocesses) => {34 for (const subprocess of subprocesses) {35 subprocess.kill();36 }3738 await Promise.allSettled(subprocesses);39};4041const getPipeMessages = async piped => {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 42why, one step back42 const messages = await Array.fromAsync(piped.getEachMessage());Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 43–46why, one step back4344 return messages;45};46TweaksSindre Sorhusbefore adoption698a1b8
line 47why, one step back47test('The .pipe() return value can be iterated', async () => {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 48why, one step back48 const lines = await Array.fromAsync(pipeSimple());Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 49why, one step back49TweaksSindre Sorhusbefore adoption698a1b8
line 50why, one step back50 assert.deepEqual(lines, noNewlinesChunks);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 51–52why, one step back51});52TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53test('The .pipe() return value has an .iterable() method', async () => {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 54why, one step back54 const lines = await Array.fromAsync(pipeSimple().iterable());Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 55why, one step back55TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56 assert.deepEqual(lines, noNewlinesChunks);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 57–58why, one step back57});58TweaksSindre Sorhusbefore adoption698a1b8
lines 59–60why, one step back59test('The .pipe() return value has a .readable() method', async () => {60 assert.equal(await text(pipeSimple().readable()), simpleFull);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 61–62why, one step back61});62TweaksSindre Sorhusbefore adoption698a1b8
lines 63–64why, one step back63test('The .pipe() return value has a .readableStream() method', async () => {64 assert.equal(await text(pipeSimple().readableStream()), simpleFull);Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc
lines 65–66why, one step back65});66TweaksSindre Sorhusbefore adoption698a1b8
line 67why, one step back67test('The .pipe() return value .readable() can be called multiple times', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 68–73why, one step back68 const piped = pipeSimple();69 const [output, secondOutput] = await Promise.all([70 text(piped.readable()),71 text(piped.readable()),72 ]);73TweaksSindre Sorhusbefore adoption698a1b8
lines 74–75why, one step back74 assert.equal(output, simpleFull);75 assert.equal(secondOutput, simpleFull);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 76–77why, one step back76});77TweaksSindre Sorhusbefore adoption698a1b8
line 78why, one step back78test('The .pipe() return value .readable() keeps conversion options', async () => {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 79why, one step back79 const chunks = await Array.fromAsync(pipeSimple().readable({binary: false, preserveNewlines: false}));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 80why, one step back80TweaksSindre Sorhusbefore adoption698a1b8
lines 81–82why, one step back81 assert.deepEqual(chunks, noNewlinesChunks);82 assert.equal(chunks.join(''), noNewlinesFull);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 83–84why, one step back83});84TweaksSindre Sorhusbefore adoption698a1b8
line 85why, one step back85test('The .pipe() return value does not have a .writable() method', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 86why, one step back86 const piped = pipeSimple();TweaksSindre Sorhusbefore adoption698a1b8
lines 87–90why, one step back87 assert.equal(piped.writable, undefined);88 assert.equal(piped.duplex, undefined);89 assert.equal(piped.writableStream, undefined);90 assert.equal(piped.transformStream, undefined);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 91–93why, one step back91 await piped;92});93TweaksSindre Sorhusbefore adoption698a1b8
line 94why, one step back94test('The .pipe() return value does not have .all unless destination uses the "all" option', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 95–97why, one step back95 const piped = pipeSimple();96 const descriptor = Object.getOwnPropertyDescriptor(piped, 'all');97TweaksSindre Sorhusbefore adoption698a1b8
lines 98–100why, one step back98 assert.equal(piped.all, undefined);99 assert.equal(descriptor.value, undefined);100 assert.equal(descriptor.get, undefined);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 101–103why, one step back101 await piped;102});103TweaksSindre Sorhusbefore adoption698a1b8
line 104why, one step back104test('The .pipe() return value has an .all property', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 105why, one step back105 const piped = pipeAll();TweaksSindre Sorhusbefore adoption698a1b8
lines 106–107why, one step back106 assert.ok(piped.all instanceof Readable);107 assert.equal(await text(piped.all), simpleFull);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 108–110why, one step back108 await piped;109});110TweaksSindre Sorhusbefore adoption698a1b8
line 111why, one step back111test('The .pipe() return value .all is created lazily and cached', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 112–114why, one step back112 const piped = pipeAll();113 const descriptor = Object.getOwnPropertyDescriptor(piped, 'all');114TweaksSindre Sorhusbefore adoption698a1b8
line 115why, one step back115 assert.equal(typeof descriptor.get, 'function');Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 116why, one step back116 const {all} = piped;TweaksSindre Sorhusbefore adoption698a1b8
lines 117–120why, one step back117 assert.ok(all instanceof Readable);118 assert.equal(piped.all, all);119 assert.equal(Object.getOwnPropertyDescriptor(piped, 'all').get, undefined);120 assert.equal(await text(all), simpleFull);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 121–123why, one step back121 await piped;122});123TweaksSindre Sorhusbefore adoption698a1b8
line 124why, one step back124test('The .pipe() return value .readable() can read destination stderr', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 125–126why, one step back125 const piped = pipeDistinctBoth();126TweaksSindre Sorhusbefore adoption698a1b8
line 127why, one step back127 assert.equal(await text(piped.readable({from: 'stderr'})), `${simpleFull}:stderr`);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 128–130why, one step back128 await piped;129});130TweaksSindre Sorhusbefore adoption698a1b8
line 131why, one step back131test('The .pipe() return value .iterable() can read destination stderr', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 132why, one step back132 const piped = pipeDistinctBoth();Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 133why, one step back133 const lines = await Array.fromAsync(piped.iterable({from: 'stderr'}));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 134why, one step back134TweaksSindre Sorhusbefore adoption698a1b8
line 135why, one step back135 assert.deepEqual(lines, ['aaa', 'bbb', 'ccc:stderr']);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 136–138why, one step back136 await piped;137});138TweaksSindre Sorhusbefore adoption698a1b8
line 139why, one step back139test('The .pipe() return value has IPC methods', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 140why, one step back140 const piped = execa('empty.js').pipe('ipc-send-twice.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 141why, one step back141 assert.deepEqual(await getPipeMessages(piped), foobarArray);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 142why, one step back142 const {ipcOutput} = await piped;TweaksSindre Sorhusbefore adoption698a1b8
line 143why, one step back143 assert.deepEqual(ipcOutput, foobarArray);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 144–145why, one step back144});145TweaksSindre Sorhusbefore adoption698a1b8
line 146why, one step back146test('The .pipe() return value .getEachMessage() can be called twice at the same time', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 147–148why, one step back147 const piped = execa('empty.js').pipe('ipc-send-twice.js', {ipc: true});148TweaksSindre Sorhusbefore adoption698a1b8
line 149why, one step back149 assert.deepEqual(Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 150–154why, one step back150 await Promise.all([getPipeMessages(piped), getPipeMessages(piped)]),151 [foobarArray, foobarArray],152 );153154 const {ipcOutput} = await piped;TweaksSindre Sorhusbefore adoption698a1b8
line 155why, one step back155 assert.deepEqual(ipcOutput, foobarArray);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 156–157why, one step back156});157TweaksSindre Sorhusbefore adoption698a1b8
line 158why, one step back158test('The .pipe() return value .getEachMessage() preserves setup errors', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 159–160why, one step back159 const piped = execa('empty.js').pipe('ipc-send-twice.js', {ipc: true});160TweaksSindre Sorhusbefore adoption698a1b8
line 161why, one step back161 assertThrows(() => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 162–167why, one step back162 piped.getEachMessage(null);163 }, {instanceOf: TypeError});164165 await piped;166});167TweaksSindre Sorhusbefore adoption698a1b8
line 168why, one step back168test('The .pipe() return value .getEachMessage() waits for source failure', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 169–170why, one step back169 const piped = execa('fail.js').pipe('ipc-send-twice.js', {ipc: true});170TweaksSindre Sorhusbefore adoption698a1b8
line 171why, one step back171 await assertRejects(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 172why, one step back172 for await (const message of piped.getEachMessage()) {TweaksSindre Sorhusbefore adoption698a1b8
line 173why, one step back173 assert.ok(foobarArray.includes(message));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 174–181why, one step back174 }175 }, {message: /Command failed with exit code 2/});176});177178test('The .pipe() return value .getEachMessage() waits for pipe cancellation', async t => {179 const abortController = new AbortController();180 const source = execa('noop-repeat.js');181 const destination = execa('ipc-send-forever.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 182why, one step back182 t.after(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 183–187why, one step back183 await cleanupSubprocesses(source, destination);184 });185186 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});187 const iterator = piped.getEachMessage();TweaksSindre Sorhusbefore adoption698a1b8
line 188why, one step back188 assert.deepEqual(await iterator.next(), {done: false, value: foobarString});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 189why, one step back189TweaksSindre Sorhusbefore adoption698a1b8
line 190why, one step back190 const readerPromise = assertRejects(iterator.next(), {message: /Pipe canceled/});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 191why, one step back191 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 192why, one step back192 await assertSettles(readerPromise);Fix IPC edge casesSindre Sorhusbefore adoption5f80cde
line 193why, one step back193 assert.equal(destination.nodeChildProcess.connected, true);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 194–199why, one step back194});195196test('The .pipe() return value .getEachMessage() cancels every pending reader', async t => {197 const abortController = new AbortController();198 const source = execa('noop-repeat.js');199 const destination = execa('ipc-send-forever.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 200why, one step back200 t.after(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 201–209why, one step back201 await cleanupSubprocesses(source, destination);202 });203204 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});205 const iterators = [206 piped.getEachMessage(),207 piped.getEachMessage(),208 ];209TweaksSindre Sorhusbefore adoption698a1b8
line 210why, one step back210 assert.deepEqual(Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 211–217why, one step back211 await Promise.all(iterators.map(async iterator => iterator.next())),212 [213 {done: false, value: foobarString},214 {done: false, value: foobarString},215 ],216 );217TweaksSindre Sorhusbefore adoption698a1b8
line 218why, one step back218 const readerPromises = iterators.map(iterator => assertRejects(iterator.next(), {message: /Pipe canceled/}));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 219why, one step back219 abortController.abort();TweaksSindre Sorhusbefore adoption698a1b8
line 220why, one step back220 await Promise.all(readerPromises.map(async readerPromise => assertSettles(readerPromise)));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 221–222why, one step back221});222Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 223why, one step back223const assertCanceledPipeMessageReader = async (t, getReader, shouldAbortBeforePipe = false) => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 224why, one step back224 const abortController = new AbortController();Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 225why, one step back225 if (shouldAbortBeforePipe) {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 226–230why, one step back226 abortController.abort();227 }228229 const source = execa('noop-repeat.js');230 const destination = execa('ipc-get.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 231why, one step back231 t.after(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 232–235why, one step back232 await cleanupSubprocesses(source, destination);233 });234235 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});TweaksSindre Sorhusbefore adoption698a1b8
line 236why, one step back236 const readerPromise = assertRejects(getReader(piped), {message: /Pipe canceled/});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 237why, one step back237Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 238why, one step back238 if (!shouldAbortBeforePipe) {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 239–241why, one step back239 abortController.abort();240 }241TweaksSindre Sorhusbefore adoption698a1b8
lines 242–243why, one step back242 await assertSettles(readerPromise);243 await assertRejects(piped, {message: /Pipe canceled/});Fix IPC edge casesSindre Sorhusbefore adoption5f80cde
lines 244–248why, one step back244245 // The destination keeps running after the pipe is canceled, so it must still be able to use IPC246 assert.equal(destination.nodeChildProcess.connected, true);247 await destination.sendMessage(foobarString);248 await destination;Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 249–269why, one step back249};250251test('The .pipe() return value .getEachMessage() waits for pipe cancellation before IPC messages', async t => {252 await assertCanceledPipeMessageReader(t, piped => piped.getEachMessage().next());253});254255test('The .pipe() return value .getEachMessage() waits for already canceled pipes', async t => {256 await assertCanceledPipeMessageReader(t, piped => piped.getEachMessage().next(), true);257});258259test('The .pipe() return value .getOneMessage() waits for pipe cancellation before IPC messages', async t => {260 await assertCanceledPipeMessageReader(t, piped => piped.getOneMessage());261});262263test('The .pipe() return value .getOneMessage() waits for already canceled pipes', async t => {264 await assertCanceledPipeMessageReader(t, piped => piped.getOneMessage(), true);265});266267test('The .pipe() return value .getEachMessage() waits for the pipe when the iterator is returned', async t => {268 const source = execa('empty.js');269 const destination = execa('ipc-send-forever.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 270why, one step back270 t.after(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 271–276why, one step back271 await cleanupSubprocesses(source, destination);272 });273274 const piped = source.pipe(destination);275 const iterator = piped.getEachMessage();276TweaksSindre Sorhusbefore adoption698a1b8
lines 277–278why, one step back277 assert.deepEqual(await iterator.next(), {done: false, value: foobarString});278 const returnPromise = assertRejects(iterator.return());Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 279–280why, one step back279 destination.kill();280 const error = await returnPromise;TweaksSindre Sorhusbefore adoption698a1b8
line 281why, one step back281 assert.equal(error.isTerminated, true);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 282–284why, one step back282 await Promise.allSettled([source, destination, piped]);283});284TweaksSindre Sorhusbefore adoption698a1b8
line 285why, one step back285test('The .pipe() return value .getEachMessage() propagates source failure when the iterator is returned', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 286–289why, one step back286 const source = execa('ipc-echo-fail.js', {ipc: true});287 const piped = source.pipe('ipc-send-wait-print.js', {ipc: true});288 const iterator = piped.getEachMessage();289TweaksSindre Sorhusbefore adoption698a1b8
lines 290–291why, one step back290 assert.deepEqual(await iterator.next(), {done: false, value: foobarString});291 const returnPromise = assertRejects(iterator.return(), {message: /Command failed with exit code 1/});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 292–295why, one step back292 await source.sendMessage(foobarString);293 await returnPromise;294});295TweaksSindre Sorhusbefore adoption698a1b8
line 296why, one step back296test('The .pipe() return value .getEachMessage() propagates destination failure', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 297–298why, one step back297 const piped = execa('empty.js').pipe('ipc-send-fail.js', {ipc: true});298TweaksSindre Sorhusbefore adoption698a1b8
line 299why, one step back299 await assertRejects(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 300why, one step back300 for await (const message of piped.getEachMessage()) {TweaksSindre Sorhusbefore adoption698a1b8
line 301why, one step back301 assert.equal(message, foobarString);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 302–304why, one step back302 }303 }, {message: /Command failed with exit code 1/});304TweaksSindre Sorhusbefore adoption698a1b8
lines 305–306why, one step back305 const {ipcOutput} = await assertRejects(piped);306 assert.deepEqual(ipcOutput, [foobarString]);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 307–308why, one step back307});308TweaksSindre Sorhusbefore adoption698a1b8
line 309why, one step back309test('The .pipe() return value .getEachMessage() waits for the pipe when the consumer throws', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 310–312why, one step back310 const piped = execa('empty.js').pipe('ipc-send-wait-print.js', {ipc: true});311 const cause = new Error(foobarString);312TweaksSindre Sorhusbefore adoption698a1b8
line 313why, one step back313 assert.equal(await assertRejects(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 314–315why, one step back314 // eslint-disable-next-line no-unreachable-loop315 for await (const message of piped.getEachMessage()) {TweaksSindre Sorhusbefore adoption698a1b8
line 316why, one step back316 assert.equal(message, foobarString);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 317–321why, one step back317 throw cause;318 }319 }), cause);320321 const {ipcOutput, stdout} = await piped;TweaksSindre Sorhusbefore adoption698a1b8
lines 322–323why, one step back322 assert.deepEqual(ipcOutput, [foobarString]);323 assert.equal(stdout, '.');Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 324–328why, one step back324});325326test('The .pipe() return value .getEachMessage() validates IPC immediately', async t => {327 const source = execa('stdin.js');328 const destination = execa('stdin.js');TweaksSindre Sorhusbefore adoption698a1b8
line 329why, one step back329 t.after(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 330–333why, one step back330 await cleanupSubprocesses(source, destination);331 });332333 const piped = source.pipe(destination);TweaksSindre Sorhusbefore adoption698a1b8
line 334why, one step back334 const {message} = assertThrows(() => piped.getEachMessage());Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 335why, one step back335TweaksSindre Sorhusbefore adoption698a1b8
line 336why, one step back336 assert.ok(message.includes('subprocess.getEachMessage() can only be used'));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 337–341why, one step back337 source.kill();338 destination.kill();339 await Promise.allSettled([source, destination, piped]);340});341TweaksSindre Sorhusbefore adoption698a1b8
line 342why, one step back342test('The .pipe() return value can exchange IPC messages', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 343–344why, one step back343 const piped = execa('empty.js').pipe('ipc-echo.js', {ipc: true});344 await piped.sendMessage(foobarString);TweaksSindre Sorhusbefore adoption698a1b8
line 345why, one step back345 assert.equal(await piped.getOneMessage(), foobarString);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 346–348why, one step back346 await piped;347});348TweaksSindre Sorhusbefore adoption698a1b8
line 349why, one step back349test('A chained .pipe() return value can be iterated', async () => {Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 350why, one step back350 const lines = await Array.fromAsync(execa('noop-fd.js', ['1', simpleFull]).pipe('stdin.js').pipe('stdin.js'));Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 351why, one step back351TweaksSindre Sorhusbefore adoption698a1b8
line 352why, one step back352 assert.deepEqual(lines, noNewlinesChunks);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 353–354why, one step back353});354TweaksSindre Sorhusbefore adoption698a1b8
lines 355–356why, one step back355test('The .pipe() return value still awaits both subprocesses', async () => {356 await assertRejects(execa('fail.js').pipe('stdin.js'), {message: /Command failed with exit code 2/});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 357–358why, one step back357});358TweaksSindre Sorhusbefore adoption698a1b8
line 359why, one step back359test('The .pipe() return value iteration waits for source failure', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 360–361why, one step back360 const piped = execa('fail.js').pipe('stdin.js');361TweaksSindre Sorhusbefore adoption698a1b8
line 362why, one step back362 await assertRejects(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 363why, one step back363 for await (const line of piped) {TweaksSindre Sorhusbefore adoption698a1b8
line 364why, one step back364 assert.fail(`Unexpected line: ${line}`);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 365–368why, one step back365 }366 }, {message: /Command failed with exit code 2/});367});368TweaksSindre Sorhusbefore adoption698a1b8
line 369why, one step back369test('The .pipe() return value .readable() waits for source failure', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 370–371why, one step back370 const piped = execa('fail.js').pipe('stdin.js');371TweaksSindre Sorhusbefore adoption698a1b8
line 372why, one step back372 await assertRejects(text(piped.readable()), {message: /Command failed with exit code 2/});Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc
lines 373–374why, one step back373});374TweaksSindre Sorhusbefore adoption698a1b8
line 375why, one step back375test('The .pipe() return value .readableStream() waits for source failure', async () => {Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc
lines 376–377why, one step back376 const piped = execa('fail.js').pipe('stdin.js');377TweaksSindre Sorhusbefore adoption698a1b8
line 378why, one step back378 await assertRejects(text(piped.readableStream()), {message: /Command failed with exit code 2/});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 379–380why, one step back379});380TweaksSindre Sorhusbefore adoption698a1b8
line 381why, one step back381test('The .pipe() return value .all waits for source failure', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 382–383why, one step back382 const piped = execa('fail.js').pipe('stdin.js', {all: true});383TweaksSindre Sorhusbefore adoption698a1b8
line 384why, one step back384 await assertRejects(text(piped.all), {message: /Command failed with exit code 2/});Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d
lines 385–406why, one step back385});386387// Like `subprocess.all`, `.all` does not need an `error` listener, as long as the pipe is awaited388test('The .pipe() return value .all does not need an error listener on source failure', async () => {389 const piped = execa('fail.js').pipe('stdin.js', {all: true});390 piped.all.resume();391 await assertRejects(piped, {message: /Command failed with exit code 2/});392 await setTimeout(0);393});394395test('The .pipe() return value .all does not need an error listener when piped', async () => {396 const piped = execa('fail.js').pipe('stdin.js', {all: true});397 const chunks = [];398 piped.all.pipe(new Writable({399 write(chunk, encoding, done) {400 chunks.push(chunk);401 done();402 },403 }));404 await assertRejects(piped, {message: /Command failed with exit code 2/});405 await setTimeout(0);406 assert.deepEqual(chunks, []);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 407–408why, one step back407});408Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 409why, one step back409const assertCanceledPipeReader = async (t, getReader, shouldAbortBeforePipe = false) => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 410why, one step back410 const abortController = new AbortController();Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 411why, one step back411 if (shouldAbortBeforePipe) {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 412–416why, one step back412 abortController.abort();413 }414415 const source = execa('stdin.js');416 const destination = execa('stdin.js', {all: true});TweaksSindre Sorhusbefore adoption698a1b8
line 417why, one step back417 t.after(async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 418–421why, one step back418 await cleanupSubprocesses(source, destination);419 });420421 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});TweaksSindre Sorhusbefore adoption698a1b8
line 422why, one step back422 const readerPromise = assertRejects(getReader(piped), {message: /Pipe canceled/});Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
line 423why, one step back423Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d
line 424why, one step back424 if (!shouldAbortBeforePipe) {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 425–427why, one step back425 abortController.abort();426 }427TweaksSindre Sorhusbefore adoption698a1b8
line 428why, one step back428 await assertSettles(readerPromise, 200);Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 429–446why, one step back429};430431test('The .pipe() return value .readable() waits for pipe cancellation', async t => {432 await assertCanceledPipeReader(t, piped => text(piped.readable()));433});434435test('The .pipe() return value .all waits for pipe cancellation', async t => {436 await assertCanceledPipeReader(t, piped => text(piped.all));437});438439test('The .pipe() return value .readable() waits for already canceled pipes', async t => {440 await assertCanceledPipeReader(t, piped => text(piped.readable()), true);441});442443test('The .pipe() return value .all waits for already canceled pipes', async t => {444 await assertCanceledPipeReader(t, piped => text(piped.all), true);445});446TweaksSindre Sorhusbefore adoption698a1b8
line 447why, one step back447test('Multiple sources piped to one destination each expose the destination methods', async () => {Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 448–454why, one step back448 const destination = execa('stdin.js');449 const piped = [450 execa('noop-fd.js', ['1', foobarString]).pipe(destination),451 execa('noop-fd.js', ['1', foobarString]).pipe(destination),452 ];453454 for (const pipePromise of piped) {TweaksSindre Sorhusbefore adoption698a1b8
lines 455–456why, one step back455 assert.equal(typeof pipePromise.iterable, 'function');456 assert.equal(typeof pipePromise[Symbol.asyncIterator], 'function');Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c
lines 457–460why, one step back457 }458459 await Promise.all(piped);460});TweaksSindre Sorhusbefore adoption698a1b8
lines 461–462why, one step back461462/* eslint-enable node-test/no-conditional-assertion */