Skip to content
Myr

native-fd.js

This file

Path

test/stdio/native-fd.js

76 lines · 3.6 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 1–4why, one step back
1import {platform} from 'node:process';
2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {getStdio, fullStdio} from '../helpers/stdio.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

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

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 6–8why, one step back
6import {foobarString} from '../helpers/input.js';
7import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';8

Upgrade xo (#980)ehmickybefore adoptionccfa412

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

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 10–76why, one step back
10
11const isLinux = platform === 'linux';12const isWindows = platform === 'win32';1314const testFd3InheritOutput = async (t, stdioOption, execaMethod) => {15 const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio);16 t.is(stdio[3], foobarString);17};1819test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);20test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);21test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);22test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);2324if (isLinux) {25 const testOverflowStream = async (t, fdNumber, stdioOption, execaMethod) => {26 const {stdout} = await execaMethod('empty.js', getStdio(fdNumber, stdioOption), fullStdio);27 t.is(stdout, '');28 };2930 test('stdin can use 4+', testOverflowStream, 0, 4, parentExecaAsync);31 test('stdin can use [4+]', testOverflowStream, 0, [4], parentExecaAsync);32 test('stdout can use 4+', testOverflowStream, 1, 4, parentExecaAsync);33 test('stdout can use [4+]', testOverflowStream, 1, [4], parentExecaAsync);34 test('stderr can use 4+', testOverflowStream, 2, 4, parentExecaAsync);35 test('stderr can use [4+]', testOverflowStream, 2, [4], parentExecaAsync);36 test('stdio[*] can use 4+', testOverflowStream, 3, 4, parentExecaAsync);37 test('stdio[*] can use [4+]', testOverflowStream, 3, [4], parentExecaAsync);38 test('stdin can use 4+, sync', testOverflowStream, 0, 4, parentExecaSync);39 test('stdin can use [4+], sync', testOverflowStream, 0, [4], parentExecaSync);40 test('stdout can use 4+, sync', testOverflowStream, 1, 4, parentExecaSync);41 test('stdout can use [4+], sync', testOverflowStream, 1, [4], parentExecaSync);42 test('stderr can use 4+, sync', testOverflowStream, 2, 4, parentExecaSync);43 test('stderr can use [4+], sync', testOverflowStream, 2, [4], parentExecaSync);44 test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, parentExecaSync);45 test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], parentExecaSync);46}4748const testOverflowStreamArray = (t, fdNumber, stdioOption) => {49 t.throws(() => {50 execa('empty.js', getStdio(fdNumber, stdioOption));51 }, {message: /no such standard stream/});52};5354test('stdin cannot use 4+ and another value', testOverflowStreamArray, 0, [4, 'pipe']);55test('stdout cannot use 4+ and another value', testOverflowStreamArray, 1, [4, 'pipe']);56test('stderr cannot use 4+ and another value', testOverflowStreamArray, 2, [4, 'pipe']);57test('stdio[*] cannot use 4+ and another value', testOverflowStreamArray, 3, [4, 'pipe']);58test('stdio[*] cannot use "inherit" and another value', testOverflowStreamArray, 3, ['inherit', 'pipe']);5960const getInvalidFdCode = () => {61 if (isLinux) {62 return 'EINVAL';63 }6465 return isWindows ? 'EBADF' : 'ENXIO';66};6768const testOverflowStreamArraySync = (t, fdNumber) => {69 t.throws(() => {70 execaSync('noop-fd.js', [fdNumber, foobarString], getStdio(fdNumber, [4, 'pipe']));71 }, {code: getInvalidFdCode()});72};7374test('stdout cannot use 4+ and another value, sync', testOverflowStreamArraySync, 1);75test('stderr cannot use 4+ and another value, sync', testOverflowStreamArraySync, 2);76test('stdio[*] cannot use 4+ and another value, sync', testOverflowStreamArraySync, 3);