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 fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import {platform} from 'node:process';import test from 'ava';import {execa, execaSync} from '../../index.js';import {getStdio, fullStdio} from '../helpers/stdio.js';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';import {foobarString} from '../helpers/input.js';import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';
setFixtureDirectory();
const isLinux = platform === 'linux';const isWindows = platform === 'win32';
const testFd3InheritOutput = async (t, stdioOption, execaMethod) => { const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio); t.is(stdio[3], foobarString);};
test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);
if (isLinux) { const testOverflowStream = async (t, fdNumber, stdioOption, execaMethod) => { const {stdout} = await execaMethod('empty.js', getStdio(fdNumber, stdioOption), fullStdio); t.is(stdout, ''); };
test('stdin can use 4+', testOverflowStream, 0, 4, parentExecaAsync); test('stdin can use [4+]', testOverflowStream, 0, [4], parentExecaAsync); test('stdout can use 4+', testOverflowStream, 1, 4, parentExecaAsync); test('stdout can use [4+]', testOverflowStream, 1, [4], parentExecaAsync); test('stderr can use 4+', testOverflowStream, 2, 4, parentExecaAsync); test('stderr can use [4+]', testOverflowStream, 2, [4], parentExecaAsync); test('stdio[*] can use 4+', testOverflowStream, 3, 4, parentExecaAsync); test('stdio[*] can use [4+]', testOverflowStream, 3, [4], parentExecaAsync); test('stdin can use 4+, sync', testOverflowStream, 0, 4, parentExecaSync); test('stdin can use [4+], sync', testOverflowStream, 0, [4], parentExecaSync); test('stdout can use 4+, sync', testOverflowStream, 1, 4, parentExecaSync); test('stdout can use [4+], sync', testOverflowStream, 1, [4], parentExecaSync); test('stderr can use 4+, sync', testOverflowStream, 2, 4, parentExecaSync); test('stderr can use [4+], sync', testOverflowStream, 2, [4], parentExecaSync); test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, parentExecaSync); test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], parentExecaSync);}
const testOverflowStreamArray = (t, fdNumber, stdioOption) => { t.throws(() => { execa('empty.js', getStdio(fdNumber, stdioOption)); }, {message: /no such standard stream/});};
test('stdin cannot use 4+ and another value', testOverflowStreamArray, 0, [4, 'pipe']);test('stdout cannot use 4+ and another value', testOverflowStreamArray, 1, [4, 'pipe']);test('stderr cannot use 4+ and another value', testOverflowStreamArray, 2, [4, 'pipe']);test('stdio[*] cannot use 4+ and another value', testOverflowStreamArray, 3, [4, 'pipe']);test('stdio[*] cannot use "inherit" and another value', testOverflowStreamArray, 3, ['inherit', 'pipe']);
const getInvalidFdCode = () => { if (isLinux) { return 'EINVAL'; }
return isWindows ? 'EBADF' : 'ENXIO';};
const testOverflowStreamArraySync = (t, fdNumber) => { t.throws(() => { execaSync('noop-fd.js', [fdNumber, foobarString], getStdio(fdNumber, [4, 'pipe'])); }, {code: getInvalidFdCode()});};
test('stdout cannot use 4+ and another value, sync', testOverflowStreamArraySync, 1);test('stderr cannot use 4+ and another value, sync', testOverflowStreamArraySync, 2);test('stdio[*] cannot use 4+ and another value, sync', testOverflowStreamArraySync, 3);