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 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 {readFile, rm} from 'node:fs/promises';TweaksSindre Sorhusbefore adoption698a1b8
line 3why, one step back3import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 4why, one step back4import tempfile from 'tempfile';TweaksSindre Sorhusbefore adoption698a1b8
line 5why, one step back5import {assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 6–9why, one step back6import {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 back10import {nestedSubprocess} from '../helpers/nested.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 11–13why, one step back1112setFixtureDirectory();13TweaksSindre Sorhusbefore adoption698a1b8
line 14why, one step back14const testInheritStdin = async (stdioOption, isSync) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 15why, one step back15 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdioOption), `${isSync}`], {input: foobarString});TweaksSindre Sorhusbefore adoption698a1b8
line 16why, one step back16 assert.equal(stdout, `${foobarString}${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 17–18why, one step back17};18TweaksSindre Sorhusbefore adoption698a1b8
lines 19–24why, one step back19test('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 back2526// eslint-disable-next-line max-paramsTweaksSindre Sorhusbefore adoption698a1b8
line 27why, one step back27const testInheritStdioOutput = async (fdNumber, outerFdNumber, stdioOption, isSync, encoding) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 28why, one step back28 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 back29 assert.equal(stdio[fdNumber], foobarString);30 assert.equal(stdio[outerFdNumber], `nested ${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 31–32why, one step back31};32TweaksSindre Sorhusbefore adoption698a1b8
lines 33–60why, one step back33test('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 back61TweaksSindre Sorhusbefore adoption698a1b8
line 62why, one step back62const testInheritNoBuffer = async (stdioOption, isSync) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 63why, one step back63 const filePath = tempfile();Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 64why, one step back64 await nestedSubprocess('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false, isSync}, {input: foobarString});TweaksSindre Sorhusbefore adoption698a1b8
line 65why, one step back65 assert.equal(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 66–68why, one step back66 await rm(filePath);67};68TweaksSindre Sorhusbefore adoption698a1b8
lines 69–72why, one step back69test('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 back73TweaksSindre Sorhusbefore adoption698a1b8
line 74why, one step back74test('stdin can use ["inherit", "pipe"] in a TTY', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 75–76why, one step back75 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 back77 assert.equal(stdout, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 78–79why, one step back78});79TweaksSindre Sorhusbefore adoption698a1b8
line 80why, one step back80const testNoTtyInput = async (fdNumber, optionName) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 81–82why, one step back81 const stdioOption = ['pipe', 'inherit', 'pipe'];82 stdioOption[fdNumber] = [[''], 'inherit', 'pipe'];TweaksSindre Sorhusbefore adoption698a1b8
lines 83–84why, one step back83 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 back85};86TweaksSindre Sorhusbefore adoption698a1b8
lines 87–88why, one step back87test('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 back89TweaksSindre Sorhusbefore adoption698a1b8
line 90why, one step back90const testTtyOutput = async (fdNumber, isSync) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 91why, one step back91 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 back92 assert.equal(stdio[fdNumber], foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 93–94why, one step back93};94TweaksSindre Sorhusbefore adoption698a1b8
lines 95–99why, one step back95test('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));