Skip to content
Myr

sequence.js

This file

Path

test/pipe/sequence.js

400 lines · 15.1 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 2–4why, one step back
2import {once} from 'node:events';
3import process from 'node:process';4import {PassThrough} from 'node:stream';

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

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 6–7why, one step back
6import test from 'node:test';
7import {assertRejects, assertLike} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 8–16why, one step back
8import {execa} from '../../index.js';
9import {setFixtureDirectory} from '../helpers/fixtures-directory.js';10import {foobarString} from '../helpers/input.js';11import {noopGenerator} from '../helpers/generator.js';12import {prematureClose} from '../helpers/stdio.js';1314setFixtureDirectory();1516const isLinux = process.platform === 'linux';

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

line 17why, one step back
17const timeoutSymbol = Symbol('timeout');

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18

TweaksSindre Sorhusbefore adoption698a1b8

lines 19–37why, one step back
19// The `unhandledRejection` event is what these tests assert on, but `node:test` also listens to it
20// and fails any test during which it fires. That listener is removed while the event is observed,21// since the event itself is what `assertUnhandledRejection()` asserts on.22const observeUnhandledRejection = async () => {23 const testRunnerListeners = process.listeners('unhandledRejection');24 for (const listener of testRunnerListeners) {25 process.removeListener('unhandledRejection', listener);26 }2728 try {29 return await once(process, 'unhandledRejection');30 } finally {31 for (const listener of testRunnerListeners) {32 process.on('unhandledRejection', listener);33 }34 }35};3637const assertUnhandledRejection = async pipePromise => {

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

line 38why, one step back
38 const result = await Promise.race([

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–40why, one step back
39 observeUnhandledRejection(),
40 setTimeout(5000, timeoutSymbol),

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

lines 41–42why, one step back
41 ]);
42

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 44–49why, one step back
44
45 if (result === timeoutSymbol) {46 return;47 }4849 const [reason, unhandledPromise] = result;

TweaksSindre Sorhusbefore adoption698a1b8

lines 50–51why, one step back
50 assert.equal(unhandledPromise, pipePromise);
51 assert.match(reason.message, /Command failed with exit code 2/);

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

lines 52–53why, one step back
52};
53

TweaksSindre Sorhusbefore adoption698a1b8

line 54why, one step back
54const assertUnhandledPipePromise = async ({destinationOptions = {}, inspectPipePromise} = {}) => {

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

lines 55–58why, one step back
55 const source = execa('fail.js');
56 const destination = execa('fail.js', destinationOptions);57 const pipePromise = source.pipe(destination);58 await inspectPipePromise?.(pipePromise);

TweaksSindre Sorhusbefore adoption698a1b8

line 59why, one step back
59 await assertUnhandledRejection(pipePromise);

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

line 60why, one step back
60 await Promise.all([

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–62why, one step back
61 assertRejects(source),
62 assertRejects(destination),

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

line 63why, one step back
63 ]);

TweaksSindre Sorhusbefore adoption698a1b8

line 64why, one step back
64 await assertRejects(pipePromise);

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

lines 65–66why, one step back
65};
66

TweaksSindre Sorhusbefore adoption698a1b8

line 67why, one step back
67test('Source stream abort -> destination success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 68–72why, one step back
68 const source = execa('noop-repeat.js');
69 const destination = execa('stdin.js');70 const pipePromise = source.pipe(destination);71 source.stdout.destroy();72

TweaksSindre Sorhusbefore adoption698a1b8

lines 73–74why, one step back
73 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
74 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 75–77why, one step back
75 await destination;
76});77

TweaksSindre Sorhusbefore adoption698a1b8

line 78why, one step back
78test('Source stream error -> destination success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 79–84why, one step back
79 const source = execa('noop-repeat.js');
80 const destination = execa('stdin.js');81 const pipePromise = source.pipe(destination);82 const cause = new Error('test');83 source.stdout.destroy(cause);84

TweaksSindre Sorhusbefore adoption698a1b8

lines 85–86why, one step back
85 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
86 assertLike(await assertRejects(source), {originalMessage: cause.message, exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 87–89why, one step back
87 await destination;
88});89

TweaksSindre Sorhusbefore adoption698a1b8

line 90why, one step back
90test('Destination stream abort -> source failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 91–95why, one step back
91 const source = execa('noop-repeat.js');
92 const destination = execa('stdin.js');93 const pipePromise = source.pipe(destination);94 destination.stdin.destroy();95

TweaksSindre Sorhusbefore adoption698a1b8

lines 96–98why, one step back
96 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
97 assertLike(await assertRejects(destination), prematureClose);98 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 99–100why, one step back
99});
100

