Skip to content
Myr

stdio-option.js

This file

Path

test/stdio/stdio-option.js

61 lines · 2.7 KiB · JavaScript

Last changed by

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 2why, one step back
2import {inspect} from 'node:util';

TweaksSindre Sorhusbefore adoption698a1b8

lines 3–4why, one step back
3import test from 'node:test';
4import {assertThrows} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–6why, one step back
5import {normalizeStdioOption} from '../../lib/stdio/stdio-option.js';
6

TweaksSindre Sorhusbefore adoption698a1b8

line 7why, one step back
7const stdioMacro = (input, expected) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 8why, one step back
8 if (expected instanceof Error) {

TweaksSindre Sorhusbefore adoption698a1b8

line 9why, one step back
9 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 10–14why, one step back
10 normalizeStdioOption(input);
11 }, {message: expected.message});12 return;13 }14

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15 assert.deepEqual(normalizeStdioOption(input), expected);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 16–17why, one step back
16};
17

TweaksSindre Sorhusbefore adoption698a1b8

lines 18–21why, one step back
18const stdioCases = [
19 [{stdio: 'inherit'}, ['inherit', 'inherit', 'inherit']],20 [{stdio: 'pipe'}, ['pipe', 'pipe', 'pipe']],21 [{stdio: 'ignore'}, ['ignore', 'ignore', 'ignore']],

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 22why, one step back
22

TweaksSindre Sorhusbefore adoption698a1b8

lines 23–36why, one step back
23 [{}, ['pipe', 'pipe', 'pipe']],
24 [{stdio: []}, ['pipe', 'pipe', 'pipe']],25 [{stdio: [0]}, [0, 'pipe', 'pipe']],26 [{stdio: [0, 1]}, [0, 1, 'pipe']],27 [{stdio: [0, 1, 2]}, [0, 1, 2]],28 [{stdio: [0, 1, 2, 3]}, [0, 1, 2, 3]],29 [{stdio: [undefined, 1, 2]}, ['pipe', 1, 2]],30 [{stdio: [null, 1, 2]}, ['pipe', 1, 2]],31 [{stdio: [0, undefined, 2]}, [0, 'pipe', 2]],32 [{stdio: [0, null, 2]}, [0, 'pipe', 2]],33 [{stdio: [0, 1, undefined]}, [0, 1, 'pipe']],34 [{stdio: [0, 1, null]}, [0, 1, 'pipe']],35 [{stdio: [0, 1, 2, undefined]}, [0, 1, 2, 'ignore']],36 [{stdio: [0, 1, 2, null]}, [0, 1, 2, 'ignore']],

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 37why, one step back
37

TweaksSindre Sorhusbefore adoption698a1b8

lines 38–48why, one step back
38 [{stdin: 'pipe'}, ['pipe', 'pipe', 'pipe']],
39 [{stdout: 'ignore'}, ['pipe', 'ignore', 'pipe']],40 [{stderr: 'inherit'}, ['pipe', 'pipe', 'inherit']],41 [{stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']],42 [{stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', 'pipe']],43 [{stdin: 'pipe', stderr: 'inherit'}, ['pipe', 'pipe', 'inherit']],44 [{stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']],45 [{stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]],46 [{stdin: 0, stdout: 1}, [0, 1, 'pipe']],47 [{stdin: 0, stderr: 2}, [0, 'pipe', 2]],48 [{stdout: 1, stderr: 2}, ['pipe', 1, 2]],

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 49why, one step back
49

TweaksSindre Sorhusbefore adoption698a1b8

line 50why, one step back
50 [{stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`')],

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

line 51why, one step back
51 [{stdio: null}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `null`')],

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 52why, one step back
52

TweaksSindre Sorhusbefore adoption698a1b8

lines 53–57why, one step back
53 [{stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`')],
54 [{stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`')],55 [{stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`')],56 [{stdin: 0, stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`')],57];

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 58why, one step back
58

TweaksSindre Sorhusbefore adoption698a1b8

lines 59–61why, one step back
59for (const [input, expected] of stdioCases) {
60 test(`execa() ${inspect(input)}`, () => stdioMacro(input, expected));61}