Skip to content
Myr

normalize.js

This file

Path

test/stdio/normalize.js

66 lines · 3.6 KiB · JavaScript

Last changed by

Refactor `stdio` normalization logic (#638)ehmickybefore adoptionf4955ad

History of this file

Take it

Refactor tests (#628)ehmickybefore adoption30ecc81

lines 1–20why, one step back
1import {inspect} from 'node:util';
2import test from 'ava';3import {normalizeStdio, normalizeStdioNode} from '../../lib/stdio/normalize.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()');20

Refactor `stdio` normalization logic (#638)ehmickybefore adoptionf4955ad

lines 21–22why, one step back
21test(stdioMacro, undefined, [undefined, undefined, undefined]);
22test(stdioMacro, null, [undefined, undefined, undefined]);

Refactor tests (#628)ehmickybefore adoption30ecc81

line 23why, one step back
23

Refactor `stdio` normalization logic (#638)ehmickybefore adoptionf4955ad

lines 24–26why, one step back
24test(stdioMacro, {stdio: 'inherit'}, ['inherit', 'inherit', 'inherit']);
25test(stdioMacro, {stdio: 'pipe'}, ['pipe', 'pipe', 'pipe']);26test(stdioMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore']);

Refactor tests (#628)ehmickybefore adoption30ecc81

lines 27–54why, one step back
27test(stdioMacro, {stdio: [0, 1, 2]}, [0, 1, 2]);
2829test(stdioMacro, {}, [undefined, undefined, undefined]);30test(stdioMacro, {stdio: []}, [undefined, undefined, undefined]);31test(stdioMacro, {stdin: 'pipe'}, ['pipe', undefined, undefined]);32test(stdioMacro, {stdout: 'ignore'}, [undefined, 'ignore', undefined]);33test(stdioMacro, {stderr: 'inherit'}, [undefined, undefined, 'inherit']);34test(stdioMacro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);35test(stdioMacro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', undefined]);36test(stdioMacro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', undefined, 'inherit']);37test(stdioMacro, {stdout: 'ignore', stderr: 'inherit'}, [undefined, 'ignore', 'inherit']);38test(stdioMacro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);39test(stdioMacro, {stdin: 0, stdout: 1}, [0, 1, undefined]);40test(stdioMacro, {stdin: 0, stderr: 2}, [0, undefined, 2]);41test(stdioMacro, {stdout: 1, stderr: 2}, [undefined, 1, 2]);4243test(stdioMacro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));4445test(stdioMacro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));46test(stdioMacro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));47test(stdioMacro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));48test(stdioMacro, {stdin: 0, stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));4950const forkMacro = (...args) => macro(...args, normalizeStdioNode);51forkMacro.title = macroTitle('execaNode()');5253test(forkMacro, undefined, [undefined, undefined, undefined, 'ipc']);54test(forkMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore', 'ipc']);

Refactor `stdio` normalization logic (#638)ehmickybefore adoptionf4955ad

line 55why, one step back
55test(forkMacro, {stdio: 'ipc'}, ['ipc', 'ipc', 'ipc']);

Refactor tests (#628)ehmickybefore adoption30ecc81

lines 56–66why, one step back
56test(forkMacro, {stdio: [0, 1, 2]}, [0, 1, 2, 'ipc']);
57test(forkMacro, {stdio: [0, 1, 2, 3]}, [0, 1, 2, 3, 'ipc']);58test(forkMacro, {stdio: [0, 1, 2, 'ipc']}, [0, 1, 2, 'ipc']);5960test(forkMacro, {stdio: [0, 1, undefined]}, [0, 1, undefined, 'ipc']);61test(forkMacro, {stdio: [0, 1, 2, undefined]}, [0, 1, 2, undefined, 'ipc']);62test(forkMacro, {stdout: 'ignore'}, [undefined, 'ignore', undefined, 'ipc']);63test(forkMacro, {stdout: 'ignore', stderr: 'ignore'}, [undefined, 'ignore', 'ignore', 'ipc']);6465test(forkMacro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));66test(forkMacro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));