Skip to content
Myr

methods.js

This file

Path

test/pipe/methods.js

434 lines · 15.0 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

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

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 2–4why, one step back
2import {setTimeout} from 'node:timers/promises';
3import {Readable} from 'node:stream';4import {text} from 'node:stream/consumers';

TweaksSindre Sorhusbefore adoption698a1b8

lines 5–6why, one step back
5import 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 back
7import {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 back
11/* 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 back
12
13setFixtureDirectory();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');21

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22const assertSettles = async (promise, timeout = 1000) => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 23–28why, one step back
23 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 ]);28

TweaksSindre Sorhusbefore adoption698a1b8

line 29why, one step back
29 assert.notEqual(result, timeoutSymbol);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 30–41why, one step back
30 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 back
42 const messages = await Array.fromAsync(piped.getEachMessage());

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 43–46why, one step back
43
44 return messages;45};46

TweaksSindre Sorhusbefore adoption698a1b8

line 47why, one step back
47test('The .pipe() return value can be iterated', async () => {

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 48why, one step back
48 const lines = await Array.fromAsync(pipeSimple());

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 49why, one step back
49

TweaksSindre Sorhusbefore adoption698a1b8

line 50why, one step back
50 assert.deepEqual(lines, noNewlinesChunks);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 51–52why, one step back
51});
52

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53test('The .pipe() return value has an .iterable() method', async () => {

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 54why, one step back
54 const lines = await Array.fromAsync(pipeSimple().iterable());

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 55why, one step back
55

TweaksSindre Sorhusbefore adoption698a1b8

line 56why, one step back
56 assert.deepEqual(lines, noNewlinesChunks);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 57–58why, one step back
57});
58

TweaksSindre Sorhusbefore adoption698a1b8

lines 59–60why, one step back
59test('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 back
61});
62

TweaksSindre Sorhusbefore adoption698a1b8

lines 63–64why, one step back
63test('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 back
65});
66

TweaksSindre Sorhusbefore adoption698a1b8

line 67why, one step back
67test('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 back
68 const piped = pipeSimple();
69 const [output, secondOutput] = await Promise.all([70 text(piped.readable()),71 text(piped.readable()),72 ]);73

TweaksSindre Sorhusbefore adoption698a1b8

lines 74–75why, one step back
74 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 back
76});
77

TweaksSindre Sorhusbefore adoption698a1b8

line 78why, one step back
78test('The .pipe() return value .readable() keeps conversion options', async () => {

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 79why, one step back
79 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 back
80

TweaksSindre Sorhusbefore adoption698a1b8

lines 81–82why, one step back
81 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 back
83});
84

TweaksSindre Sorhusbefore adoption698a1b8

line 85why, one step back
85test('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 back
86 const piped = pipeSimple();

TweaksSindre Sorhusbefore adoption698a1b8

lines 87–90why, one step back
87 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 back
91 await piped;
92});93

TweaksSindre Sorhusbefore adoption698a1b8

line 94why, one step back
94test('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 back
95 const piped = pipeSimple();
96 const descriptor = Object.getOwnPropertyDescriptor(piped, 'all');97

TweaksSindre Sorhusbefore adoption698a1b8

lines 98–100why, one step back
98 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 back
101 await piped;
102});103

TweaksSindre Sorhusbefore adoption698a1b8

line 104why, one step back
104test('The .pipe() return value has an .all property', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 105why, one step back
105 const piped = pipeAll();

TweaksSindre Sorhusbefore adoption698a1b8

lines 106–107why, one step back
106 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 back
108 await piped;
109});110

TweaksSindre Sorhusbefore adoption698a1b8

line 111why, one step back
111test('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 back
112 const piped = pipeAll();
113 const descriptor = Object.getOwnPropertyDescriptor(piped, 'all');114

TweaksSindre Sorhusbefore adoption698a1b8

line 115why, one step back
115 assert.equal(typeof descriptor.get, 'function');

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 116why, one step back
116 const {all} = piped;

TweaksSindre Sorhusbefore adoption698a1b8

lines 117–120why, one step back
117 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 back
121 await piped;
122});123

TweaksSindre Sorhusbefore adoption698a1b8

line 124why, one step back
124test('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 back
125 const piped = pipeDistinctBoth();
126

TweaksSindre Sorhusbefore adoption698a1b8

line 127why, one step back
127 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 back
128 await piped;
129});130

TweaksSindre Sorhusbefore adoption698a1b8

line 131why, one step back
131test('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 back
132 const piped = pipeDistinctBoth();

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 133why, one step back
133 const lines = await Array.fromAsync(piped.iterable({from: 'stderr'}));

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 134why, one step back
134

TweaksSindre Sorhusbefore adoption698a1b8

line 135why, one step back
135 assert.deepEqual(lines, ['aaa', 'bbb', 'ccc:stderr']);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 136–138why, one step back
136 await piped;
137});138

TweaksSindre Sorhusbefore adoption698a1b8

line 139why, one step back
139test('The .pipe() return value has IPC methods', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 140why, one step back
140 const piped = execa('empty.js').pipe('ipc-send-twice.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 141why, one step back
141 assert.deepEqual(await getPipeMessages(piped), foobarArray);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 142why, one step back
142 const {ipcOutput} = await piped;

TweaksSindre Sorhusbefore adoption698a1b8

line 143why, one step back
143 assert.deepEqual(ipcOutput, foobarArray);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 144–145why, one step back
144});
145

TweaksSindre Sorhusbefore adoption698a1b8

line 146why, one step back
146test('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 back
147 const piped = execa('empty.js').pipe('ipc-send-twice.js', {ipc: true});
148

TweaksSindre Sorhusbefore adoption698a1b8

line 149why, one step back
149 assert.deepEqual(

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 150–154why, one step back
150 await Promise.all([getPipeMessages(piped), getPipeMessages(piped)]),
151 [foobarArray, foobarArray],152 );153154 const {ipcOutput} = await piped;

TweaksSindre Sorhusbefore adoption698a1b8

line 155why, one step back
155 assert.deepEqual(ipcOutput, foobarArray);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 156–157why, one step back
156});
157

TweaksSindre Sorhusbefore adoption698a1b8

line 158why, one step back
158test('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 back
159 const piped = execa('empty.js').pipe('ipc-send-twice.js', {ipc: true});
160

TweaksSindre Sorhusbefore adoption698a1b8

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

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 162–167why, one step back
162 piped.getEachMessage(null);
163 }, {instanceOf: TypeError});164165 await piped;166});167

TweaksSindre Sorhusbefore adoption698a1b8

line 168why, one step back
168test('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 back
169 const piped = execa('fail.js').pipe('ipc-send-twice.js', {ipc: true});
170

TweaksSindre Sorhusbefore adoption698a1b8

line 171why, one step back
171 await assertRejects(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 172why, one step back
172 for await (const message of piped.getEachMessage()) {

TweaksSindre Sorhusbefore adoption698a1b8

line 173why, one step back
173 assert.ok(foobarArray.includes(message));

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 174–181why, one step back
174 }
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 back
182 t.after(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 183–187why, one step back
183 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 back
188 assert.deepEqual(await iterator.next(), {done: false, value: foobarString});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 189why, one step back
189

TweaksSindre Sorhusbefore adoption698a1b8

line 190why, one step back
190 const readerPromise = assertRejects(iterator.next(), {message: /Pipe canceled/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 191why, one step back
191 abortController.abort();

TweaksSindre Sorhusbefore adoption698a1b8

line 192why, one step back
192 await assertSettles(readerPromise);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 193–198why, one step back
193});
194195test('The .pipe() return value .getEachMessage() cancels every pending reader', async t => {196 const abortController = new AbortController();197 const source = execa('noop-repeat.js');198 const destination = execa('ipc-send-forever.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 199why, one step back
199 t.after(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 200–208why, one step back
200 await cleanupSubprocesses(source, destination);
201 });202203 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});204 const iterators = [205 piped.getEachMessage(),206 piped.getEachMessage(),207 ];208

TweaksSindre Sorhusbefore adoption698a1b8

line 209why, one step back
209 assert.deepEqual(

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 210–216why, one step back
210 await Promise.all(iterators.map(async iterator => iterator.next())),
211 [212 {done: false, value: foobarString},213 {done: false, value: foobarString},214 ],215 );216

TweaksSindre Sorhusbefore adoption698a1b8

line 217why, one step back
217 const readerPromises = iterators.map(iterator => assertRejects(iterator.next(), {message: /Pipe canceled/}));

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 218why, one step back
218 abortController.abort();

TweaksSindre Sorhusbefore adoption698a1b8

line 219why, one step back
219 await Promise.all(readerPromises.map(async readerPromise => assertSettles(readerPromise)));

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 220–221why, one step back
220});
221

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 222why, one step back
222const assertCanceledPipeMessageReader = async (t, getReader, shouldAbortBeforePipe = false) => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 223why, one step back
223 const abortController = new AbortController();

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 224why, one step back
224 if (shouldAbortBeforePipe) {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 225–229why, one step back
225 abortController.abort();
226 }227228 const source = execa('noop-repeat.js');229 const destination = execa('ipc-get.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 230why, one step back
230 t.after(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 231–234why, one step back
231 await cleanupSubprocesses(source, destination);
232 });233234 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});

TweaksSindre Sorhusbefore adoption698a1b8

line 235why, one step back
235 const readerPromise = assertRejects(getReader(piped), {message: /Pipe canceled/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 236why, one step back
236

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 237why, one step back
237 if (!shouldAbortBeforePipe) {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 238–240why, one step back
238 abortController.abort();
239 }240

TweaksSindre Sorhusbefore adoption698a1b8

lines 241–242why, one step back
241 await assertSettles(readerPromise);
242 await assertRejects(piped, {message: /Pipe canceled/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 243–263why, one step back
243};
244245test('The .pipe() return value .getEachMessage() waits for pipe cancellation before IPC messages', async t => {246 await assertCanceledPipeMessageReader(t, piped => piped.getEachMessage().next());247});248249test('The .pipe() return value .getEachMessage() waits for already canceled pipes', async t => {250 await assertCanceledPipeMessageReader(t, piped => piped.getEachMessage().next(), true);251});252253test('The .pipe() return value .getOneMessage() waits for pipe cancellation before IPC messages', async t => {254 await assertCanceledPipeMessageReader(t, piped => piped.getOneMessage());255});256257test('The .pipe() return value .getOneMessage() waits for already canceled pipes', async t => {258 await assertCanceledPipeMessageReader(t, piped => piped.getOneMessage(), true);259});260261test('The .pipe() return value .getEachMessage() waits for the pipe when the iterator is returned', async t => {262 const source = execa('empty.js');263 const destination = execa('ipc-send-forever.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 264why, one step back
264 t.after(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 265–270why, one step back
265 await cleanupSubprocesses(source, destination);
266 });267268 const piped = source.pipe(destination);269 const iterator = piped.getEachMessage();270

TweaksSindre Sorhusbefore adoption698a1b8

lines 271–272why, one step back
271 assert.deepEqual(await iterator.next(), {done: false, value: foobarString});
272 const returnPromise = assertRejects(iterator.return());

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 273–274why, one step back
273 destination.kill();
274 const error = await returnPromise;

TweaksSindre Sorhusbefore adoption698a1b8

line 275why, one step back
275 assert.equal(error.isTerminated, true);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 276–278why, one step back
276 await Promise.allSettled([source, destination, piped]);
277});278

TweaksSindre Sorhusbefore adoption698a1b8

line 279why, one step back
279test('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 280–283why, one step back
280 const source = execa('ipc-echo-fail.js', {ipc: true});
281 const piped = source.pipe('ipc-send-wait-print.js', {ipc: true});282 const iterator = piped.getEachMessage();283

TweaksSindre Sorhusbefore adoption698a1b8

lines 284–285why, one step back
284 assert.deepEqual(await iterator.next(), {done: false, value: foobarString});
285 const returnPromise = assertRejects(iterator.return(), {message: /Command failed with exit code 1/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 286–289why, one step back
286 await source.sendMessage(foobarString);
287 await returnPromise;288});289

TweaksSindre Sorhusbefore adoption698a1b8

line 290why, one step back
290test('The .pipe() return value .getEachMessage() propagates destination failure', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 291–292why, one step back
291 const piped = execa('empty.js').pipe('ipc-send-fail.js', {ipc: true});
292

TweaksSindre Sorhusbefore adoption698a1b8

line 293why, one step back
293 await assertRejects(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 294why, one step back
294 for await (const message of piped.getEachMessage()) {

TweaksSindre Sorhusbefore adoption698a1b8

line 295why, one step back
295 assert.equal(message, foobarString);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 296–298why, one step back
296 }
297 }, {message: /Command failed with exit code 1/});298

TweaksSindre Sorhusbefore adoption698a1b8

lines 299–300why, one step back
299 const {ipcOutput} = await assertRejects(piped);
300 assert.deepEqual(ipcOutput, [foobarString]);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 301–302why, one step back
301});
302

TweaksSindre Sorhusbefore adoption698a1b8

line 303why, one step back
303test('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 304–306why, one step back
304 const piped = execa('empty.js').pipe('ipc-send-wait-print.js', {ipc: true});
305 const cause = new Error(foobarString);306

TweaksSindre Sorhusbefore adoption698a1b8

line 307why, one step back
307 assert.equal(await assertRejects(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 308–309why, one step back
308 // eslint-disable-next-line no-unreachable-loop
309 for await (const message of piped.getEachMessage()) {

TweaksSindre Sorhusbefore adoption698a1b8

line 310why, one step back
310 assert.equal(message, foobarString);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 311–315why, one step back
311 throw cause;
312 }313 }), cause);314315 const {ipcOutput, stdout} = await piped;

TweaksSindre Sorhusbefore adoption698a1b8

lines 316–317why, one step back
316 assert.deepEqual(ipcOutput, [foobarString]);
317 assert.equal(stdout, '.');

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 318–322why, one step back
318});
319320test('The .pipe() return value .getEachMessage() validates IPC immediately', async t => {321 const source = execa('stdin.js');322 const destination = execa('stdin.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 323why, one step back
323 t.after(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 324–327why, one step back
324 await cleanupSubprocesses(source, destination);
325 });326327 const piped = source.pipe(destination);

TweaksSindre Sorhusbefore adoption698a1b8

line 328why, one step back
328 const {message} = assertThrows(() => piped.getEachMessage());

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 329why, one step back
329

TweaksSindre Sorhusbefore adoption698a1b8

line 330why, one step back
330 assert.ok(message.includes('subprocess.getEachMessage() can only be used'));

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 331–335why, one step back
331 source.kill();
332 destination.kill();333 await Promise.allSettled([source, destination, piped]);334});335

TweaksSindre Sorhusbefore adoption698a1b8

line 336why, one step back
336test('The .pipe() return value can exchange IPC messages', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 337–338why, one step back
337 const piped = execa('empty.js').pipe('ipc-echo.js', {ipc: true});
338 await piped.sendMessage(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

line 339why, one step back
339 assert.equal(await piped.getOneMessage(), foobarString);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 340–342why, one step back
340 await piped;
341});342

TweaksSindre Sorhusbefore adoption698a1b8

line 343why, one step back
343test('A chained .pipe() return value can be iterated', async () => {

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 344why, one step back
344 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 345why, one step back
345

TweaksSindre Sorhusbefore adoption698a1b8

line 346why, one step back
346 assert.deepEqual(lines, noNewlinesChunks);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 347–348why, one step back
347});
348

TweaksSindre Sorhusbefore adoption698a1b8

lines 349–350why, one step back
349test('The .pipe() return value still awaits both subprocesses', async () => {
350 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 351–352why, one step back
351});
352

TweaksSindre Sorhusbefore adoption698a1b8

line 353why, one step back
353test('The .pipe() return value iteration waits for source failure', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 354–355why, one step back
354 const piped = execa('fail.js').pipe('stdin.js');
355

TweaksSindre Sorhusbefore adoption698a1b8

line 356why, one step back
356 await assertRejects(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 357why, one step back
357 for await (const line of piped) {

TweaksSindre Sorhusbefore adoption698a1b8

line 358why, one step back
358 assert.fail(`Unexpected line: ${line}`);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 359–362why, one step back
359 }
360 }, {message: /Command failed with exit code 2/});361});362

TweaksSindre Sorhusbefore adoption698a1b8

line 363why, one step back
363test('The .pipe() return value .readable() waits for source failure', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 364–365why, one step back
364 const piped = execa('fail.js').pipe('stdin.js');
365

TweaksSindre Sorhusbefore adoption698a1b8

line 366why, one step back
366 await assertRejects(text(piped.readable()), {message: /Command failed with exit code 2/});

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 367–368why, one step back
367});
368

TweaksSindre Sorhusbefore adoption698a1b8

line 369why, one step back
369test('The .pipe() return value .readableStream() waits for source failure', async () => {

Add `.readableStream()`, `.writableStream()` and `.transformStream()` methods (#1254)Sindre Sorhusbefore adoption29d9cfc

lines 370–371why, one step back
370 const piped = execa('fail.js').pipe('stdin.js');
371

TweaksSindre Sorhusbefore adoption698a1b8

line 372why, one step back
372 await assertRejects(text(piped.readableStream()), {message: /Command failed with exit code 2/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 373–374why, one step back
373});
374

TweaksSindre Sorhusbefore adoption698a1b8

line 375why, one step back
375test('The .pipe() return value .all waits for source failure', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 376–377why, one step back
376 const piped = execa('fail.js').pipe('stdin.js', {all: true});
377

TweaksSindre Sorhusbefore adoption698a1b8

line 378why, one step back
378 await assertRejects(text(piped.all), {message: /Command failed with exit code 2/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 379–380why, one step back
379});
380

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 381why, one step back
381const assertCanceledPipeReader = async (t, getReader, shouldAbortBeforePipe = false) => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 382why, one step back
382 const abortController = new AbortController();

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 383why, one step back
383 if (shouldAbortBeforePipe) {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 384–388why, one step back
384 abortController.abort();
385 }386387 const source = execa('stdin.js');388 const destination = execa('stdin.js', {all: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 389why, one step back
389 t.after(async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 390–393why, one step back
390 await cleanupSubprocesses(source, destination);
391 });392393 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});

TweaksSindre Sorhusbefore adoption698a1b8

line 394why, one step back
394 const readerPromise = assertRejects(getReader(piped), {message: /Pipe canceled/});

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

line 395why, one step back
395

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 396why, one step back
396 if (!shouldAbortBeforePipe) {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 397–399why, one step back
397 abortController.abort();
398 }399

TweaksSindre Sorhusbefore adoption698a1b8

line 400why, one step back
400 await assertSettles(readerPromise, 200);

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 401–418why, one step back
401};
402403test('The .pipe() return value .readable() waits for pipe cancellation', async t => {404 await assertCanceledPipeReader(t, piped => text(piped.readable()));405});406407test('The .pipe() return value .all waits for pipe cancellation', async t => {408 await assertCanceledPipeReader(t, piped => text(piped.all));409});410411test('The .pipe() return value .readable() waits for already canceled pipes', async t => {412 await assertCanceledPipeReader(t, piped => text(piped.readable()), true);413});414415test('The .pipe() return value .all waits for already canceled pipes', async t => {416 await assertCanceledPipeReader(t, piped => text(piped.all), true);417});418

TweaksSindre Sorhusbefore adoption698a1b8

line 419why, one step back
419test('Multiple sources piped to one destination each expose the destination methods', async () => {

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 420–426why, one step back
420 const destination = execa('stdin.js');
421 const piped = [422 execa('noop-fd.js', ['1', foobarString]).pipe(destination),423 execa('noop-fd.js', ['1', foobarString]).pipe(destination),424 ];425426 for (const pipePromise of piped) {

TweaksSindre Sorhusbefore adoption698a1b8

lines 427–428why, one step back
427 assert.equal(typeof pipePromise.iterable, 'function');
428 assert.equal(typeof pipePromise[Symbol.asyncIterator], 'function');

Expose the destination subprocess methods on `.pipe()` (#1252)Sindre Sorhusbefore adoptionc31c94c

lines 429–432why, one step back
429 }
430431 await Promise.all(piped);432});

TweaksSindre Sorhusbefore adoption698a1b8

lines 433–434why, one step back
433
434/* eslint-enable node-test/no-conditional-assertion */