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

Do not silently fail on bad opts argument #2716

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions bin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ module.exports = getOptions;
*/

function getOptions () {
var optsPath = process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];
var defaultPath = 'test/mocha.opts';

var optsIndex = process.argv.indexOf('--opts');
var optsPath = optsIndex === -1
? defaultPath
: process.argv[optsIndex + 1];
var shouldThrowError = optsIndex !== -1;
Copy link
Contributor

@dasilvacontin dasilvacontin Jun 4, 2017

Choose a reason for hiding this comment

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

I'd rename this to wasOptsProvided. It makes the code / reasoning more clearer imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind the feedback in case the variable is no longer necessary.


try {
var opts = fs.readFileSync(optsPath, 'utf8')
Expand All @@ -34,7 +38,9 @@ function getOptions () {
.slice(0, 2)
.concat(opts.concat(process.argv.slice(2)));
} catch (err) {
// ignore
if (shouldThrowError) {
throw new Error(err);
}
}

process.env.LOADED_MOCHA_OPTS = true;
Expand Down