stdio.js
This file
Path
test/stdio.js
49 lines · 2.2 KiB · JavaScript
Last changed by
Improve the TS types and don't accept `null` in the `stdio` optionSindre Sorhusbefore adoption4692dcd
History of this fileTake it
Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
lines 1–23why, one step back1import util from 'util';2import test from 'ava';3import stdio from '../lib/stdio';45util.inspect.styles.name = 'magenta';67function macro(t, input, expected) {8 if (expected instanceof Error) {9 t.throws(() => stdio(input), expected.message);10 return;11 }1213 const result = stdio(input);1415 if (typeof expected === 'object' && expected !== null) {16 t.deepEqual(result, expected);17 } else {18 t.is(result, expected);19 }20}2122macro.title = (providedTitle, input) => providedTitle || util.inspect(input, {colors: true});23Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
line 24why, one step back24test(macro, undefined, undefined);Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
lines 25–30why, one step back2526test(macro, {stdio: 'inherit'}, 'inherit');27test(macro, {stdio: 'pipe'}, 'pipe');28test(macro, {stdio: 'ignore'}, 'ignore');29test(macro, {stdio: [0, 1, 2]}, [0, 1, 2]);30Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
lines 31–35why, one step back31test(macro, {}, [undefined, undefined, undefined]);32test(macro, {stdio: []}, [undefined, undefined, undefined]);33test(macro, {stdin: 'pipe'}, ['pipe', undefined, undefined]);34test(macro, {stdout: 'ignore'}, [undefined, 'ignore', undefined]);35test(macro, {stderr: 'inherit'}, [undefined, undefined, 'inherit']);Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
line 36why, one step back36test(macro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
lines 37–39why, one step back37test(macro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', undefined]);38test(macro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', undefined, 'inherit']);39test(macro, {stdout: 'ignore', stderr: 'inherit'}, [undefined, 'ignore', 'inherit']);Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
line 40why, one step back40test(macro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
lines 41–43why, one step back41test(macro, {stdin: 0, stdout: 1}, [0, 1, undefined]);42test(macro, {stdin: 0, stderr: 2}, [0, undefined, 2]);43test(macro, {stdout: 1, stderr: 2}, [undefined, 1, 2]);Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a
lines 44–49why, one step back4445test(macro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));4647test(macro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));48test(macro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));49test(macro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));