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

3363: Throw error if unable to parse Mocha options file #3376

Closed
wants to merge 4 commits into from
Closed
Changes from 3 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: 20 additions & 11 deletions bin/options.js
Expand Up @@ -24,10 +24,12 @@ function getOptions() {
return;
}

const optsPath =
process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];
const optsIndex = process.argv.indexOf('--opts');
const optsPathSpecified = optsIndex !== -1;
const defaultOptsPath = 'test/mocha.opts';
const optsPath = optsPathSpecified
? process.argv[optsIndex + 1]
: defaultOptsPath;

try {
const opts = fs
Expand All @@ -37,12 +39,19 @@ function getOptions() {
.filter(Boolean)
.map(value => value.replace(/%20/g, ' '));

process.argv = process.argv
.slice(0, 2)
.concat(opts.concat(process.argv.slice(2)));
} catch (ignore) {
// NOTE: should console.error() and throw the error
if (opts.length > 0) {
process.argv = process.argv
.slice(0, 2)
.concat(opts.concat(process.argv.slice(2)));
}
} catch (err) {
// Default options file may not exist - rethrow anything else
if (optsPathSpecified || err.code !== 'ENOENT') {
console.error(`failed to load Mocha options file: ${optsPath}`);
throw err;
}
} finally {
// Despite its name, signifies loading was attempted and should not be again
process.env.LOADED_MOCHA_OPTS = '1';
}

process.env.LOADED_MOCHA_OPTS = true;
}