Validate `verbose` option (#990)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent be91ecf · Browse files · 3 files·+39 added−1 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+39 added−1 removed
- tests:+19 added−1 removed
- other:+20 added−0 removed
Provenance
- Commit
f092dec- Tree
cdbad4c- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
be91ecf
3 files changed+39 added−1 removed
modified:lib/verbose/info.js+20 added
4 unmodified lines56789101112134 unmodified lines18192021222324252627282930313233343536373839404 unmodified lines
// Information computed before spawning, used by the `verbose` optionexport const getVerboseInfo = verbose => { const verboseId = isVerbose(verbose) ? VERBOSE_ID++ : undefined; validateVerbose(verbose); return {verbose, verboseId};};
// Prepending the `pid` is useful when multiple commands print their output at the same time.4 unmodified lineslet VERBOSE_ID = 0n;
// The `verbose` option can have different values for `stdout`/`stderr`export const isVerbose = verbose => verbose.some(fdVerbose => fdVerbose !== 'none');
const validateVerbose = verbose => { for (const verboseItem of verbose) { if (verboseItem === false) { throw new TypeError('The "verbose: false" option was renamed to "verbose: \'none\'".'); }
if (verboseItem === true) { throw new TypeError('The "verbose: true" option was renamed to "verbose: \'short\'".'); }
if (!VERBOSE_VALUES.has(verboseItem)) { const allowedValues = [...VERBOSE_VALUES].map(allowedValue => `'${allowedValue}'`).join(', '); throw new TypeError(`The "verbose" option must not be ${verboseItem}. Allowed values are: ${allowedValues}.`); } }};
const VERBOSE_VALUES = new Set(['none', 'short', 'full']);modified:test/verbose/info.js+18 added
40 unmodified lines4142434445464748495051525354555657585960616240 unmodified lines};
test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, parentExecaAsync);test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, parentExecaSync);
const invalidFalseMessage = 'renamed to "verbose: \'none\'"';const invalidTrueMessage = 'renamed to "verbose: \'short\'"';const invalidUnknownMessage = 'Allowed values are: \'none\', \'short\', \'full\'';
const testInvalidVerbose = (t, verbose, expectedMessage, execaMethod) => { const {message} = t.throws(() => { execaMethod('empty.js', {verbose}); }); t.true(message.includes(expectedMessage));};
test('Does not allow "verbose: false"', testInvalidVerbose, false, invalidFalseMessage, execa);test('Does not allow "verbose: false", sync', testInvalidVerbose, false, invalidFalseMessage, execaSync);test('Does not allow "verbose: true"', testInvalidVerbose, true, invalidTrueMessage, execa);test('Does not allow "verbose: true", sync', testInvalidVerbose, true, invalidTrueMessage, execaSync);test('Does not allow "verbose: \'unknown\'"', testInvalidVerbose, 'unknown', invalidUnknownMessage, execa);test('Does not allow "verbose: \'unknown\'", sync', testInvalidVerbose, 'unknown', invalidUnknownMessage, execaSync);modified:test/verbose/output-enable.js+1 added-1 removed
120 unmodified lines121 t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);122 });123 124 const testStdioSame = async (t, fdNumber) => {125- const {stdio} = await nestedExecaAsync('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: true});125+ const {stdio} = await nestedExecaAsync('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: 'full'});126 t.is(stdio[fdNumber], foobarString);127 };128 129 test('Does not change subprocess.stdout', testStdioSame, 1);17 unmodified lines