From a9745f100322114fbe8f73e77a678be4e45a0ed4 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Thu, 3 May 2018 17:10:22 -0500 Subject: [PATCH 1/2] feat(bin/options.js): Add support for comment lines in "mocha.opts" Modified code to strip comment lines, those beginning with a hash character ('#'), from "mocha.opts" prior to processing its contents. Fixes #3370 --- bin/options.js | 1 + test/integration/regression.spec.js | 1 + test/mocha.opts | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/bin/options.js b/bin/options.js index 60cbcd705e..a25a18e28e 100644 --- a/bin/options.js +++ b/bin/options.js @@ -32,6 +32,7 @@ function getOptions() { try { const opts = fs .readFileSync(optsPath, 'utf8') + .replace(/^#.*$/gm, '') .replace(/\\\s/g, '%20') .split(/\s/) .filter(Boolean) diff --git a/test/integration/regression.spec.js b/test/integration/regression.spec.js index e1f6b19dde..92f2223c7a 100644 --- a/test/integration/regression.spec.js +++ b/test/integration/regression.spec.js @@ -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( diff --git a/test/mocha.opts b/test/mocha.opts index c233b95260..c6f308ee28 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,6 +1,11 @@ +### +### mocha.opts +### + --require ./test/setup --ui bdd --globals okGlobalA,okGlobalB --globals okGlobalC --globals callback* --timeout 200 + From ddd15ed38385c24b7b88e2265d97cd948b003611 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Sat, 5 May 2018 10:26:34 -0500 Subject: [PATCH 2/2] docs(docs/index.md): Update "mocha.opts" documentation Added information on file content, noting support for comment/blank lines. --- docs/index.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index a5acfc9945..b56610e043 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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