Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent empty default value in CLI options #3441

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 19 additions & 12 deletions bin/_mocha
Expand Up @@ -82,7 +82,12 @@ const list = str => str.split(/ *, */);
/**
* Parse multiple flag.
*/
const collect = (val, memo) => memo.concat(val);
const collect = (val, memo) => {
if (!memo) {
memo = [];
}
return memo.concat(val);
};

/**
* Hide the cursor.
Expand Down Expand Up @@ -171,15 +176,13 @@ program
.option(
'--compilers <ext>:<module>,...',
'use the given module(s) to compile files',
list,
[]
list
)
.option('--debug-brk', "enable node's debugger breaking on the first line")
.option(
'--globals <names>',
'allow the given comma-delimited global [names]',
list,
[]
list
)
.option('--es_staging', 'enable all staged features')
.option(
Expand Down Expand Up @@ -241,13 +244,8 @@ program
'--forbid-pending',
'causes pending tests and test marked with skip to fail the suite'
)
.option(
'--file <file>',
'include a file to be ran during the suite',
collect,
[]
)
.option('--exclude <file>', 'a file or glob pattern to ignore', collect, []);
.option('--file <file>', 'include a file to be ran during the suite', collect)
.option('--exclude <file>', 'a file or glob pattern to ignore', collect);

program._name = 'mocha';

Expand Down Expand Up @@ -472,6 +470,9 @@ if (program.forbidPending) mocha.forbidPending();

// custom compiler support

if (!program.compilers) {
program.compilers = [];
}
if (program.compilers.length > 0) {
require('util').deprecate(() => {},
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
Expand Down Expand Up @@ -506,6 +507,9 @@ const args = program.args;

// default files to test/*.{js,coffee}

if (!program.exclude) {
program.exclude = [];
}
if (!args.length) {
args.push('test');
}
Expand Down Expand Up @@ -543,6 +547,9 @@ if (!files.length) {
}

// resolve
if (!program.file) {
program.file = [];
}
let fileArgs = program.file.map(path => resolve(path));
files = files.map(path => resolve(path));

Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Expand Up @@ -763,9 +763,9 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass
-w, --watch watch files for changes
--check-leaks check for global variable leaks
--full-trace display the full stack trace
--compilers <ext>:<module>,... use the given module(s) to compile files (default: )
--compilers <ext>:<module>,... use the given module(s) to compile files
Copy link
Contributor

@plroebuck plroebuck Sep 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for all of these README changes, why did you remove the default text altogether rather than just adding [] where it was missing?

--debug-brk enable node's debugger breaking on the first line
--globals <names> allow the given comma-delimited global [names] (default: )
--globals <names> allow the given comma-delimited global [names]
--es_staging enable all staged features
--harmony<_classes,_generators,...> all node --harmony* flags are available
--preserve-symlinks Instructs the module loader to preserve symbolic links when resolving and caching modules
Expand Down Expand Up @@ -797,8 +797,8 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass
--allow-uncaught enable uncaught errors to propagate
--forbid-only causes test marked with only to fail the suite
--forbid-pending causes pending tests and test marked with skip to fail the suite
--file <file> include a file to be ran during the suite (default: )
--exclude <file> a file or glob pattern to ignore (default: )
--file <file> include a file to be ran during the suite
--exclude <file> a file or glob pattern to ignore
-h, --help output usage information

Commands:
Expand Down