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 fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import 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 back4import {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 back8import {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 back1415setFixtureDirectory();16TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17const testOutput = async (fdNumber, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 18why, one step back18 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], fullStdio);TweaksSindre Sorhusbefore adoption698a1b8
line 19why, one step back19 assert.equal(stdio[fdNumber], foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 20–21why, one step back2021 if (fdNumber === 1) {TweaksSindre Sorhusbefore adoption698a1b8
line 22why, one step back22 assert.equal(stdio[fdNumber], stdout);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 23why, one step back23 } else if (fdNumber === 2) {TweaksSindre Sorhusbefore adoption698a1b8
line 24why, one step back24 assert.equal(stdio[fdNumber], stderr);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 25–27why, one step back25 }26};27TweaksSindre Sorhusbefore adoption698a1b8
lines 28–33why, one step back28test('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 back34TweaksSindre Sorhusbefore adoption698a1b8
line 35why, one step back35const testNoStdin = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 36why, one step back36 const {stdio} = await execaMethod('noop.js', [foobarString]);TweaksSindre Sorhusbefore adoption698a1b8
line 37why, one step back37 assert.equal(stdio[0], undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 38–39why, one step back38};39TweaksSindre Sorhusbefore adoption698a1b8
lines 40–41why, one step back40test('cannot return stdin', () => testNoStdin(execa));41test('cannot return stdin, sync', () => testNoStdin(execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 42why, one step back42TweaksSindre Sorhusbefore adoption698a1b8
line 43why, one step back43test('cannot return input stdio[*]', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 44why, one step back44 const {stdio} = await execa('stdin-fd.js', ['3'], getStdio(3, [[foobarString]]));TweaksSindre Sorhusbefore adoption698a1b8
line 45why, one step back45 assert.equal(stdio[3], undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 46–47why, one step back46});47TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48test('do not try to consume streams twice', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 49–51why, one step back49 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 back52 assert.equal(stdout, 'foo');53 assert.equal(stdout2, 'foo');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 54–55why, one step back54});55TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56const testEmptyErrorStdio = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 57why, one step back57 const {failed, stdout, stderr, stdio} = await execaMethod('fail.js', {reject: false});TweaksSindre Sorhusbefore adoption698a1b8
lines 58–61why, one step back58 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 back62};63TweaksSindre Sorhusbefore adoption698a1b8
lines 64–65why, one step back64test('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 back66TweaksSindre Sorhusbefore adoption698a1b8
line 67why, one step back67const testUndefinedErrorStdio = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 68why, one step back68 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});TweaksSindre Sorhusbefore adoption698a1b8
lines 69–71why, one step back69 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 back72};73TweaksSindre Sorhusbefore adoption698a1b8
lines 74–75why, one step back74test('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 back76TweaksSindre Sorhusbefore adoption698a1b8
line 77why, one step back77const testEmptyAll = async (options, expectedValue, execaMethod) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 78why, one step back78 const {all} = await execaMethod('empty.js', options);TweaksSindre Sorhusbefore adoption698a1b8
line 79why, one step back79 assert.equal(all, expectedValue);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 80–81why, one step back80};81TweaksSindre Sorhusbefore adoption698a1b8
lines 82–87why, one step back82test('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 back88TweaksSindre Sorhusbefore adoption698a1b8
lines 89–91why, one step back89test('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 back92});93Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff
line 94why, one step back94// The subprocess never spawned, so its output is emptyTweaksSindre Sorhusbefore adoption698a1b8
line 95why, one step back95const validateSpawnErrorStdio = ({stdout, stderr, stdio, all}) => {Fix errors, early errors and `result.all` edge casesSindre Sorhusbefore adoptionc4262ff
lines 96–99why, one step back96 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 back100};101TweaksSindre Sorhusbefore adoption698a1b8
lines 102–105why, one step back102test('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 back106});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 107why, one step back107TweaksSindre Sorhusbefore adoption698a1b8
lines 108–111why, one step back108test('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 back112});113TweaksSindre Sorhusbefore adoption698a1b8
line 114why, one step back114const testErrorOutput = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 115why, one step back115 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});TweaksSindre Sorhusbefore adoption698a1b8
lines 116–119why, one step back116 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 back120};121TweaksSindre Sorhusbefore adoption698a1b8
lines 122–123why, one step back122test('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 back124TweaksSindre Sorhusbefore adoption698a1b8
lines 125–128why, one step back125test('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 back129});130TweaksSindre Sorhusbefore adoption698a1b8
lines 131–134why, one step back131const 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 back135};136TweaksSindre Sorhusbefore adoption698a1b8
lines 137–138why, one step back137test('ipc on subprocess spawning errors, ipc false', () => testEarlyErrorNoIpc({ipc: false}));138test('ipc on subprocess spawning errors, buffer false', () => testEarlyErrorNoIpc({buffer: false}));