TweaksSindre Sorhusbefore adoption698a1b8

line 101why, one step back
101test('Destination stream error -> source failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 102–107why, one step back
102 const source = execa('noop-repeat.js');
103 const destination = execa('stdin.js');104 const pipePromise = source.pipe(destination);105 const cause = new Error('test');106 destination.stdin.destroy(cause);107

TweaksSindre Sorhusbefore adoption698a1b8

lines 108–110why, one step back
108 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
109 assertLike(await assertRejects(destination), {originalMessage: cause.message, exitCode: 0});110 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 111–112why, one step back
111});
112

TweaksSindre Sorhusbefore adoption698a1b8

line 113why, one step back
113test('Source success -> destination success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 114–117why, one step back
114 const source = execa('noop.js', [foobarString]);
115 const destination = execa('stdin.js');116 const pipePromise = source.pipe(destination);117

TweaksSindre Sorhusbefore adoption698a1b8

lines 118–120why, one step back
118 assertLike(await source, {stdout: foobarString});
119 assertLike(await destination, {stdout: foobarString});120 assert.equal(await pipePromise, await destination);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 121–122why, one step back
121});
122

TweaksSindre Sorhusbefore adoption698a1b8

line 123why, one step back
123test('Destination stream end -> source failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 124–128why, one step back
124 const source = execa('noop-repeat.js');
125 const destination = execa('stdin.js');126 const pipePromise = source.pipe(destination);127 destination.stdin.end();128

TweaksSindre Sorhusbefore adoption698a1b8

line 129why, one step back
129 assert.equal(await assertRejects(pipePromise), await assertRejects(source));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 130why, one step back
130 await destination;

TweaksSindre Sorhusbefore adoption698a1b8

line 131why, one step back
131 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 132–133why, one step back
132});
133

TweaksSindre Sorhusbefore adoption698a1b8

line 134why, one step back
134test('Source normal failure -> destination success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 135–138why, one step back
135 const source = execa('noop-fail.js', ['1', foobarString]);
136 const destination = execa('stdin.js');137 const pipePromise = source.pipe(destination);138

TweaksSindre Sorhusbefore adoption698a1b8

lines 139–140why, one step back
139 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
140 assertLike(await assertRejects(source), {stdout: foobarString, exitCode: 2});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 141–143why, one step back
141 await destination;
142});143

TweaksSindre Sorhusbefore adoption698a1b8

line 144why, one step back
144test('Source normal failure -> deep destination success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 145–150why, one step back
145 const source = execa('noop-fail.js', ['1', foobarString]);
146 const destination = execa('stdin.js');147 const secondDestination = execa('stdin.js');148 const pipePromise = source.pipe(destination);149 const secondPipePromise = pipePromise.pipe(secondDestination);150

TweaksSindre Sorhusbefore adoption698a1b8

lines 151–155why, one step back
151 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
152 assert.equal(await assertRejects(secondPipePromise), await assertRejects(source));153 assertLike(await assertRejects(source), {stdout: foobarString, exitCode: 2});154 assertLike(await destination, {stdout: foobarString});155 assertLike(await secondDestination, {stdout: foobarString});

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 158why, one step back
158const testSourceTerminated = async signal => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 159–163why, one step back
159 const source = execa('noop-repeat.js');
160 const destination = execa('stdin.js');161 const pipePromise = source.pipe(destination);162 source.kill(signal);163

TweaksSindre Sorhusbefore adoption698a1b8

lines 164–165why, one step back
164 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
165 assertLike(await assertRejects(source), {signal});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 166–168why, one step back
166 await destination;
167};168

TweaksSindre Sorhusbefore adoption698a1b8

