Skip to content
Myr

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 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

line 2why, one step back
2import {setTimeout} from 'node:timers/promises';

Fix `.pipe()` and stream conversion edge casesSindre Sorhusbefore adoptiond3ec10d

line 3why, one step back
3import {Readable, Writable} from 'node:stream';

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

line 4why, one step back
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);

Fix IPC edge casesSindre Sorhusbefore adoption5f80cde

line 193why, one step back
193 assert.equal(destination.nodeChildProcess.connected, true);

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

lines 194–199why, one step back
194});
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 back
200 t.after(async () => {

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

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

TweaksSindre Sorhusbefore adoption698a1b8

line 218why, one step back
218 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 back
219 abortController.abort();

TweaksSindre Sorhusbefore adoption698a1b8

line 220why, one step back
220 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 back
221});
222

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

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

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

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

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

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

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

lines 226–230why, one step back
226 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 back
231 t.after(async () => {

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

line 237why, one step back
237

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

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

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

Fix IPC edge casesSindre Sorhusbefore adoption5f80cde

lines 244–248why, one step back
244
245 // 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 back
249};
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 back
270 t.after(async () => {

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

lines 271–276why, one step back
271 await cleanupSubprocesses(source, destination);
272 });273274 const piped = source.pipe(destination);275 const iterator = piped.getEachMessage();276

TweaksSindre Sorhusbefore adoption698a1b8

lines 277–278why, one step back
277 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 back
279 destination.kill();
280 const error = await returnPromise;

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 282–284why, one step back
282 await Promise.allSettled([source, destination, piped]);
283});284

TweaksSindre Sorhusbefore adoption698a1b8

line 285why, one step back
285test('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 back
286 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();289

TweaksSindre Sorhusbefore adoption698a1b8

lines 290–291why, one step back
290 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 back
292 await source.sendMessage(foobarString);
293 await returnPromise;294});295

TweaksSindre Sorhusbefore adoption698a1b8

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 302–304why, one step back
302 }
303 }, {message: /Command failed with exit code 1/});304

TweaksSindre Sorhusbefore adoption698a1b8

lines 305–306why, one step back
305 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 back
307});
308

TweaksSindre Sorhusbefore adoption698a1b8

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 317–321why, one step back
317 throw cause;
318 }319 }), cause);320321 const {ipcOutput, stdout} = await piped;

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 324–328why, one step back
324});
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 back
329 t.after(async () => {

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

lines 330–333why, one step back
330 await cleanupSubprocesses(source, destination);
331 });332333 const piped = source.pipe(destination);

TweaksSindre Sorhusbefore adoption698a1b8

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

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

line 335why, one step back
335

TweaksSindre Sorhusbefore adoption698a1b8

line 336why, one step back
336 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 back
337 source.kill();
338 destination.kill();339 await Promise.allSettled([source, destination, piped]);340});341

TweaksSindre Sorhusbefore adoption698a1b8

line 342why, one step back
342test('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 back
343 const piped = execa('empty.js').pipe('ipc-echo.js', {ipc: true});
344 await piped.sendMessage(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

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

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 350why, one step back
350 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 back
351

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 353–354why, one step back
353});
354

TweaksSindre Sorhusbefore adoption698a1b8

lines 355–356why, one step back
355test('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 back
357});
358

TweaksSindre Sorhusbefore adoption698a1b8

line 359why, one step back
359test('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 back
360 const piped = execa('fail.js').pipe('stdin.js');
361

TweaksSindre Sorhusbefore adoption698a1b8

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

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

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

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 365–368why, one step back
365 }
366 }, {message: /Command failed with exit code 2/});367});368

TweaksSindre Sorhusbefore adoption698a1b8

line 369why, one step back
369test('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 back
370 const piped = execa('fail.js').pipe('stdin.js');
371

TweaksSindre Sorhusbefore adoption698a1b8

line 372why, one step back
372 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 back
373});
374

TweaksSindre Sorhusbefore adoption698a1b8

line 375why, one step back
375test('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 back
376 const piped = execa('fail.js').pipe('stdin.js');
377

TweaksSindre Sorhusbefore adoption698a1b8

line 378why, one step back
378 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 back
379});
380

TweaksSindre Sorhusbefore adoption698a1b8

line 381why, one step back
381test('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 back
382 const piped = execa('fail.js').pipe('stdin.js', {all: true});
383

TweaksSindre Sorhusbefore adoption698a1b8

line 384why, one step back
384 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 back
385});
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 back
407});
408

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

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

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

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

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

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

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

lines 412–416why, one step back
412 abortController.abort();
413 }414415 const source = execa('stdin.js');416 const destination = execa('stdin.js', {all: true});

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 418–421why, one step back
418 await cleanupSubprocesses(source, destination);
419 });420421 const piped = source.pipe(destination, {unpipeSignal: abortController.signal});

TweaksSindre Sorhusbefore adoption698a1b8

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

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

line 423why, one step back
423

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

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

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

lines 425–427why, one step back
425 abortController.abort();
426 }427

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 429–446why, one step back
429};
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});446

TweaksSindre Sorhusbefore adoption698a1b8

line 447why, one step back
447test('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 back
448 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 back
455 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 back
457 }
458459 await Promise.all(piped);460});

TweaksSindre Sorhusbefore adoption698a1b8

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