Skip to content
Myr

option.js

This file

Path

test/stdio/option.js

57 lines · 3.0 KiB · JavaScript

Last changed by

Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–23why, one step back
1import {inspect} from 'node:util';
2import test from 'ava';3import {normalizeStdio} from '../../lib/stdio/option.js';45const macro = (t, input, expected, func) => {6 if (expected instanceof Error) {7 t.throws(() => {8 normalizeStdio(input);9 }, {message: expected.message});10 return;11 }1213 t.deepEqual(func(input), expected);14};1516const macroTitle = name => (title, input) => `${name} ${(inspect(input))}`;1718const stdioMacro = (...args) => macro(...args, normalizeStdio);19stdioMacro.title = macroTitle('execa()');2021test(stdioMacro, {stdio: 'inherit'}, ['inherit', 'inherit', 'inherit']);22test(stdioMacro, {stdio: 'pipe'}, ['pipe', 'pipe', 'pipe']);23test(stdioMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore']);

Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7

lines 24–28why, one step back
24
25test(stdioMacro, {}, ['pipe', 'pipe', 'pipe']);26test(stdioMacro, {stdio: []}, ['pipe', 'pipe', 'pipe']);27test(stdioMacro, {stdio: [0]}, [0, 'pipe', 'pipe']);28test(stdioMacro, {stdio: [0, 1]}, [0, 1, 'pipe']);

Split files (#837)ehmickybefore adoption672c2d7

line 29why, one step back
29test(stdioMacro, {stdio: [0, 1, 2]}, [0, 1, 2]);

Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7

lines 30–38why, one step back
30test(stdioMacro, {stdio: [0, 1, 2, 3]}, [0, 1, 2, 3]);
31test(stdioMacro, {stdio: [undefined, 1, 2]}, ['pipe', 1, 2]);32test(stdioMacro, {stdio: [null, 1, 2]}, ['pipe', 1, 2]);33test(stdioMacro, {stdio: [0, undefined, 2]}, [0, 'pipe', 2]);34test(stdioMacro, {stdio: [0, null, 2]}, [0, 'pipe', 2]);35test(stdioMacro, {stdio: [0, 1, undefined]}, [0, 1, 'pipe']);36test(stdioMacro, {stdio: [0, 1, null]}, [0, 1, 'pipe']);37test(stdioMacro, {stdio: [0, 1, 2, undefined]}, [0, 1, 2, 'ignore']);38test(stdioMacro, {stdio: [0, 1, 2, null]}, [0, 1, 2, 'ignore']);

Split files (#837)ehmickybefore adoption672c2d7

line 39why, one step back
39

Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7

lines 40–42why, one step back
40test(stdioMacro, {stdin: 'pipe'}, ['pipe', 'pipe', 'pipe']);
41test(stdioMacro, {stdout: 'ignore'}, ['pipe', 'ignore', 'pipe']);42test(stdioMacro, {stderr: 'inherit'}, ['pipe', 'pipe', 'inherit']);

Split files (#837)ehmickybefore adoption672c2d7

line 43why, one step back
43test(stdioMacro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);

Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7

lines 44–46why, one step back
44test(stdioMacro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', 'pipe']);
45test(stdioMacro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', 'pipe', 'inherit']);46test(stdioMacro, {stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);

Split files (#837)ehmickybefore adoption672c2d7

line 47why, one step back
47test(stdioMacro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);

Fix `stdio: [..., undefined]` option (#948)ehmickybefore adoption96d2ef7

lines 48–50why, one step back
48test(stdioMacro, {stdin: 0, stdout: 1}, [0, 1, 'pipe']);
49test(stdioMacro, {stdin: 0, stderr: 2}, [0, 'pipe', 2]);50test(stdioMacro, {stdout: 1, stderr: 2}, ['pipe', 1, 2]);

Split files (#837)ehmickybefore adoption672c2d7

lines 51–57why, one step back
51
52test(stdioMacro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));5354test(stdioMacro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));55test(stdioMacro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));56test(stdioMacro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));57test(stdioMacro, {stdin: 0, stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));