Skip to content
Myr

native-inherit-pipe.js

This file

Path

test/stdio/native-inherit-pipe.js

99 lines · 7.5 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 {readFile, rm} from 'node:fs/promises';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 4why, one step back
4import tempfile from 'tempfile';

TweaksSindre Sorhusbefore adoption698a1b8

line 5why, one step back
5import {assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 6–9why, one step back
6import {execa} from '../../index.js';
7import {getStdio, fullStdio} from '../helpers/stdio.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {foobarString} from '../helpers/input.js';

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

line 10why, one step back
10import {nestedSubprocess} from '../helpers/nested.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 11–13why, one step back
11
12setFixtureDirectory();13

TweaksSindre Sorhusbefore adoption698a1b8

line 14why, one step back
14const testInheritStdin = async (stdioOption, isSync) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 15why, one step back
15 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdioOption), `${isSync}`], {input: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

line 16why, one step back
16 assert.equal(stdout, `${foobarString}${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 19–24why, one step back
19test('stdin can be ["inherit", "pipe"]', () => testInheritStdin(['inherit', 'pipe'], false));
20test('stdin can be [0, "pipe"]', () => testInheritStdin([0, 'pipe'], false));21test('stdin can be [process.stdin, "pipe"]', () => testInheritStdin(['stdin', 'pipe'], false));22test('stdin can be ["inherit", "pipe"], sync', () => testInheritStdin(['inherit', 'pipe'], true));23test('stdin can be [0, "pipe"], sync', () => testInheritStdin([0, 'pipe'], true));24test('stdin can be [process.stdin, "pipe"], sync', () => testInheritStdin(['stdin', 'pipe'], true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 25–26why, one step back
25
26// eslint-disable-next-line max-params

TweaksSindre Sorhusbefore adoption698a1b8

line 27why, one step back
27const testInheritStdioOutput = async (fdNumber, outerFdNumber, stdioOption, isSync, encoding) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 28why, one step back
28 const {stdio} = await execa('nested-multiple-stdio-output.js', [JSON.stringify(stdioOption), `${fdNumber}`, `${outerFdNumber}`, `${isSync}`, encoding], fullStdio);

TweaksSindre Sorhusbefore adoption698a1b8

lines 29–30why, one step back
29 assert.equal(stdio[fdNumber], foobarString);
30 assert.equal(stdio[outerFdNumber], `nested ${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 31–32why, one step back
31};
32

TweaksSindre Sorhusbefore adoption698a1b8

lines 33–60why, one step back
33test('stdout can be ["inherit", "pipe"]', () => testInheritStdioOutput(1, 2, ['inherit', 'pipe'], false, 'utf8'));
34test('stdout can be [1, "pipe"]', () => testInheritStdioOutput(1, 2, [1, 'pipe'], false, 'utf8'));35test('stdout can be [process.stdout, "pipe"]', () => testInheritStdioOutput(1, 2, ['stdout', 'pipe'], false, 'utf8'));36test('stderr can be ["inherit", "pipe"]', () => testInheritStdioOutput(2, 1, ['inherit', 'pipe'], false, 'utf8'));37test('stderr can be [2, "pipe"]', () => testInheritStdioOutput(2, 1, [2, 'pipe'], false, 'utf8'));38test('stderr can be [process.stderr, "pipe"]', () => testInheritStdioOutput(2, 1, ['stderr', 'pipe'], false, 'utf8'));39test('stdout can be ["inherit", "pipe"], encoding "buffer"', () => testInheritStdioOutput(1, 2, ['inherit', 'pipe'], false, 'buffer'));40test('stdout can be [1, "pipe"], encoding "buffer"', () => testInheritStdioOutput(1, 2, [1, 'pipe'], false, 'buffer'));41test('stdout can be [process.stdout, "pipe"], encoding "buffer"', () => testInheritStdioOutput(1, 2, ['stdout', 'pipe'], false, 'buffer'));42test('stderr can be ["inherit", "pipe"], encoding "buffer"', () => testInheritStdioOutput(2, 1, ['inherit', 'pipe'], false, 'buffer'));43test('stderr can be [2, "pipe"], encoding "buffer"', () => testInheritStdioOutput(2, 1, [2, 'pipe'], false, 'buffer'));44test('stderr can be [process.stderr, "pipe"], encoding "buffer"', () => testInheritStdioOutput(2, 1, ['stderr', 'pipe'], false, 'buffer'));45test('stdout can be ["inherit", "pipe"], sync', () => testInheritStdioOutput(1, 2, ['inherit', 'pipe'], true, 'utf8'));46test('stdout can be [1, "pipe"], sync', () => testInheritStdioOutput(1, 2, [1, 'pipe'], true, 'utf8'));47test('stdout can be [process.stdout, "pipe"], sync', () => testInheritStdioOutput(1, 2, ['stdout', 'pipe'], true, 'utf8'));48test('stderr can be ["inherit", "pipe"], sync', () => testInheritStdioOutput(2, 1, ['inherit', 'pipe'], true, 'utf8'));49test('stderr can be [2, "pipe"], sync', () => testInheritStdioOutput(2, 1, [2, 'pipe'], true, 'utf8'));50test('stderr can be [process.stderr, "pipe"], sync', () => testInheritStdioOutput(2, 1, ['stderr', 'pipe'], true, 'utf8'));51test('stdio[*] output can be ["inherit", "pipe"], sync', () => testInheritStdioOutput(3, 1, ['inherit', 'pipe'], true, 'utf8'));52test('stdio[*] output can be [3, "pipe"], sync', () => testInheritStdioOutput(3, 1, [3, 'pipe'], true, 'utf8'));53test('stdout can be ["inherit", "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(1, 2, ['inherit', 'pipe'], true, 'buffer'));54test('stdout can be [1, "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(1, 2, [1, 'pipe'], true, 'buffer'));55test('stdout can be [process.stdout, "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(1, 2, ['stdout', 'pipe'], true, 'buffer'));56test('stderr can be ["inherit", "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(2, 1, ['inherit', 'pipe'], true, 'buffer'));57test('stderr can be [2, "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(2, 1, [2, 'pipe'], true, 'buffer'));58test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(2, 1, ['stderr', 'pipe'], true, 'buffer'));59test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(3, 1, ['inherit', 'pipe'], true, 'buffer'));60test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', () => testInheritStdioOutput(3, 1, [3, 'pipe'], true, 'buffer'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 61why, one step back
61

TweaksSindre Sorhusbefore adoption698a1b8

line 62why, one step back
62const testInheritNoBuffer = async (stdioOption, isSync) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 63why, one step back
63 const filePath = tempfile();

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

line 64why, one step back
64 await nestedSubprocess('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false, isSync}, {input: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

line 65why, one step back
65 assert.equal(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 66–68why, one step back
66 await rm(filePath);
67};68

TweaksSindre Sorhusbefore adoption698a1b8

lines 69–72why, one step back
69test('stdin can be ["inherit", "pipe"], buffer: false', () => testInheritNoBuffer(['inherit', 'pipe'], false));
70test('stdin can be [0, "pipe"], buffer: false', () => testInheritNoBuffer([0, 'pipe'], false));71test('stdin can be ["inherit", "pipe"], buffer: false, sync', () => testInheritNoBuffer(['inherit', 'pipe'], true));72test('stdin can be [0, "pipe"], buffer: false, sync', () => testInheritNoBuffer([0, 'pipe'], true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 73why, one step back
73

TweaksSindre Sorhusbefore adoption698a1b8

line 74why, one step back
74test('stdin can use ["inherit", "pipe"] in a TTY', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 75–76why, one step back
75 const stdioOption = [['inherit', 'pipe'], 'inherit', 'pipe'];
76 const {stdout} = await execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'false', 'stdin-fd.js', '0'], {input: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 78–79why, one step back
78});
79

TweaksSindre Sorhusbefore adoption698a1b8

line 80why, one step back
80const testNoTtyInput = async (fdNumber, optionName) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 81–82why, one step back
81 const stdioOption = ['pipe', 'inherit', 'pipe'];
82 stdioOption[fdNumber] = [[''], 'inherit', 'pipe'];

TweaksSindre Sorhusbefore adoption698a1b8

lines 83–84why, one step back
83 const {message} = await assertRejects(execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'true', 'stdin-fd.js', `${fdNumber}`], fullStdio));
84 assert.ok(message.includes(`The \`${optionName}: 'inherit'\` option is invalid: it cannot be a TTY`));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 85–86why, one step back
85};
86

TweaksSindre Sorhusbefore adoption698a1b8

lines 87–88why, one step back
87test('stdin cannot use ["inherit", "pipe"] in a TTY, sync', () => testNoTtyInput(0, 'stdin'));
88test('stdio[*] input cannot use ["inherit", "pipe"] in a TTY, sync', () => testNoTtyInput(3, 'stdio[3]'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 89why, one step back
89

TweaksSindre Sorhusbefore adoption698a1b8

line 90why, one step back
90const testTtyOutput = async (fdNumber, isSync) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 91why, one step back
91 const {stdio} = await execa('nested-sync-tty.js', [JSON.stringify(getStdio(fdNumber, ['inherit', 'pipe'])), `${isSync}`, 'noop-fd.js', `${fdNumber}`, foobarString], fullStdio);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 93–94why, one step back
93};
94

TweaksSindre Sorhusbefore adoption698a1b8

lines 95–99why, one step back
95test('stdout can use ["inherit", "pipe"] in a TTY', () => testTtyOutput(1, false));
96test('stderr can use ["inherit", "pipe"] in a TTY', () => testTtyOutput(2, false));97test('stdout can use ["inherit", "pipe"] in a TTY, sync', () => testTtyOutput(1, true));98test('stderr can use ["inherit", "pipe"] in a TTY, sync', () => testTtyOutput(2, true));99test('stdio[*] output can use ["inherit", "pipe"] in a TTY, sync', () => testTtyOutput(3, true));