Skip to content
Myr

handle-options.js

This file

Path

test/stdio/handle-options.js

51 lines · 2.9 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

lines 1–2why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 3why, one step back
3import {execa} from '../../index.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 4why, one step back
4import {getStdio, fullStdio} from '../helpers/stdio.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 5why, one step back
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 7–9why, one step back
7
8setFixtureDirectory();9

TweaksSindre Sorhusbefore adoption698a1b8

line 10why, one step back
10const testNoPipeOption = async (stdioOption, fdNumber) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 11why, one step back
11 const subprocess = execa('empty.js', getStdio(fdNumber, stdioOption));

TweaksSindre Sorhusbefore adoption698a1b8

line 12why, one step back
12 assert.equal(subprocess.stdio[fdNumber], null);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 13–15why, one step back
13 await subprocess;
14};15

TweaksSindre Sorhusbefore adoption698a1b8

lines 16–51why, one step back
16test('stdin can be "ignore"', () => testNoPipeOption('ignore', 0));
17test('stdin can be ["ignore"]', () => testNoPipeOption(['ignore'], 0));18test('stdin can be ["ignore", "ignore"]', () => testNoPipeOption(['ignore', 'ignore'], 0));19test('stdin can be "inherit"', () => testNoPipeOption('inherit', 0));20test('stdin can be ["inherit"]', () => testNoPipeOption(['inherit'], 0));21test('stdin can be 0', () => testNoPipeOption(0, 0));22test('stdin can be [0]', () => testNoPipeOption([0], 0));23test('stdout can be "ignore"', () => testNoPipeOption('ignore', 1));24test('stdout can be ["ignore"]', () => testNoPipeOption(['ignore'], 1));25test('stdout can be ["ignore", "ignore"]', () => testNoPipeOption(['ignore', 'ignore'], 1));26test('stdout can be "inherit"', () => testNoPipeOption('inherit', 1));27test('stdout can be ["inherit"]', () => testNoPipeOption(['inherit'], 1));28test('stdout can be 1', () => testNoPipeOption(1, 1));29test('stdout can be [1]', () => testNoPipeOption([1], 1));30test('stderr can be "ignore"', () => testNoPipeOption('ignore', 2));31test('stderr can be ["ignore"]', () => testNoPipeOption(['ignore'], 2));32test('stderr can be ["ignore", "ignore"]', () => testNoPipeOption(['ignore', 'ignore'], 2));33test('stderr can be "inherit"', () => testNoPipeOption('inherit', 2));34test('stderr can be ["inherit"]', () => testNoPipeOption(['inherit'], 2));35test('stderr can be 2', () => testNoPipeOption(2, 2));36test('stderr can be [2]', () => testNoPipeOption([2], 2));37test('stdio[*] can be "ignore"', () => testNoPipeOption('ignore', 3));38test('stdio[*] can be ["ignore"]', () => testNoPipeOption(['ignore'], 3));39test('stdio[*] can be ["ignore", "ignore"]', () => testNoPipeOption(['ignore', 'ignore'], 3));4041// Inheriting fd 3 requires the current process to have one that can be inherited. The test runner does not provide one, so this runs inside a parent process which does.42const testNoPipeOptionFd3 = async stdioOption => {43 const {nestedResult} = await nestedSubprocess('empty.js', getStdio(3, stdioOption), fullStdio);44 assert.equal(nestedResult.failed, false);45 assert.equal(nestedResult.stdio[3], undefined);46};4748test('stdio[*] can be "inherit"', () => testNoPipeOptionFd3('inherit'));49test('stdio[*] can be ["inherit"]', () => testNoPipeOptionFd3(['inherit']));50test('stdio[*] can be 3', () => testNoPipeOptionFd3(3));51test('stdio[*] can be [3]', () => testNoPipeOptionFd3([3]));