output.js
This file
Path
test/return/output.js
139 lines · 6.3 KiB · JavaScript
Last changed by
Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–8why, one step back1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {fullStdio, getStdio} from '../helpers/stdio.js';5import {noopGenerator} from '../helpers/generator.js';67setFixtureDir();8Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 9–11why, one step back9const testOutput = async (t, fdNumber, execaMethod) => {10 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], fullStdio);11 t.is(stdio[fdNumber], 'foobar');Split files (#837)ehmickybefore adoption672c2d7
line 12why, one step back12Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 13–16why, one step back13 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–68why, one step back17 }18};1920test('can return stdout', testOutput, 1, execa);21test('can return stderr', testOutput, 2, execa);22test('can return output stdio[*]', testOutput, 3, execa);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);2627const testNoStdin = async (t, execaMethod) => {28 const {stdio} = await execaMethod('noop.js', ['foobar']);29 t.is(stdio[0], undefined);30};3132test('cannot return stdin', testNoStdin, execa);33test('cannot return stdin - sync', testNoStdin, execaSync);3435test('cannot return input stdio[*]', async t => {36 const {stdio} = await execa('stdin-fd.js', ['3'], getStdio(3, [['foobar']]));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);57test('empty error.stdout/stderr/stdio - sync', testEmptyErrorStdio, execaSync);5859const 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);67test('undefined error.stdout/stderr/stdio - sync', testUndefinedErrorStdio, execaSync);68Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4
lines 69–70why, one step back69const testEmptyAll = async (t, options, expectedValue, execaMethod) => {70 const {all} = await execaMethod('empty.js', options);Split files (#837)ehmickybefore adoption672c2d7
lines 71–73why, one step back71 t.is(all, expectedValue);72};73Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4
lines 74–79why, one step back74test('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 back8081test('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']);88Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4
lines 89–90why, one step back89const 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 back91 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 back94 t.is(all, undefined);Split files (#837)ehmickybefore adoption672c2d7
line 95why, one step back95 t.deepEqual(stdio, [undefined, undefined, undefined]);Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4
line 96why, one step back96};Split files (#837)ehmickybefore adoption672c2d7
line 97why, one step back97Add support for `all` option to `execaSync()` (#956)ehmickybefore adoption63b5ac4
lines 98–99why, one step back98test('stdout/stderr/all/stdio on subprocess spawning errors', testSpawnError, execa);99test('stdout/stderr/all/stdio on subprocess spawning errors - sync', testSpawnError, execaSync);Split files (#837)ehmickybefore adoption672c2d7
lines 100–111why, one step back100101const 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);110test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);111Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
lines 112–114why, one step back112const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, execaMethod) => {113 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar\n'], {...fullStdio, stripFinalNewline});114 t.is(stdio[fdNumber], `foobar${stripFinalNewline === false ? '\n' : ''}`);Split files (#837)ehmickybefore adoption672c2d7
lines 115–136why, one step back115};116117test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);118test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);119test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, execa);120test('stripFinalNewline: undefined with stderr', testStripFinalNewline, 2, undefined, execa);121test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, execa);122test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, execa);123test('stripFinalNewline: undefined with stdio[*]', testStripFinalNewline, 3, undefined, execa);124test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, execa);125test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, execa);126test('stripFinalNewline: undefined with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);127test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, true, execaSync);128test('stripFinalNewline: false with stdout - sync', testStripFinalNewline, 1, false, execaSync);129test('stripFinalNewline: undefined with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);130test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, true, execaSync);131test('stripFinalNewline: false with stderr - sync', testStripFinalNewline, 2, false, execaSync);132test('stripFinalNewline: undefined with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);133test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, true, execaSync);134test('stripFinalNewline: false with stdio[*] - sync', testStripFinalNewline, 3, false, execaSync);135136test('stripFinalNewline is not used in objectMode', async t => {Prevent handling binary data like text data (#924)ehmickybefore adoptionaf3aefd
line 137why, one step back137 const {stdout} = await execa('noop-fd.js', ['1', 'foobar\n'], {stripFinalNewline: true, stdout: noopGenerator(true, false, true)});Split files (#837)ehmickybefore adoption672c2d7
lines 138–139why, one step back138 t.deepEqual(stdout, ['foobar\n']);139});