Skip to content
Myr

output.js

This file

Path

test/return/output.js

138 lines · 5.4 KiB · JavaScript

Last changed by

Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff

History of this file

Take it

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';3import {assertThrows, assertRejects, assertLike} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–7why, one step back
4import {execa, execaSync} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';7import {foobarString} from '../helpers/input.js';

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 8–13why, one step back
8import {
9 getEarlyErrorSubprocess,10 getEarlyErrorSubprocessSync,11 expectedEarlyError,12 expectedEarlyErrorSync,13} from '../helpers/early-error.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 14–16why, one step back
14
15setFixtureDirectory();16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17const testOutput = async (fdNumber, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], fullStdio);

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19 assert.equal(stdio[fdNumber], foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 20–21why, one step back
20
21 if (fdNumber === 1) {

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22 assert.equal(stdio[fdNumber], stdout);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 23why, one step back
23 } else if (fdNumber === 2) {

TweaksSindre Sorhusbefore adoption698a1b8

line 24why, one step back
24 assert.equal(stdio[fdNumber], stderr);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 25–27why, one step back
25 }
26};27

TweaksSindre Sorhusbefore adoption698a1b8

lines 28–33why, one step back
28test('can return stdout', () => testOutput(1, execa));
29test('can return stderr', () => testOutput(2, execa));30test('can return output stdio[*]', () => testOutput(3, execa));31test('can return stdout, sync', () => testOutput(1, execaSync));32test('can return stderr, sync', () => testOutput(2, execaSync));33test('can return output stdio[*], sync', () => testOutput(3, execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 34why, one step back
34

TweaksSindre Sorhusbefore adoption698a1b8

line 35why, one step back
35const testNoStdin = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 36why, one step back
36 const {stdio} = await execaMethod('noop.js', [foobarString]);

TweaksSindre Sorhusbefore adoption698a1b8

line 37why, one step back
37 assert.equal(stdio[0], undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 38–39why, one step back
38};
39

TweaksSindre Sorhusbefore adoption698a1b8

lines 40–41why, one step back
40test('cannot return stdin', () => testNoStdin(execa));
41test('cannot return stdin, sync', () => testNoStdin(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 42why, one step back
42

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43test('cannot return input stdio[*]', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 44why, one step back
44 const {stdio} = await execa('stdin-fd.js', ['3'], getStdio(3, [[foobarString]]));

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45 assert.equal(stdio[3], undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 46–47why, one step back
46});
47

TweaksSindre Sorhusbefore adoption698a1b8

line 48why, one step back
48test('do not try to consume streams twice', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 49–51why, one step back
49 const subprocess = execa('noop.js', ['foo']);
50 const {stdout} = await subprocess;51 const {stdout: stdout2} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 52–53why, one step back
52 assert.equal(stdout, 'foo');
53 assert.equal(stdout2, 'foo');

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 56why, one step back
56const testEmptyErrorStdio = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 57why, one step back
57 const {failed, stdout, stderr, stdio} = await execaMethod('fail.js', {reject: false});

TweaksSindre Sorhusbefore adoption698a1b8

lines 58–61why, one step back
58 assert.equal(failed, true);
59 assert.equal(stdout, '');60 assert.equal(stderr, '');61 assert.deepEqual(stdio, [undefined, '', '']);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 62–63why, one step back
62};
63

TweaksSindre Sorhusbefore adoption698a1b8

lines 64–65why, one step back
64test('empty error.stdout/stderr/stdio', () => testEmptyErrorStdio(execa));
65test('empty error.stdout/stderr/stdio, sync', () => testEmptyErrorStdio(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 66why, one step back
66

TweaksSindre Sorhusbefore adoption698a1b8

line 67why, one step back
67const testUndefinedErrorStdio = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 68why, one step back
68 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});

TweaksSindre Sorhusbefore adoption698a1b8

lines 69–71why, one step back
69 assert.equal(stdout, undefined);
70 assert.equal(stderr, undefined);71 assert.deepEqual(stdio, [undefined, undefined, undefined]);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 72–73why, one step back
72};
73

TweaksSindre Sorhusbefore adoption698a1b8

lines 74–75why, one step back
74test('undefined error.stdout/stderr/stdio', () => testUndefinedErrorStdio(execa));
75test('undefined error.stdout/stderr/stdio, sync', () => testUndefinedErrorStdio(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 76why, one step back
76

TweaksSindre Sorhusbefore adoption698a1b8

line 77why, one step back
77const testEmptyAll = async (options, expectedValue, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 78why, one step back
78 const {all} = await execaMethod('empty.js', options);

TweaksSindre Sorhusbefore adoption698a1b8

line 79why, one step back
79 assert.equal(all, expectedValue);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 80–81why, one step back
80};
81

TweaksSindre Sorhusbefore adoption698a1b8

lines 82–87why, one step back
82test('empty error.all', () => testEmptyAll({all: true}, '', execa));
83test('undefined error.all', () => testEmptyAll({}, undefined, execa));84test('ignored error.all', () => testEmptyAll({all: true, stdio: 'ignore'}, undefined, execa));85test('empty error.all, sync', () => testEmptyAll({all: true}, '', execaSync));86test('undefined error.all, sync', () => testEmptyAll({}, undefined, execaSync));87test('ignored error.all, sync', () => testEmptyAll({all: true, stdio: 'ignore'}, undefined, execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 88why, one step back
88

TweaksSindre Sorhusbefore adoption698a1b8

lines 89–91why, one step back
89test('empty error.stdio[0] even with input', async () => {
90 const {stdio} = await assertRejects(execa('fail.js', {input: 'test'}));91 assert.equal(stdio[0], undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 92–93why, one step back
92});
93

Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff

line 94why, one step back
94// The subprocess never spawned, so its output is empty

TweaksSindre Sorhusbefore adoption698a1b8

line 95why, one step back
95const validateSpawnErrorStdio = ({stdout, stderr, stdio, all}) => {

Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff

lines 96–99why, one step back
96 assert.equal(stdout, '');
97 assert.equal(stderr, '');98 assert.equal(all, '');99 assert.deepEqual(stdio, [undefined, '', '']);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 100–101why, one step back
100};
101

TweaksSindre Sorhusbefore adoption698a1b8

lines 102–105why, one step back
102test('stdout/stderr/all/stdio on subprocess spawning errors', async () => {
103 const error = await assertRejects(getEarlyErrorSubprocess({all: true}));104 assertLike(error, expectedEarlyError);105 validateSpawnErrorStdio(error);

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 106why, one step back
106});

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 107why, one step back
107

TweaksSindre Sorhusbefore adoption698a1b8

lines 108–111why, one step back
108test('stdout/stderr/all/stdio on subprocess spawning errors, sync', () => {
109 const error = assertThrows(() => getEarlyErrorSubprocessSync({all: true}));110 assertLike(error, expectedEarlyErrorSync);111 validateSpawnErrorStdio(error);

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

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

TweaksSindre Sorhusbefore adoption698a1b8

line 114why, one step back
114const testErrorOutput = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 115why, one step back
115 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});

TweaksSindre Sorhusbefore adoption698a1b8

lines 116–119why, one step back
116 assert.equal(failed, true);
117 assert.equal(stdout, 'stdout');118 assert.equal(stderr, 'stderr');119 assert.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 120–121why, one step back
120};
121

TweaksSindre Sorhusbefore adoption698a1b8

lines 122–123why, one step back
122test('error.stdout/stderr/stdio is defined', () => testErrorOutput(execa));
123test('error.stdout/stderr/stdio is defined, sync', () => testErrorOutput(execaSync));

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 124why, one step back
124

TweaksSindre Sorhusbefore adoption698a1b8

lines 125–128why, one step back
125test('ipc on subprocess spawning errors', async () => {
126 const error = await assertRejects(getEarlyErrorSubprocess({ipc: true}));127 assertLike(error, expectedEarlyError);128 assert.deepEqual(error.ipcOutput, []);

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 129–130why, one step back
129});
130

TweaksSindre Sorhusbefore adoption698a1b8

lines 131–134why, one step back
131const testEarlyErrorNoIpc = async options => {
132 const error = await assertRejects(getEarlyErrorSubprocess(options));133 assertLike(error, expectedEarlyError);134 assert.deepEqual(error.ipcOutput, []);

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 135–136why, one step back
135};
136

TweaksSindre Sorhusbefore adoption698a1b8

lines 137–138why, one step back
137test('ipc on subprocess spawning errors, ipc false', () => testEarlyErrorNoIpc({ipc: false}));
138test('ipc on subprocess spawning errors, buffer false', () => testEarlyErrorNoIpc({buffer: false}));