Fix fd-specific options (#974)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent a25a50d · Browse files · 3 files·+58 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+58 added−2 removed
- tests:+32 added−0 removed
- other:+26 added−2 removed
Provenance
- Commit
4940511- Tree
c32b947- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
a25a50d
3 files changed+58 added−2 removed
modified:lib/arguments/specific.js+13 added-2 removed
25 unmodified lines26272829303031323233343536373839404142434445464748495051525341 unmodified lines25 unmodified lines ? normalizeOptionObject(optionValue, optionArray, optionName) : optionArray.fill(optionValue);
const normalizeOptionObject = (optionValue, optionArray, optionName) => { for (const [fdName, fdValue] of Object.entries(optionValue)) { for (const fdName of Object.keys(optionValue).sort(compareFdName)) { for (const fdNumber of parseFdName(fdName, optionName, optionArray)) { optionArray[fdNumber] = fdValue; optionArray[fdNumber] = optionValue[fdName]; } }
return optionArray;};
// Ensure priority order when setting both `stdout`/`stderr`, `fd1`/`fd2`, and `all`const compareFdName = (fdNameA, fdNameB) => getFdNameOrder(fdNameA) < getFdNameOrder(fdNameB) ? 1 : -1;
const getFdNameOrder = fdName => { if (fdName === 'stdout' || fdName === 'stderr') { return 0; }
return fdName === 'all' ? 2 : 1;};
const parseFdName = (fdName, optionName, optionArray) => { const fdNumber = parseFd(fdName); if (fdNumber === undefined || fdNumber === 0) { throw new TypeError(`"${optionName}.${fdName}" is invalid.41 unmodified linesmodified:test/stream/no-buffer.js+32 added
143 unmodified lines144 test('buffer: {stdout: false}, all: true, sync', testNoOutputAll, {stdout: false}, false, true, execaSync);145 test('buffer: {stderr: false}, all: true, sync', testNoOutputAll, {stderr: false}, true, false, execaSync);146 test('buffer: {all: false}, all: true, sync', testNoOutputAll, {all: false}, false, false, execaSync);147 148+// eslint-disable-next-line max-params149+const testPriorityOrder = async (t, buffer, bufferStdout, bufferStderr, execaMethod) => {150+ const {stdout, stderr} = await execaMethod('noop-both.js', {buffer});151+ t.is(stdout, bufferStdout ? foobarString : undefined);152+ t.is(stderr, bufferStderr ? foobarString : undefined);153+};154+155+test('buffer: {stdout, fd1}', testPriorityOrder, {stdout: true, fd1: false}, true, true, execa);156+test('buffer: {stdout, all}', testPriorityOrder, {stdout: true, all: false}, true, false, execa);157+test('buffer: {fd1, all}', testPriorityOrder, {fd1: true, all: false}, true, false, execa);158+test('buffer: {stderr, fd2}', testPriorityOrder, {stderr: true, fd2: false}, true, true, execa);159+test('buffer: {stderr, all}', testPriorityOrder, {stderr: true, all: false}, false, true, execa);160+test('buffer: {fd2, all}', testPriorityOrder, {fd2: true, all: false}, false, true, execa);161+test('buffer: {fd1, stdout}', testPriorityOrder, {fd1: false, stdout: true}, true, true, execa);162+test('buffer: {all, stdout}', testPriorityOrder, {all: false, stdout: true}, true, false, execa);163+test('buffer: {all, fd1}', testPriorityOrder, {all: false, fd1: true}, true, false, execa);164+test('buffer: {fd2, stderr}', testPriorityOrder, {fd2: false, stderr: true}, true, true, execa);165+test('buffer: {all, stderr}', testPriorityOrder, {all: false, stderr: true}, false, true, execa);166+test('buffer: {all, fd2}', testPriorityOrder, {all: false, fd2: true}, false, true, execa);167+test('buffer: {stdout, fd1}, sync', testPriorityOrder, {stdout: true, fd1: false}, true, true, execaSync);168+test('buffer: {stdout, all}, sync', testPriorityOrder, {stdout: true, all: false}, true, false, execaSync);169+test('buffer: {fd1, all}, sync', testPriorityOrder, {fd1: true, all: false}, true, false, execaSync);170+test('buffer: {stderr, fd2}, sync', testPriorityOrder, {stderr: true, fd2: false}, true, true, execaSync);171+test('buffer: {stderr, all}, sync', testPriorityOrder, {stderr: true, all: false}, false, true, execaSync);172+test('buffer: {fd2, all}, sync', testPriorityOrder, {fd2: true, all: false}, false, true, execaSync);173+test('buffer: {fd1, stdout}, sync', testPriorityOrder, {fd1: false, stdout: true}, true, true, execaSync);174+test('buffer: {all, stdout}, sync', testPriorityOrder, {all: false, stdout: true}, true, false, execaSync);175+test('buffer: {all, fd1}, sync', testPriorityOrder, {all: false, fd1: true}, true, false, execaSync);176+test('buffer: {fd2, stderr}, sync', testPriorityOrder, {fd2: false, stderr: true}, true, true, execaSync);177+test('buffer: {all, stderr}, sync', testPriorityOrder, {all: false, stderr: true}, false, true, execaSync);178+test('buffer: {all, fd2}, sync', testPriorityOrder, {all: false, fd2: true}, false, true, execaSync);179+180 const testTransform = async (t, objectMode, execaMethod) => {181 const lines = [];182 const {stdout} = await execaMethod('noop.js', {183 buffer: false,41 unmodified linesmodified:index.test-d.ts+13 added
1633 unmodified lines1634 execaSync('unicorns', {buffer: {fd2: true}});1635 execaSync('unicorns', {buffer: {fd3: true}});1636 expectError(execaSync('unicorns', {buffer: {stdout: 'true'}}));1637 1638+expectType<string[]>(execaSync('unicorns', {lines: {stdout: true, fd1: false}}).stdout);1639+expectType<string[]>(execaSync('unicorns', {lines: {stdout: true, all: false}}).stdout);1640+expectType<string[]>(execaSync('unicorns', {lines: {fd1: true, all: false}}).stdout);1641+expectType<string[]>(execaSync('unicorns', {lines: {stderr: true, fd2: false}}).stderr);1642+expectType<string[]>(execaSync('unicorns', {lines: {stderr: true, all: false}}).stderr);1643+expectType<string[]>(execaSync('unicorns', {lines: {fd2: true, all: false}}).stderr);1644+expectType<string[]>(execaSync('unicorns', {lines: {fd1: false, stdout: true}}).stdout);1645+expectType<string[]>(execaSync('unicorns', {lines: {all: false, stdout: true}}).stdout);1646+expectType<string[]>(execaSync('unicorns', {lines: {all: false, fd1: true}}).stdout);1647+expectType<string[]>(execaSync('unicorns', {lines: {fd2: false, stderr: true}}).stderr);1648+expectType<string[]>(execaSync('unicorns', {lines: {all: false, stderr: true}}).stderr);1649+expectType<string[]>(execaSync('unicorns', {lines: {all: false, fd2: true}}).stderr);1650+1651 const linesStdoutResult = await execa('unicorns', {all: true, lines: {stdout: true}});1652 expectType<string[]>(linesStdoutResult.stdout);1653 expectType<string[]>(linesStdoutResult.stdio[1]);1654 expectType<string>(linesStdoutResult.stderr);2479 unmodified lines