Skip to content

Throw error if unable to parse Mocha options file #3363

@plroebuck

Description

@plroebuck

Description

The current code silently ignores any problems parsing the options file and continues on.

mocha/bin/options.js

Lines 32 to 47 in 99c2f8a

try {
const opts = fs
.readFileSync(optsPath, 'utf8')
.replace(/\\\s/g, '%20')
.split(/\s/)
.filter(Boolean)
.map(value => value.replace(/%20/g, ' '));
process.argv = process.argv
.slice(0, 2)
.concat(opts.concat(process.argv.slice(2)));
} catch (err) {
// ignore
}
process.env.LOADED_MOCHA_OPTS = true;

Code should instead throw an error for any error encountered, except for a nonexistent default options file (i.e., user did not specify --opts and "test/mocha.opts" does not exist).

Downside?

People who have errors in their "mocha.opts" file will experience failures until corrected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions