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

3370: Add support for comment lines in "mocha.opts" #3375

Merged
merged 2 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions bin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function getOptions() {
try {
const opts = fs
.readFileSync(optsPath, 'utf8')
.replace(/^#.*$/gm, '')
.replace(/\\\s/g, '%20')
.split(/\s/)
.filter(Boolean)
Expand Down
21 changes: 19 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,32 @@ The "HTML" reporter is what you see when running Mocha in the browser. It looks

## `mocha.opts`

Back on the server, Mocha will attempt to load `./test/mocha.opts` as a configuration file of sorts. The lines in this file are combined with any command-line arguments. The command-line arguments take precedence. For example, suppose you have the following `mocha.opts` file:
Back on the server, Mocha will attempt to load `"./test/mocha.opts"` as a
Run-Control file of sorts.

Beginning-of-line comment support is available; any line _starting_ with a
hash (#) symbol will be considered a comment. Blank lines may also be used.
Any other line will be treated as a command-line argument (along with any
associated option value) to be used as a default setting. Settings should be
specified one per line.

The lines in this file are prepended to any actual command-line arguments.
As such, actual command-line arguments will take precedence over the defaults.

For example, suppose you have the following `mocha.opts` file:

```sh
# mocha.opts

--require should
--reporter dot
--ui bdd
```

This will default the reporter to `dot`, require the `should` library, and use `bdd` as the interface. With this, you may then invoke `mocha` with additional arguments, here enabling [Growl](http://growl.info) support, and changing the reporter to `list`:
The settings above will default the reporter to `dot`, require the `should`
library, and use `bdd` as the interface. With this, you may then invoke `mocha`
with additional arguments, here enabling [Growl](http://growl.info/) support,
and changing the reporter to `list`:

```sh
$ mocha --reporter list --growl
Expand Down
1 change: 1 addition & 0 deletions test/integration/regression.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('regressions', function() {
var processArgv = process.argv.join('');
var mochaOpts = fs
.readFileSync(path.join(__dirname, '..', 'mocha.opts'), 'utf-8')
.replace(/^#.*$/gm, '')
.split(/[\s]+/)
.join('');
assert.notEqual(
Expand Down
5 changes: 5 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
###
### mocha.opts
###

--require ./test/setup
--ui bdd
--globals okGlobalA,okGlobalB
--globals okGlobalC
--globals callback*
--timeout 200