Skip to content
Myr

throw.js

This file

Path

test/pipe/throw.js

74 lines · 2.8 KiB · JavaScript

Last changed by

Report `null` pipe options as a rejectionSindre Sorhusbefore adoptionecda56b

History of this file

Take it

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–2why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 3–6why, one step back
3import {execa} from '../../index.js';
4import {foobarString} from '../helpers/input.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {assertPipeError} from '../helpers/pipe.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 7why, one step back
7import {assertLike} from '../helpers/assert.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 8–10why, one step back
8
9setFixtureDirectory();10

TweaksSindre Sorhusbefore adoption698a1b8

line 11why, one step back
11test('Destination stream is ended when first argument is invalid', async () => {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 12–15why, one step back
12 const source = execa('empty.js', {stdout: 'ignore'});
13 const destination = execa('stdin.js');14 const pipePromise = source.pipe(destination);15

TweaksSindre Sorhusbefore adoption698a1b8

line 16why, one step back
16 await assertPipeError(pipePromise, 'option is incompatible');

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 17why, one step back
17 await source;

TweaksSindre Sorhusbefore adoption698a1b8

line 18why, one step back
18 assertLike(await destination, {stdout: ''});

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 19–20why, one step back
19});
20

TweaksSindre Sorhusbefore adoption698a1b8

line 21why, one step back
21test('Destination stream is ended when first argument is invalid - $', async () => {

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 22why, one step back
22 const pipePromise = execa('empty.js', {stdout: 'ignore'}).pipe`stdin.js`;

TweaksSindre Sorhusbefore adoption698a1b8

line 23why, one step back
23 await assertPipeError(pipePromise, 'option is incompatible');

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 24–25why, one step back
24});
25

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26test('Source stream is aborted when second argument is invalid', async () => {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 27–29why, one step back
27 const source = execa('noop.js', [foobarString]);
28 const pipePromise = source.pipe(false);29

TweaksSindre Sorhusbefore adoption698a1b8

lines 30–31why, one step back
30 await assertPipeError(pipePromise, 'an Execa subprocess');
31 assertLike(await source, {stdout: ''});

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 32–33why, one step back
32});
33

TweaksSindre Sorhusbefore adoption698a1b8

line 34why, one step back
34test('Both arguments might be invalid', async () => {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 35–37why, one step back
35 const source = execa('empty.js', {stdout: 'ignore'});
36 const pipePromise = source.pipe(false);37

TweaksSindre Sorhusbefore adoption698a1b8

lines 38–40why, one step back
38 await assertPipeError(pipePromise, 'an Execa subprocess');
39 const {stdout} = await source;40 assert.equal(stdout, undefined);

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 41why, one step back
41});

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

lines 42–44why, one step back
42
43// The destination subprocess is spawned before the `to` option is validated, so its error must be handled.44// This runs in another process, since that is where the unhandled rejection crashes it.

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45test('Destination subprocess error is not unhandled when the "to" option is invalid', async () => {

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

line 46why, one step back
46 const {stdout} = await execa('pipe-destination-error.js', ['fail.js']);

TweaksSindre Sorhusbefore adoption698a1b8

line 47why, one step back
47 assert.equal(stdout, 'REACHED THE END');

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

lines 48–49why, one step back
48});
49

TweaksSindre Sorhusbefore adoption698a1b8

line 50why, one step back
50test('Destination subprocess is terminated when the "to" option is invalid', async () => {

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

line 51why, one step back
51 const {stdout} = await execa('pipe-destination-error.js', ['stdin.js'], {timeout: 10_000});

TweaksSindre Sorhusbefore adoption698a1b8

line 52why, one step back
52 assert.equal(stdout, 'REACHED THE END');

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

lines 53–54why, one step back
53});
54

TweaksSindre Sorhusbefore adoption698a1b8

line 55why, one step back
55test('Destination subprocess passed by the user is not terminated when the "to" option is invalid', async () => {

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

lines 56–59why, one step back
56 const source = execa('empty.js', {stdout: 'ignore'});
57 const destination = execa('stdin.js');58 const pipePromise = source.pipe(destination, {to: 'fd9'});59

TweaksSindre Sorhusbefore adoption698a1b8

line 60why, one step back
60 await assertPipeError(pipePromise, 'fd9');

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

lines 61–62why, one step back
61 destination.stdin.end(foobarString);
62 const {stdout} = await destination;

TweaksSindre Sorhusbefore adoption698a1b8

line 63why, one step back
63 assert.equal(stdout, foobarString);

Fix `.pipe()` with the `stdio` option and orphaned destination subprocessesSindre Sorhusbefore adoption8d3f0a9

line 64why, one step back
64});

Report `null` pipe options as a rejectionSindre Sorhusbefore adoptionecda56b

lines 65–74why, one step back
65
66test('The pipe options cannot be null', async () => {67 const source = execa('empty.js');68 const destination = execa('stdin.js');69 const pipePromise = source.pipe(destination, null);7071 await assertPipeError(pipePromise, 'not `null`');72 destination.stdin.end();73 await Promise.all([source, destination]);74});