native-fd.js
This file
Path
test/stdio/native-fd.js
86 lines · 4.7 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {platform} from 'node:process';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–4why, one step back3import test from 'node:test';4import {assertThrows} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–8why, one step back5import {execa, execaSync} from '../../index.js';6import {getStdio, fullStdio} from '../helpers/stdio.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {foobarString} from '../helpers/input.js';Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 9why, one step back9import {nestedSubprocess} from '../helpers/nested.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 10–14why, one step back1011setFixtureDirectory();1213const isLinux = platform === 'linux';14TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15const testFd3InheritOutput = async (stdioOption, isSync) => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 16why, one step back16 const {stdio} = await nestedSubprocess('noop-fd.js', ['3', foobarString], {...getStdio(3, stdioOption), isSync}, fullStdio);TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17 assert.equal(stdio[3], foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 18–19why, one step back18};19TweaksSindre Sorhusbefore adoption698a1b8
lines 20–23why, one step back20test('stdio[*] output can use "inherit"', () => testFd3InheritOutput('inherit', false));21test('stdio[*] output can use ["inherit"]', () => testFd3InheritOutput(['inherit'], false));22test('stdio[*] output can use "inherit", sync', () => testFd3InheritOutput('inherit', true));23test('stdio[*] output can use ["inherit"], sync', () => testFd3InheritOutput(['inherit'], true));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 24–25why, one step back2425if (isLinux) {TweaksSindre Sorhusbefore adoption698a1b8
line 26why, one step back26 const testOverflowStream = async (fdNumber, stdioOption, isSync) => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 27why, one step back27 const {stdout} = await nestedSubprocess('empty.js', {...getStdio(fdNumber, stdioOption), isSync}, fullStdio);TweaksSindre Sorhusbefore adoption698a1b8
line 28why, one step back28 assert.equal(stdout, '');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 29–30why, one step back29 };30TweaksSindre Sorhusbefore adoption698a1b8
lines 31–46why, one step back31 test('stdin can use 4+', () => testOverflowStream(0, 4, false));32 test('stdin can use [4+]', () => testOverflowStream(0, [4], false));33 test('stdout can use 4+', () => testOverflowStream(1, 4, false));34 test('stdout can use [4+]', () => testOverflowStream(1, [4], false));35 test('stderr can use 4+', () => testOverflowStream(2, 4, false));36 test('stderr can use [4+]', () => testOverflowStream(2, [4], false));37 test('stdio[*] can use 4+', () => testOverflowStream(3, 4, false));38 test('stdio[*] can use [4+]', () => testOverflowStream(3, [4], false));39 test('stdin can use 4+, sync', () => testOverflowStream(0, 4, true));40 test('stdin can use [4+], sync', () => testOverflowStream(0, [4], true));41 test('stdout can use 4+, sync', () => testOverflowStream(1, 4, true));42 test('stdout can use [4+], sync', () => testOverflowStream(1, [4], true));43 test('stderr can use 4+, sync', () => testOverflowStream(2, 4, true));44 test('stderr can use [4+], sync', () => testOverflowStream(2, [4], true));45 test('stdio[*] can use 4+, sync', () => testOverflowStream(3, 4, true));46 test('stdio[*] can use [4+], sync', () => testOverflowStream(3, [4], true));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 47–48why, one step back47}48TweaksSindre Sorhusbefore adoption698a1b8
lines 49–50why, one step back49const testOverflowStreamArray = (fdNumber, stdioOption) => {50 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 51–54why, one step back51 execa('empty.js', getStdio(fdNumber, stdioOption));52 }, {message: /no such standard stream/});53};54TweaksSindre Sorhusbefore adoption698a1b8
lines 55–59why, one step back55test('stdin cannot use 4+ and another value', () => testOverflowStreamArray(0, [4, 'pipe']));56test('stdout cannot use 4+ and another value', () => testOverflowStreamArray(1, [4, 'pipe']));57test('stderr cannot use 4+ and another value', () => testOverflowStreamArray(2, [4, 'pipe']));58test('stdio[*] cannot use 4+ and another value', () => testOverflowStreamArray(3, [4, 'pipe']));59test('stdio[*] cannot use "inherit" and another value', () => testOverflowStreamArray(3, ['inherit', 'pipe']));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 60why, one step back60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–63why, one step back61// A file descriptor number which is not open in the current process.62// Lower ones might be used internally by Node.js, and the error then depends on what they are.63const closedFdNumber = 1000;100% test coverage (#1018)ehmickybefore adoption9f65b86
line 64why, one step back64TweaksSindre Sorhusbefore adoption698a1b8
lines 65–68why, one step back65const testOverflowStreamArraySync = fdNumber => {66 assertThrows(() => {67 execaSync('noop-fd.js', [fdNumber, foobarString], getStdio(fdNumber, [closedFdNumber, 'pipe']));68 }, {code: 'EBADF'});100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 69–70why, one step back69};70TweaksSindre Sorhusbefore adoption698a1b8
lines 71–73why, one step back71test('stdout cannot use 4+ and another value, sync', () => testOverflowStreamArraySync(1));72test('stderr cannot use 4+ and another value, sync', () => testOverflowStreamArraySync(2));73test('stdio[*] cannot use 4+ and another value, sync', () => testOverflowStreamArraySync(3));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 74why, one step back74Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 75–77why, one step back75// `1` and 'inherit' are two spellings of the same target, which only becomes apparent once native values are normalized.76// The output must be written to the inherited file descriptor only once, which the nested parent captures.77// The nested parent's `stdout` has its final newline stripped by the outer `execa()` call.TweaksSindre Sorhusbefore adoption698a1b8
line 78why, one step back78const testSameTargetOutput = async (stdioOption, isSync) => {Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
line 79why, one step back79 const {stdout} = await nestedSubprocess('noop.js', [foobarString], {stdout: stdioOption, isSync});TweaksSindre Sorhusbefore adoption698a1b8
line 80why, one step back80 assert.equal(stdout, foobarString);Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a
lines 81–82why, one step back81};82TweaksSindre Sorhusbefore adoption698a1b8
lines 83–86why, one step back83test('stdout output is not duplicated with [1, "inherit"]', () => testSameTargetOutput([1, 'inherit'], false));84test('stdout output is not duplicated with ["inherit", 1]', () => testSameTargetOutput(['inherit', 1], false));85test('stdout output is not duplicated with [1, "inherit"], sync', () => testSameTargetOutput([1, 'inherit'], true));86test('stdout output is not duplicated with ["inherit", 1], sync', () => testSameTargetOutput(['inherit', 1], true));