lines 169–170why, one step back
169test('Source SIGTERM -> destination success', () => testSourceTerminated('SIGTERM'));
170test('Source SIGKILL -> destination success', () => testSourceTerminated('SIGKILL'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 171why, one step back
171

TweaksSindre Sorhusbefore adoption698a1b8

line 172why, one step back
172test('Destination success before source -> source success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 173–180why, one step back
173 const passThroughStream = new PassThrough();
174 const source = execa('stdin.js', {stdin: ['pipe', passThroughStream]});175 const destination = execa('empty.js');176 const pipePromise = source.pipe(destination);177178 await destination;179 passThroughStream.end();180 await source;

TweaksSindre Sorhusbefore adoption698a1b8

line 181why, one step back
181 assert.equal(await pipePromise, await destination);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 182–183why, one step back
182});
183

TweaksSindre Sorhusbefore adoption698a1b8

line 184why, one step back
184test('Destination normal failure -> source failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 185–188why, one step back
185 const source = execa('noop-repeat.js');
186 const destination = execa('fail.js');187 const pipePromise = source.pipe(destination);188

TweaksSindre Sorhusbefore adoption698a1b8

lines 189–191why, one step back
189 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
190 assertLike(await assertRejects(destination), {exitCode: 2});191 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 192–193why, one step back
192});
193

TweaksSindre Sorhusbefore adoption698a1b8

line 194why, one step back
194test('Destination normal failure -> deep source failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 195–200why, one step back
195 const source = execa('noop-repeat.js');
196 const destination = execa('stdin.js');197 const secondDestination = execa('fail.js');198 const pipePromise = source.pipe(destination);199 const secondPipePromise = pipePromise.pipe(secondDestination);200

TweaksSindre Sorhusbefore adoption698a1b8

lines 201–205why, one step back
201 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
202 assert.equal(await assertRejects(secondPipePromise), await assertRejects(secondDestination));203 assertLike(await assertRejects(secondDestination), {exitCode: 2});204 assertLike(await assertRejects(destination), {exitCode: 1});205 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 206–207why, one step back
206});
207

TweaksSindre Sorhusbefore adoption698a1b8

line 208why, one step back
208const testDestinationTerminated = async signal => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 209–213why, one step back
209 const source = execa('noop-repeat.js');
210 const destination = execa('stdin.js');211 const pipePromise = source.pipe(destination);212 destination.kill(signal);213

TweaksSindre Sorhusbefore adoption698a1b8

lines 214–216why, one step back
214 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
215 assertLike(await assertRejects(destination), {signal});216 assertLike(await assertRejects(source), {exitCode: 1});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 217–218why, one step back
217};
218

TweaksSindre Sorhusbefore adoption698a1b8

lines 219–220why, one step back
219test('Destination SIGTERM -> source abort', () => testDestinationTerminated('SIGTERM'));
220test('Destination SIGKILL -> source abort', () => testDestinationTerminated('SIGKILL'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 221why, one step back
221

TweaksSindre Sorhusbefore adoption698a1b8

line 222why, one step back
222test('Source already ended -> ignore source', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 223–227why, one step back
223 const source = execa('noop.js', [foobarString]);
224 await source;225 const destination = execa('stdin.js');226 const pipePromise = source.pipe(destination);227

TweaksSindre Sorhusbefore adoption698a1b8

lines 228–230why, one step back
228 assert.equal(await pipePromise, await destination);
229 assertLike(await source, {stdout: foobarString});230 assertLike(await destination, {stdout: ''});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 231–232why, one step back
231});
232

TweaksSindre Sorhusbefore adoption698a1b8

line 233why, one step back
233test('Source already aborted -> ignore source', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 234–238why, one step back
234 const source = execa('noop.js', [foobarString]);
235 source.stdout.destroy();236 const destination = execa('stdin.js');237 const pipePromise = source.pipe(destination);238

TweaksSindre Sorhusbefore adoption698a1b8

lines 239–241why, one step back
239 assert.equal(await pipePromise, await destination);
240 assertLike(await source, {stdout: ''});241 assertLike(await destination, {stdout: ''});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 242–243why, one step back
242});
243

TweaksSindre Sorhusbefore adoption698a1b8

line 244why, one step back
244test('Source already errored -> failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 245–250why, one step back
245 const source = execa('noop.js', [foobarString]);
246 const cause = new Error('test');247 source.stdout.destroy(cause);248 const destination = execa('stdin.js');249 const pipePromise = source.pipe(destination);250

TweaksSindre Sorhusbefore adoption698a1b8

lines 251–253why, one step back
251 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
252 assertLike(await assertRejects(source), {cause});253 assertLike(await destination, {stdout: ''});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 254–255why, one step back
254});
255

TweaksSindre Sorhusbefore adoption698a1b8

