Skip to content
Myr

stdio.js

This file

Path

test/stdio.js

50 lines · 2.1 KiB · JavaScript

Last changed by

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

History of this file

Take it

Better stdio option handling - fixes #24Sam Verschuerenbefore adoption9cd5e2a

lines 1–50why, one step back
1import 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});2324test(macro, undefined, null);25test(macro, null, null);2627test(macro, {stdio: 'inherit'}, 'inherit');28test(macro, {stdio: 'pipe'}, 'pipe');29test(macro, {stdio: 'ignore'}, 'ignore');30test(macro, {stdio: [0, 1, 2]}, [0, 1, 2]);3132test(macro, {}, [null, null, null]);33test(macro, {stdio: []}, [null, null, null]);34test(macro, {stdin: 'pipe'}, ['pipe', null, null]);35test(macro, {stdout: 'ignore'}, [null, 'ignore', null]);36test(macro, {stderr: 'inherit'}, [null, null, 'inherit']);37test(macro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);38test(macro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', null]);39test(macro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', null, 'inherit']);40test(macro, {stdout: 'ignore', stderr: 'inherit'}, [null, 'ignore', 'inherit']);41test(macro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);42test(macro, {stdin: 0, stdout: 1}, [0, 1, null]);43test(macro, {stdin: 0, stderr: 2}, [0, null, 2]);44test(macro, {stdout: 1, stderr: 2}, [null, 1, 2]);4546test(macro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));4748test(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: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));50test(macro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));