Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 2why, one step back
2import {platform} from 'node:process';

TweaksSindre Sorhusbefore adoption698a1b8

lines 3–4why, one step back
3import test from 'node:test';
4import {assertThrows} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–8why, one step back
5import {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 back
9import {nestedSubprocess} from '../helpers/nested.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 10–14why, one step back
10
11setFixtureDirectory();1213const isLinux = platform === 'linux';14

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15const testFd3InheritOutput = async (stdioOption, isSync) => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 16why, one step back
16 const {stdio} = await nestedSubprocess('noop-fd.js', ['3', foobarString], {...getStdio(3, stdioOption), isSync}, fullStdio);

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17 assert.equal(stdio[3], foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 18–19why, one step back
18};
19

TweaksSindre Sorhusbefore adoption698a1b8

lines 20–23why, one step back
20test('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 back
24
25if (isLinux) {

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26 const testOverflowStream = async (fdNumber, stdioOption, isSync) => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 27why, one step back
27 const {stdout} = await nestedSubprocess('empty.js', {...getStdio(fdNumber, stdioOption), isSync}, fullStdio);

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28 assert.equal(stdout, '');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 29–30why, one step back
29 };
30

TweaksSindre Sorhusbefore adoption698a1b8

lines 31–46why, one step back
31 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 back
47}
48

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–50why, one step back
49const testOverflowStreamArray = (fdNumber, stdioOption) => {
50 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 51–54why, one step back
51 execa('empty.js', getStdio(fdNumber, stdioOption));
52 }, {message: /no such standard stream/});53};54

TweaksSindre Sorhusbefore adoption698a1b8

lines 55–59why, one step back
55test('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 back
60

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–63why, one step back
61// 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 back
64

TweaksSindre Sorhusbefore adoption698a1b8

lines 65–68why, one step back
65const 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 back
69};
70

TweaksSindre Sorhusbefore adoption698a1b8

lines 71–73why, one step back
71test('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 back
74

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 75–77why, one step back
75// `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 back
78const testSameTargetOutput = async (stdioOption, isSync) => {

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

line 79why, one step back
79 const {stdout} = await nestedSubprocess('noop.js', [foobarString], {stdout: stdioOption, isSync});

TweaksSindre Sorhusbefore adoption698a1b8

line 80why, one step back
80 assert.equal(stdout, foobarString);

Fix duplicated or conflicting file descriptor targetsSindre Sorhusbefore adoption587045a

lines 81–82why, one step back
81};
82

TweaksSindre Sorhusbefore adoption698a1b8

lines 83–86why, one step back
83test('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));