line 256why, one step back
256test('Destination already ended -> ignore source', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 257–262why, one step back
257 const destination = execa('stdin.js');
258 destination.stdin.end('.');259 await destination;260 const source = execa('noop.js', [foobarString]);261 const pipePromise = source.pipe(destination);262

TweaksSindre Sorhusbefore adoption698a1b8

lines 263–265why, one step back
263 assert.equal(await pipePromise, await destination);
264 assertLike(await destination, {stdout: '.'});265 assertLike(await source, {stdout: ''});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 266–267why, one step back
266});
267

TweaksSindre Sorhusbefore adoption698a1b8

line 268why, one step back
268test('Destination already aborted -> failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 269–270why, one step back
269 const destination = execa('stdin.js');
270 destination.stdin.destroy();

TweaksSindre Sorhusbefore adoption698a1b8

line 271why, one step back
271 assertLike(await assertRejects(destination), prematureClose);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 272–274why, one step back
272 const source = execa('noop.js', [foobarString]);
273 const pipePromise = source.pipe(destination);274

TweaksSindre Sorhusbefore adoption698a1b8

lines 275–276why, one step back
275 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
276 assertLike(await source, {stdout: ''});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 277–278why, one step back
277});
278

TweaksSindre Sorhusbefore adoption698a1b8

line 279why, one step back
279test('Destination already errored -> failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 280–282why, one step back
280 const destination = execa('stdin.js');
281 const cause = new Error('test');282 destination.stdin.destroy(cause);

TweaksSindre Sorhusbefore adoption698a1b8

line 283why, one step back
283 assertLike(await assertRejects(destination), {cause});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 284–286why, one step back
284 const source = execa('noop.js', [foobarString]);
285 const pipePromise = source.pipe(destination);286

TweaksSindre Sorhusbefore adoption698a1b8

lines 287–288why, one step back
287 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
288 assertLike(await source, {stdout: ''});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 289–290why, one step back
289});
290

TweaksSindre Sorhusbefore adoption698a1b8

line 291why, one step back
291test('Source normal failure + destination normal failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 292–295why, one step back
292 const source = execa('noop-fail.js', ['1', foobarString]);
293 const destination = execa('stdin-fail.js');294 const pipePromise = source.pipe(destination);295

TweaksSindre Sorhusbefore adoption698a1b8

lines 296–298why, one step back
296 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
297 assertLike(await assertRejects(source), {stdout: foobarString, exitCode: 2});298 assertLike(await assertRejects(destination), {stdout: foobarString, exitCode: 2});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 299–300why, one step back
299});
300

TweaksSindre Sorhusbefore adoption698a1b8

line 301why, one step back
301test('Simultaneous error on source and destination', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 302–306why, one step back
302 const source = execa('noop.js', ['']);
303 const destination = execa('stdin.js');304 const pipePromise = source.pipe(destination);305306 const sourceCause = new Error(foobarString);

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 307why, one step back
307 source.nodeChildProcess.emit('error', sourceCause);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 308why, one step back
308 const destinationCause = new Error('other');

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 309why, one step back
309 destination.nodeChildProcess.emit('error', destinationCause);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 310why, one step back
310

TweaksSindre Sorhusbefore adoption698a1b8

lines 311–313why, one step back
311 assert.equal(await assertRejects(pipePromise), await assertRejects(destination));
312 assertLike(await assertRejects(source), {cause: sourceCause});313 assertLike(await assertRejects(destination), {cause: destinationCause});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 314–315why, one step back
314});
315

TweaksSindre Sorhusbefore adoption698a1b8

line 316why, one step back
316test('Does not need to await individual promises', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 317–318why, one step back
317 const source = execa('fail.js');
318 const destination = execa('fail.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 319why, one step back
319 await assertRejects(source.pipe(destination));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 320–321why, one step back
320});
321

TweaksSindre Sorhusbefore adoption698a1b8

lines 322–323why, one step back
322test('Need to await .pipe() return value', async () => {
323 await assertUnhandledPipePromise();

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

lines 324–325why, one step back
324});
325

TweaksSindre Sorhusbefore adoption698a1b8

lines 326–327why, one step back
326test('Need to await .pipe() return value, "all" option', async () => {
327 await assertUnhandledPipePromise({destinationOptions: {all: true}});

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

lines 328–329why, one step back
328});
329

TweaksSindre Sorhusbefore adoption698a1b8

lines 330–331why, one step back
330test('Need to await .pipe() return value after inspecting lazy .all', async () => {
331 await assertUnhandledPipePromise({

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

lines 332–334why, one step back
332 destinationOptions: {all: true},
333 inspectPipePromise(pipePromise) {334 const descriptor = Object.getOwnPropertyDescriptor(pipePromise, 'all');

TweaksSindre Sorhusbefore adoption698a1b8

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

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

lines 336–339why, one step back
336 },
337 });338});339

