Skip to content
Myr

output.js

This file

Path

test/return/output.js

110 lines · 4.2 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–2why, one step back
1import test from 'ava';
2import {execa, execaSync} from '../../index.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 3why, one step back
3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Split files (#837)ehmickybefore adoption672c2d7

line 4why, one step back
4import {fullStdio, getStdio} from '../helpers/stdio.js';

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

line 5why, one step back
5import {foobarString} from '../helpers/input.js';

Split files (#837)ehmickybefore adoption672c2d7

line 6why, one step back
6

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 7why, one step back
7setFixtureDirectory();

Split files (#837)ehmickybefore adoption672c2d7

line 8why, one step back
8

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

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

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

lines 10–11why, one step back
10 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], fullStdio);
11 t.is(stdio[fdNumber], foobarString);

Split files (#837)ehmickybefore adoption672c2d7

line 12why, one step back
12

Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40

lines 13–16why, one step back
13 if (fdNumber === 1) {
14 t.is(stdio[fdNumber], stdout);15 } else if (fdNumber === 2) {16 t.is(stdio[fdNumber], stderr);

Split files (#837)ehmickybefore adoption672c2d7

lines 17–22why, one step back
17 }
18};1920test('can return stdout', testOutput, 1, execa);21test('can return stderr', testOutput, 2, execa);22test('can return output stdio[*]', testOutput, 3, execa);

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

lines 23–25why, one step back
23test('can return stdout, sync', testOutput, 1, execaSync);
24test('can return stderr, sync', testOutput, 2, execaSync);25test('can return output stdio[*], sync', testOutput, 3, execaSync);

Split files (#837)ehmickybefore adoption672c2d7

lines 26–27why, one step back
26
27const testNoStdin = async (t, execaMethod) => {

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

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

Split files (#837)ehmickybefore adoption672c2d7

lines 29–32why, one step back
29 t.is(stdio[0], undefined);
30};3132test('cannot return stdin', testNoStdin, execa);

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

line 33why, one step back
33test('cannot return stdin, sync', testNoStdin, execaSync);

Split files (#837)ehmickybefore adoption672c2d7

lines 34–35why, one step back
34
35test('cannot return input stdio[*]', async t => {

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

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

Split files (#837)ehmickybefore adoption672c2d7

lines 37–56why, one step back
37 t.is(stdio[3], undefined);
38});3940test('do not try to consume streams twice', async t => {41 const subprocess = execa('noop.js', ['foo']);42 const {stdout} = await subprocess;43 const {stdout: stdout2} = await subprocess;44 t.is(stdout, 'foo');45 t.is(stdout2, 'foo');46});4748const testEmptyErrorStdio = async (t, execaMethod) => {49 const {failed, stdout, stderr, stdio} = await execaMethod('fail.js', {reject: false});50 t.true(failed);51 t.is(stdout, '');52 t.is(stderr, '');53 t.deepEqual(stdio, [undefined, '', '']);54};5556test('empty error.stdout/stderr/stdio', testEmptyErrorStdio, execa);

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

line 57why, one step back
57test('empty error.stdout/stderr/stdio, sync', testEmptyErrorStdio, execaSync);

Split files (#837)ehmickybefore adoption672c2d7

lines 58–66why, one step back
58
59const testUndefinedErrorStdio = async (t, execaMethod) => {60 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});61 t.is(stdout, undefined);62 t.is(stderr, undefined);63 t.deepEqual(stdio, [undefined, undefined, undefined]);64};6566test('undefined error.stdout/stderr/stdio', testUndefinedErrorStdio, execa);

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

line 67why, one step back
67test('undefined error.stdout/stderr/stdio, sync', testUndefinedErrorStdio, execaSync);

Split files (#837)ehmickybefore adoption672c2d7

line 68why, one step back
68

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

lines 69–70why, one step back
69const testEmptyAll = async (t, options, expectedValue, execaMethod) => {
70 const {all} = await execaMethod('empty.js', options);

Split files (#837)ehmickybefore adoption672c2d7

lines 71–73why, one step back
71 t.is(all, expectedValue);
72};73

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

lines 74–79why, one step back
74test('empty error.all', testEmptyAll, {all: true}, '', execa);
75test('undefined error.all', testEmptyAll, {}, undefined, execa);76test('ignored error.all', testEmptyAll, {all: true, stdio: 'ignore'}, undefined, execa);77test('empty error.all, sync', testEmptyAll, {all: true}, '', execaSync);78test('undefined error.all, sync', testEmptyAll, {}, undefined, execaSync);79test('ignored error.all, sync', testEmptyAll, {all: true, stdio: 'ignore'}, undefined, execaSync);

Split files (#837)ehmickybefore adoption672c2d7

lines 80–88why, one step back
80
81test('empty error.stdio[0] even with input', async t => {82 const {stdio} = await t.throwsAsync(execa('fail.js', {input: 'test'}));83 t.is(stdio[0], undefined);84});8586// `error.code` is OS-specific here87const SPAWN_ERROR_CODES = new Set(['EINVAL', 'ENOTSUP', 'EPERM']);88

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

lines 89–90why, one step back
89const testSpawnError = async (t, execaMethod) => {
90 const {code, stdout, stderr, stdio, all} = await execaMethod('empty.js', {uid: -1, all: true, reject: false});

Split files (#837)ehmickybefore adoption672c2d7

lines 91–93why, one step back
91 t.true(SPAWN_ERROR_CODES.has(code));
92 t.is(stdout, undefined);93 t.is(stderr, undefined);

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

line 94why, one step back
94 t.is(all, undefined);

Split files (#837)ehmickybefore adoption672c2d7

line 95why, one step back
95 t.deepEqual(stdio, [undefined, undefined, undefined]);

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

line 96why, one step back
96};

Split files (#837)ehmickybefore adoption672c2d7

line 97why, one step back
97

Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4

line 98why, one step back
98test('stdout/stderr/all/stdio on subprocess spawning errors', testSpawnError, execa);

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

line 99why, one step back
99test('stdout/stderr/all/stdio on subprocess spawning errors, sync', testSpawnError, execaSync);

Split files (#837)ehmickybefore adoption672c2d7

lines 100–109why, one step back
100
101const testErrorOutput = async (t, execaMethod) => {102 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});103 t.true(failed);104 t.is(stdout, 'stdout');105 t.is(stderr, 'stderr');106 t.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);107};108109test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)ehmickybefore adoption64d52db

line 110why, one step back
110test('error.stdout/stderr/stdio is defined, sync', testErrorOutput, execaSync);