TweaksSindre Sorhusbefore adoption698a1b8

line 340why, one step back
340test('Need to await .pipe() return value after getOneMessage()', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 341why, one step back
341 const source = execa('fail.js');

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

line 342why, one step back
342 const destination = execa('ipc-send-twice.js', {ipc: true});

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 343why, one step back
343 const pipePromise = source.pipe(destination);

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

line 344why, one step back
344

TweaksSindre Sorhusbefore adoption698a1b8

lines 345–347why, one step back
345 assert.equal(await pipePromise.getOneMessage(), 'foo');
346 await assertUnhandledRejection(pipePromise);347 await assertRejects(source);

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

line 348why, one step back
348 await destination;

TweaksSindre Sorhusbefore adoption698a1b8

line 349why, one step back
349 await assertRejects(pipePromise);

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

lines 350–351why, one step back
350});
351

TweaksSindre Sorhusbefore adoption698a1b8

line 352why, one step back
352test('Need to await .pipe() return value after paused getEachMessage()', async () => {

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

lines 353–357why, one step back
353 const source = execa('fail.js');
354 const destination = execa('ipc-send-twice.js', {ipc: true});355 const pipePromise = source.pipe(destination);356 const iterator = pipePromise.getEachMessage();357

TweaksSindre Sorhusbefore adoption698a1b8

lines 358–360why, one step back
358 assert.deepEqual(await iterator.next(), {done: false, value: 'foo'});
359 await assertUnhandledRejection(pipePromise);360 await assertRejects(source);

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

line 361why, one step back
361 await destination;

TweaksSindre Sorhusbefore adoption698a1b8

line 362why, one step back
362 await assertRejects(pipePromise);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 363–365why, one step back
363});
364365if (isLinux) {

TweaksSindre Sorhusbefore adoption698a1b8

line 366why, one step back
366 const testYesHead = async (useStdoutTransform, useStdinTransform, all) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 367–369why, one step back
367 const source = execa('yes', {stdout: useStdoutTransform ? noopGenerator(false) : 'pipe', all});
368 const destination = execa('head', ['-n', '1'], {stdin: useStdinTransform ? noopGenerator(false) : 'pipe'});369 const pipePromise = source.pipe(destination);

TweaksSindre Sorhusbefore adoption698a1b8

lines 370–374why, one step back
370 assert.equal(await assertRejects(pipePromise), await assertRejects(source));
371 assertLike(await destination, {stdout: 'y'});372 const sourceError = await assertRejects(source);373 assert.equal(sourceError.exitCode, 1);374 assert.match(sourceError.stderr, /^yes: standard output: (?:Broken pipe|Connection reset by peer)$/);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 375why, one step back
375

TweaksSindre Sorhusbefore adoption698a1b8

lines 376–381why, one step back
376 assert.equal(source.stdout.readableEnded, false);
377 assert.equal(source.stdout.errored, null);378 assert.equal(source.stdout.destroyed, true);379 assert.equal(source.stderr.readableEnded, true);380 assert.equal(source.stderr.errored, null);381 assert.equal(source.stderr.destroyed, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 382why, one step back
382

TweaksSindre Sorhusbefore adoption698a1b8

lines 383–384why, one step back
383 if (!all) {
384 return;

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 385why, one step back
385 }

TweaksSindre Sorhusbefore adoption698a1b8

lines 386–389why, one step back
386
387 assert.equal(source.all.readableEnded, true);388 assert.equal(source.all.errored, null);389 assert.equal(source.all.destroyed, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 390–391why, one step back
390 };
391

TweaksSindre Sorhusbefore adoption698a1b8

lines 392–399why, one step back
392 test('Works with yes | head', () => testYesHead(false, false, false));
393 test('Works with yes | head, input transform', () => testYesHead(false, true, false));394 test('Works with yes | head, output transform', () => testYesHead(true, false, false));395 test('Works with yes | head, input/output transform', () => testYesHead(true, true, false));396 test('Works with yes | head, "all" option', () => testYesHead(false, false, true));397 test('Works with yes | head, "all" option, input transform', () => testYesHead(false, true, true));398 test('Works with yes | head, "all" option, output transform', () => testYesHead(true, false, true));399 test('Works with yes | head, "all" option, input/output transform', () => testYesHead(true, true, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 400why, one step back
400}