From 2b33b4e3eb37e8173302584f22f2a45cfee63c70 Mon Sep 17 00:00:00 2001 From: juergba Date: Tue, 4 Feb 2020 18:00:43 +0100 Subject: [PATCH 1/3] remove configuration via mocha.opts --- example/config/.mocharc.js | 1 - example/config/.mocharc.json | 1 - example/config/.mocharc.jsonc | 1 - example/config/.mocharc.yml | 1 - lib/cli/config.js | 1 - lib/cli/options.js | 89 +------ lib/cli/run-option-metadata.js | 1 - lib/cli/run.js | 7 - lib/mocharc.json | 1 - package-scripts.js | 11 +- .../fixtures/options/help/test/mocha.opts | 1 - .../fixtures/options/opts.fixture.js | 5 - test/integration/options/help.spec.js | 26 -- test/integration/options/opts.spec.js | 64 ----- test/node-unit/cli/options.spec.js | 245 ++---------------- test/opts/mocha.opts | 10 - test/opts/opts.spec.js | 11 - 17 files changed, 23 insertions(+), 453 deletions(-) delete mode 100644 test/integration/fixtures/options/help/test/mocha.opts delete mode 100644 test/integration/fixtures/options/opts.fixture.js delete mode 100644 test/integration/options/help.spec.js delete mode 100644 test/integration/options/opts.spec.js delete mode 100644 test/opts/mocha.opts delete mode 100644 test/opts/opts.spec.js diff --git a/example/config/.mocharc.js b/example/config/.mocharc.js index 671520cd53..46d4e9de1b 100644 --- a/example/config/.mocharc.js +++ b/example/config/.mocharc.js @@ -7,7 +7,6 @@ module.exports = { diff: true, extension: ['js'], - opts: false, package: './package.json', reporter: 'spec', slow: 75, diff --git a/example/config/.mocharc.json b/example/config/.mocharc.json index 43a83e6b0f..fd71460f9a 100644 --- a/example/config/.mocharc.json +++ b/example/config/.mocharc.json @@ -5,7 +5,6 @@ { "diff": true, "extension": ["js"], - "opts": false, "package": "./package.json", "reporter": "spec", "slow": 75, diff --git a/example/config/.mocharc.jsonc b/example/config/.mocharc.jsonc index 25a40b6821..590bf09607 100644 --- a/example/config/.mocharc.jsonc +++ b/example/config/.mocharc.jsonc @@ -5,7 +5,6 @@ { "diff": true, "extension": ["js"], - "opts": false, "package": /* 📦 */ "./package.json", "reporter": /* 📋 */ "spec", "slow": 75, diff --git a/example/config/.mocharc.yml b/example/config/.mocharc.yml index 226f8184ca..da5a0a0c4f 100644 --- a/example/config/.mocharc.yml +++ b/example/config/.mocharc.yml @@ -28,7 +28,6 @@ ignore: inline-diffs: false # needs to be used with grep or fgrep # invert: false -opts: false recursive: false reporter: spec reporter-option: diff --git a/lib/cli/config.js b/lib/cli/config.js index 24de6cd474..1be9f9c4c0 100644 --- a/lib/cli/config.js +++ b/lib/cli/config.js @@ -2,7 +2,6 @@ /** * Responsible for loading / finding Mocha's "rc" files. - * This doesn't have anything to do with `mocha.opts`. * * @private * @module diff --git a/lib/cli/options.js b/lib/cli/options.js index 9fbc22ca0b..9f9f988e70 100644 --- a/lib/cli/options.js +++ b/lib/cli/options.js @@ -2,7 +2,7 @@ /** * Main entry point for handling filesystem-based configuration, - * whether that's `mocha.opts` or a config file or `package.json` or whatever. + * whether that's a config file or `package.json` or whatever. * @module */ @@ -15,7 +15,6 @@ const mocharc = require('../mocharc.json'); const {list} = require('./run-helpers'); const {loadConfig, findConfig} = require('./config'); const findUp = require('find-up'); -const {deprecate} = require('../utils'); const debug = require('debug')('mocha:cli:options'); const {isNodeFlag} = require('./node-flags'); @@ -143,71 +142,6 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => { return result.argv; }; -/** - * - Replaces comments with empty strings - * - Replaces escaped spaces (e.g., 'xxx\ yyy') with HTML space - * - Splits on whitespace, creating array of substrings - * - Filters empty string elements from array - * - Replaces any HTML space with space - * @summary Parses options read from run-control file. - * @private - * @param {string} content - Content read from run-control file. - * @returns {string[]} cmdline options (and associated arguments) - * @ignore - */ -const parseMochaOpts = content => - content - .replace(/^#.*$/gm, '') - .replace(/\\\s/g, '%20') - .split(/\s/) - .filter(Boolean) - .map(value => value.replace(/%20/g, ' ')); - -/** - * Given filepath in `args.opts`, attempt to load and parse a `mocha.opts` file. - * @param {Object} [args] - Arguments object - * @param {string|boolean} [args.opts] - Filepath to mocha.opts; defaults to whatever's in `mocharc.opts`, or `false` to skip - * @returns {external:yargsParser.Arguments|void} If read, object containing parsed arguments - * @memberof module:lib/cli/options - * @see {@link /#mochaopts|mocha.opts} - * @public - */ -const loadMochaOpts = (args = {}) => { - let result; - let filepath = args.opts; - // /dev/null is backwards compat - if (filepath === false || filepath === '/dev/null') { - return result; - } - filepath = filepath || mocharc.opts; - result = {}; - let mochaOpts; - try { - mochaOpts = fs.readFileSync(filepath, 'utf8'); - debug(`read ${filepath}`); - } catch (err) { - if (args.opts) { - throw new Error(`Unable to read ${filepath}: ${err}`); - } - // ignore otherwise. we tried - debug(`No mocha.opts found at ${filepath}`); - } - - // real args should override `mocha.opts` which should override defaults. - // if there's an exception to catch here, I'm not sure what it is. - // by attaching the `no-opts` arg, we avoid re-parsing of `mocha.opts`. - if (mochaOpts) { - deprecate( - 'Configuration via mocha.opts is DEPRECATED and will be removed from a future version of Mocha. Use RC files or package.json instead.' - ); - result = parse(parseMochaOpts(mochaOpts)); - debug(`${filepath} parsed succesfully`); - } - return result; -}; - -module.exports.loadMochaOpts = loadMochaOpts; - /** * Given path to config file in `args.config`, attempt to load & parse config file. * @param {Object} [args] - Arguments object @@ -267,11 +201,10 @@ module.exports.loadPkgRc = loadPkgRc; * 1. Command-line args * 2. RC file (`.mocharc.c?js`, `.mocharc.ya?ml`, `mocharc.json`) * 3. `mocha` prop of `package.json` - * 4. `mocha.opts` - * 5. default configuration (`lib/mocharc.json`) + * 4. default configuration (`lib/mocharc.json`) * * If a {@link module:lib/cli/one-and-dones.ONE_AND_DONE_ARGS "one-and-done" option} is present in the `argv` array, no external config files will be read. - * @summary Parses options read from `mocha.opts`, `.mocharc.*` and `package.json`. + * @summary Parses options read from `.mocharc.*` and `package.json`. * @param {string|string[]} [argv] - Arguments to parse * @public * @memberof module:lib/cli/options @@ -279,7 +212,7 @@ module.exports.loadPkgRc = loadPkgRc; */ const loadOptions = (argv = []) => { let args = parse(argv); - // short-circuit: look for a flag that would abort loading of mocha.opts + // short-circuit: look for a flag that would abort loading of options if ( Array.from(ONE_AND_DONE_ARGS).reduce( (acc, arg) => acc || arg in args, @@ -291,7 +224,6 @@ const loadOptions = (argv = []) => { const rcConfig = loadRc(args); const pkgConfig = loadPkgRc(args); - const optsConfig = loadMochaOpts(args); if (rcConfig) { args.config = false; @@ -301,19 +233,8 @@ const loadOptions = (argv = []) => { args.package = false; args._ = args._.concat(pkgConfig._ || []); } - if (optsConfig) { - args.opts = false; - args._ = args._.concat(optsConfig._ || []); - } - args = parse( - args._, - mocharc, - args, - rcConfig || {}, - pkgConfig || {}, - optsConfig || {} - ); + args = parse(args._, mocharc, args, rcConfig || {}, pkgConfig || {}); // recombine positional arguments and "spec" if (args.spec) { diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index d0bc92ffbe..4648d9fbfe 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -51,7 +51,6 @@ exports.types = { 'config', 'fgrep', 'grep', - 'opts', 'package', 'reporter', 'ui', diff --git a/lib/cli/run.js b/lib/cli/run.js index 014227d569..af8f89bb72 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -163,13 +163,6 @@ exports.builder = yargs => group: GROUPS.OUTPUT, hidden: true }, - opts: { - default: defaults.opts, - description: 'Path to `mocha.opts` (DEPRECATED)', - group: GROUPS.CONFIG, - normalize: true, - requiresArg: true - }, package: { description: 'Path to package.json for config', group: GROUPS.CONFIG, diff --git a/lib/mocharc.json b/lib/mocharc.json index 1ed9157675..51c3fce6a0 100644 --- a/lib/mocharc.json +++ b/lib/mocharc.json @@ -1,7 +1,6 @@ { "diff": true, "extension": ["js", "cjs", "mjs"], - "opts": "./test/mocha.opts", "package": "./package.json", "reporter": "spec", "slow": 75, diff --git a/package-scripts.js b/package-scripts.js index a94de98e40..5e0b1736ef 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -80,8 +80,7 @@ module.exports = { 'test.node.jsapi', 'test.node.requires', 'test.node.reporters', - 'test.node.only', - 'test.node.opts' + 'test.node.only' ].join(' ')}`, description: 'Run Node.js tests' }, @@ -120,14 +119,6 @@ module.exports = { description: 'Run Node.js integration tests', hiddenFromHelp: true }, - opts: { - script: test( - 'opts', - '--opts test/opts/mocha.opts test/opts/opts.spec.js --no-config' - ), - description: 'Run tests concerning mocha.opts', - hiddenFromHelp: true - }, jsapi: { script: 'node test/jsapi', description: 'Run Node.js Mocha JavaScript API tests', diff --git a/test/integration/fixtures/options/help/test/mocha.opts b/test/integration/fixtures/options/help/test/mocha.opts deleted file mode 100644 index 257cc5642c..0000000000 --- a/test/integration/fixtures/options/help/test/mocha.opts +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/test/integration/fixtures/options/opts.fixture.js b/test/integration/fixtures/options/opts.fixture.js deleted file mode 100644 index 359dc1302b..0000000000 --- a/test/integration/fixtures/options/opts.fixture.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -describe('opts', function () { - it('should display this spec', function () {}); -}); diff --git a/test/integration/options/help.spec.js b/test/integration/options/help.spec.js deleted file mode 100644 index fe182bce95..0000000000 --- a/test/integration/options/help.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var path = require('path'); -var helpers = require('../helpers'); -var invokeMocha = helpers.invokeMocha; - -describe('--help', function() { - it('should work despite the presence of "mocha.opts"', function(done) { - var args = ['-h']; - // :NOTE: Must use platform-specific `path.join` for `spawnOpts.cwd` - var fixtureDir = path.join(__dirname, '..', 'fixtures', 'options', 'help'); - var spawnOpts = {cwd: fixtureDir}; - - invokeMocha( - args, - function(err, res) { - if (err) { - return done(err); - } - expect(res.output, 'to contain', 'Run tests with Mocha'); - done(); - }, - spawnOpts - ); - }); -}); diff --git a/test/integration/options/opts.spec.js b/test/integration/options/opts.spec.js deleted file mode 100644 index e3d98581ed..0000000000 --- a/test/integration/options/opts.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -var path = require('path').posix; -var helpers = require('../helpers'); -var runMochaJSON = helpers.runMochaJSON; -var invokeMocha = helpers.invokeMocha; -var resolvePath = helpers.resolveFixturePath; - -describe('--opts', function() { - var args = []; - var fixture = path.join('options', 'opts'); - - it('should print a deprecation warning', function(done) { - var mochaOpts = path.join('test', 'opts', 'mocha.opts'); - args = [resolvePath(fixture), '--opts', mochaOpts]; - invokeMocha( - args, - function(err, res) { - if (err) { - return done(err); - } - - expect(res, 'to have passed'); - expect(res.output, 'to contain', 'mocha.opts is DEPRECATED'); - done(); - }, - 'pipe' - ); - }); - - it('should work despite nonexistent default options file', function(done) { - args = []; - runMochaJSON(fixture, args, function(err, res) { - if (err) { - return done(err); - } - - expect(res, 'to have passed').and('to have passed test count', 1); - done(); - }); - }); - - it('should throw an error due to nonexistent options file', function(done) { - var spawnOpts = {stdio: 'pipe'}; - var nonexistentFile = 'nosuchoptionsfile'; - args = ['--opts', nonexistentFile, resolvePath(fixture)]; - invokeMocha( - args, - function(err, res) { - if (err) { - return done(err); - } - - var pattern = 'unable to read ' + nonexistentFile; - expect(res, 'to satisfy', { - code: 1, - output: new RegExp(pattern, 'i') - }); - done(); - }, - spawnOpts - ); - }); -}); diff --git a/test/node-unit/cli/options.spec.js b/test/node-unit/cli/options.spec.js index 84723bafda..d60de8e268 100644 --- a/test/node-unit/cli/options.spec.js +++ b/test/node-unit/cli/options.spec.js @@ -27,7 +27,6 @@ const defaults = { timeout: 1000, timeouts: 1000, t: 1000, - opts: '/default/path/to/mocha.opts', extension: ['js'] }; @@ -54,8 +53,7 @@ describe('options', function() { * 1. Command-line args * 2. RC file (`.mocharc.js`, `.mocharc.ya?ml`, `mocharc.json`) * 3. `mocha` prop of `package.json` - * 4. `mocha.opts` - * 5. default rc + * 4. default rc */ describe('loadOptions()', function() { describe('when no parameter provided', function() { @@ -63,7 +61,6 @@ describe('options', function() { this.timeout(500); readFileSync = sandbox.stub(); readFileSync.onFirstCall().returns('{}'); - readFileSync.onSecondCall().returns('--retries 3'); findConfig = sandbox.stub().returns('/some/.mocharc.json'); loadConfig = sandbox.stub().returns({}); findupSync = sandbox.stub().returns('/some/package.json'); @@ -83,192 +80,13 @@ describe('options', function() { Object.assign({}, defaults, { _: [], config: false, - opts: false, - package: false, - retries: '3' + package: false }) ); }); }); describe('when parameter provided', function() { - describe('mocha.opts', function() { - describe('when path to mocha.opts (`--opts `) is invalid', function() { - describe('when path is not default', function() { - let opts; - - beforeEach(function() { - opts = '/some/other/path/to/mocha.opts'; - readFileSync = sandbox.stub(); - readFileSync.onFirstCall().returns('{}'); - readFileSync.onSecondCall().throws(); - findConfig = sandbox.stub().returns('/some/.mocharc.json'); - loadConfig = sandbox.stub().returns({}); - findupSync = sandbox.stub().returns('/some/package.json'); - - loadOptions = proxyLoadOptions({ - readFileSync, - findConfig, - loadConfig, - findupSync - }); - }); - - it('should attempt to load file at path', function() { - try { - loadOptions(`--opts ${opts}`); - } catch (ignored) {} - expect(readFileSync, 'to have a call satisfying', [opts, 'utf8']); - }); - - it('should throw', function() { - expect( - () => { - loadOptions(`--opts ${opts}`); - }, - 'to throw', - /unable to read/i - ); - }); - }); - - describe('when path to mocha.opts is unspecified', function() { - let result; - - beforeEach(function() { - readFileSync = sandbox.stub(); - readFileSync.onFirstCall().returns('{}'); - readFileSync.onSecondCall().returns('{}'); - readFileSync.onThirdCall().throws(); - findConfig = sandbox.stub().returns('/some/.mocharc.json'); - loadConfig = sandbox.stub().returns({}); - findupSync = sandbox.stub().returns('/some/package.json'); - - loadOptions = proxyLoadOptions({ - readFileSync, - findConfig, - loadConfig, - findupSync - }); - - result = loadOptions(); - }); - - it('should attempt to load default mocha.opts', function() { - expect(readFileSync, 'to have a call satisfying', [ - defaults.opts, - 'utf8' - ]); - }); - - it('should set opts = false', function() { - expect(result, 'to have property', 'opts', false); - }); - }); - }); - - describe('when path to mocha.opts (`--opts `) is valid', function() { - let result; - beforeEach(function() { - const filepath = '/path/to/mocha.opts'; - readFileSync = sandbox.stub(); - // package.json - readFileSync.onFirstCall().throws(); - // mocha.opts - readFileSync.onSecondCall().returns('--retries 3 foobar.spec.js'); - findConfig = sandbox.stub().returns('/some/.mocharc.json'); - loadConfig = sandbox.stub().returns({}); - findupSync = sandbox.stub().returns('/some/package.json'); - loadOptions = proxyLoadOptions({ - readFileSync, - findConfig, - loadConfig, - findupSync - }); - result = loadOptions(['--opts', filepath]); - }); - - it('should return merged options incl. mocha.opts', function() { - expect( - result, - 'to equal', - Object.assign( - { - _: ['foobar.spec.js'] - }, - defaults, - { - config: false, - opts: false, - package: false, - retries: '3' - } - ) - ); - }); - - it('should have attempted to load two files', function() { - expect(readFileSync, 'was called times', 2).and( - 'to have calls satisfying', - [ - {args: ['/some/package.json', 'utf8']}, - {args: ['/path/to/mocha.opts', 'utf8']} - ] - ); - }); - - it('should set opts = false', function() { - expect(result, 'to have property', 'opts', false); - }); - }); - - describe('when called with opts = false (`--no-opts`)', function() { - let result; - beforeEach(function() { - readFileSync = sandbox - .stub() - .returns('{"mocha": {"check-leaks": false}}'); - findConfig = sandbox.stub().returns('/some/.mocharc.json'); - loadConfig = sandbox.stub().returns({retries: 3}); - findupSync = sandbox.stub().returns('/some/package.json'); - - loadOptions = proxyLoadOptions({ - readFileSync, - findConfig, - loadConfig, - findupSync - }); - - result = loadOptions('--no-opts'); - }); - - it('should return parsed args, default config, config file, and package.json', function() { - expect( - result, - 'to equal', - Object.assign({_: []}, defaults, { - 'check-leaks': false, - config: false, - opts: false, - package: false, - retries: 3 - }) - ); - }); - - it('should not attempt to read any mocha.opts', function() { - expect(readFileSync, 'was called times', 1).and( - 'to have all calls satisfying', - ['/some/package.json', 'utf8'] - ); - }); - - it('should set opts = false', function() { - expect(result, 'to have property', 'opts', false); - }); - }); - }); - describe('package.json', function() { describe('when path to package.json (`--package `) is valid', function() { let result; @@ -278,8 +96,6 @@ describe('options', function() { readFileSync = sandbox.stub(); // package.json readFileSync.onFirstCall().returns('{"mocha": {"retries": 3}}'); - // mocha.opts - readFileSync.onSecondCall().throws(); findConfig = sandbox.stub().returns('/some/.mocharc.json'); loadConfig = sandbox.stub().returns({}); findupSync = sandbox.stub(); @@ -303,7 +119,6 @@ describe('options', function() { defaults, { config: false, - opts: false, package: false, retries: 3 } @@ -325,8 +140,6 @@ describe('options', function() { readFileSync = sandbox.stub(); // package.json readFileSync.onFirstCall().throws('yikes'); - // mocha.opts - readFileSync.onSecondCall().throws(); findConfig = sandbox.stub().returns('/some/.mocharc.json'); loadConfig = sandbox.stub().returns({}); findupSync = sandbox.stub(); @@ -359,8 +172,6 @@ describe('options', function() { readFileSync .onFirstCall() .returns('{"mocha": {"retries": 3, "_": ["foobar.spec.js"]}}'); - // mocha.opts - readFileSync.onSecondCall().throws(); findConfig = sandbox.stub().returns('/some/.mocharc.json'); loadConfig = sandbox.stub().returns({}); findupSync = sandbox.stub().returns(filepath); @@ -384,7 +195,6 @@ describe('options', function() { defaults, { config: false, - opts: false, package: false, retries: 3 } @@ -401,8 +211,7 @@ describe('options', function() { let result; beforeEach(function() { readFileSync = sandbox.stub(); - - readFileSync.onFirstCall().returns('--retries 3'); + readFileSync.onFirstCall().returns('{}'); findConfig = sandbox.stub().returns('/some/path/to/.mocharc.json'); loadConfig = sandbox.stub().returns({'check-leaks': true}); findupSync = sandbox.stub().returns('/some/package.json'); @@ -414,19 +223,18 @@ describe('options', function() { findupSync }); - result = loadOptions('--no-package'); + result = loadOptions('--no-diff --no-package'); }); - it('should return parsed args, default config, package.json and mocha.opts', function() { + it('should return parsed args and default config', function() { expect( result, 'to equal', Object.assign({_: []}, defaults, { + diff: false, 'check-leaks': true, config: false, - opts: false, - package: false, - retries: '3' + package: false }) ); }); @@ -451,7 +259,6 @@ describe('options', function() { .returns( '{"mocha": {"check-leaks": true, "_": ["foobar.spec.js"]}}' ); - readFileSync.onSecondCall().returns('--retries 3 foobar.spec.js'); findConfig = sandbox.stub(); loadConfig = sandbox.stub(); findupSync = sandbox.stub().returns('/some/package.json'); @@ -463,19 +270,18 @@ describe('options', function() { findupSync }); - result = loadOptions('--no-config'); + result = loadOptions('--no-diff --no-config'); }); - it('should return parsed args, default config, package.json and mocha.opts', function() { + it('should return parsed args, default config and package.json', function() { expect( result, 'to equal', Object.assign({_: ['foobar.spec.js']}, defaults, { + diff: false, 'check-leaks': true, config: false, - opts: false, - package: false, - retries: '3' + package: false }) ); }); @@ -500,7 +306,6 @@ describe('options', function() { readFileSync = sandbox.stub(); config = '/some/.mocharc.json'; readFileSync.onFirstCall().returns('{}'); - readFileSync.onSecondCall().returns('--retries 3'); findConfig = sandbox.stub(); loadConfig = sandbox.stub().throws('Error', 'failed to parse'); findupSync = sandbox.stub().returns('/some/package.json'); @@ -613,30 +418,13 @@ describe('options', function() { }); describe('config priority', function() { - it('should prioritize mocha.opts over defaults', function() { - readFileSync = sandbox.stub(); - readFileSync.onFirstCall().returns('{}'); - readFileSync.onSecondCall().returns('--timeout 800 --require foo'); - findConfig = sandbox.stub().returns('/some/.mocharc.json'); - loadConfig = sandbox.stub().returns({}); - findupSync = sandbox.stub().returns('/some/package.json'); - - loadOptions = proxyLoadOptions({ - readFileSync, - findConfig, - loadConfig, - findupSync - }); - - expect(loadOptions(), 'to satisfy', {timeout: '800', require: ['foo']}); - }); - - it('should prioritize package.json over mocha.opts', function() { + it('should prioritize package.json over defaults', function() { readFileSync = sandbox.stub(); readFileSync .onFirstCall() - .returns('{"mocha": {"timeout": 700, "require": "bar"}}'); - readFileSync.onSecondCall().returns('--timeout 800 --require foo'); + .returns( + '{"mocha": {"timeout": 700, "require": "bar", "extension": "ts"}}' + ); findConfig = sandbox.stub().returns('/some/.mocharc.json'); loadConfig = sandbox.stub().returns({}); findupSync = sandbox.stub().returns('/some/package.json'); @@ -650,7 +438,8 @@ describe('options', function() { expect(loadOptions(), 'to satisfy', { timeout: 700, - require: ['bar', 'foo'] + require: ['bar'], + extension: ['ts'] }); }); diff --git a/test/opts/mocha.opts b/test/opts/mocha.opts deleted file mode 100644 index c212a5b0d3..0000000000 --- a/test/opts/mocha.opts +++ /dev/null @@ -1,10 +0,0 @@ -### -### mocha.opts -### - ---require test/setup ---ui bdd ---globals okGlobalA,okGlobalB ---globals okGlobalC ---globals callback* ---timeout 300 diff --git a/test/opts/opts.spec.js b/test/opts/opts.spec.js deleted file mode 100644 index 74860421a8..0000000000 --- a/test/opts/opts.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -// as of this writing we're using a config file instead of mocha.opts, -// so to run this test, we must use `--opts test/opts/mocha.opts` -// and `--no-config`. -describe('--opts', function() { - it('should use options present in test `mocha.opts`', function() { - // this will fail if config file was used and/or mocha.opts didn't load. - expect(this.timeout(), 'to be', 300); - }); -}); From 35a319768fe443f71bf25ca77a41a0b3d56952fd Mon Sep 17 00:00:00 2001 From: juergba Date: Sat, 8 Feb 2020 17:36:30 +0100 Subject: [PATCH 2/3] exit upon --opts option --- lib/cli/run.js | 7 +++++++ test/integration/options/opts.spec.js | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/integration/options/opts.spec.js diff --git a/lib/cli/run.js b/lib/cli/run.js index af8f89bb72..d024cbb0f2 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -278,6 +278,13 @@ exports.builder = yargs => ); } + if (argv.opts) { + throw createUnsupportedError( + `--opts: configuring Mocha via 'mocha.opts' is DEPRECATED and no longer supported. + Please use a configuration file instead.` + ); + } + // load requires first, because it can impact "plugin" validation handleRequires(argv.require); validatePlugin(argv, 'reporter', Mocha.reporters); diff --git a/test/integration/options/opts.spec.js b/test/integration/options/opts.spec.js new file mode 100644 index 0000000000..30b129f316 --- /dev/null +++ b/test/integration/options/opts.spec.js @@ -0,0 +1,23 @@ +'use strict'; + +var invokeMocha = require('../helpers').invokeMocha; + +describe('--opts', function() { + it('should report deprecation', function(done) { + invokeMocha( + ['--opts', './test/mocha.opts'], + function(err, res) { + if (err) { + return done(err); + } + expect( + res, + 'to have failed with output', + /'mocha.opts' is DEPRECATED/i + ); + done(); + }, + 'pipe' + ); + }); +}); From 54e3c89075edd3b83b7c6b71241a749b6ba89788 Mon Sep 17 00:00:00 2001 From: juergba Date: Wed, 5 Feb 2020 11:03:14 +0100 Subject: [PATCH 3/3] docs --- docs/index.md | 54 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/docs/index.md b/docs/index.md index 1ef8793f96..898d8f1de5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,7 +36,6 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in - [auto-exit to prevent "hanging" with an active loop](#-exit) - [easily meta-generate suites](#markdown) & [test-cases](#list) - [config file support](#-config-path) -- [mocha.opts file support](#-opts-path) - clickable suite titles to filter test execution - [node debugger support](#-inspect-inspect-brk-inspect) - [node native ES modules support](#nodejs-native-esm-support) @@ -75,7 +74,6 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in - [Running Mocha in the Browser](#running-mocha-in-the-browser) - [Desktop Notification Support](#desktop-notification-support) - [Configuring Mocha (Node.js)](#configuring-mocha-nodejs) -- [`mocha.opts`](#mochaopts) - [The `test/` Directory](#the-test-directory) - [Error Codes](#error-codes) - [Editor Plugins](#editor-plugins) @@ -865,8 +863,6 @@ Reporting & Output Configuration --config Path to config file [string] [default: (nearest rc file)] - --opts Path to `mocha.opts` (DEPRECATED) - [string] [default: "./test/mocha.opts"] --package Path to package.json for config [string] File Handling @@ -1070,11 +1066,7 @@ By default, Mocha will search for a config file if `--config` is not specified; ### `--opts ` -> _Deprecated in v7.0.0._ - -Specify a path to [`mocha.opts`](#mochaopts). - -By default, Mocha looks for a `mocha.opts` in `test/mocha.opts`; use `--no-opts` to suppress this behavior. +> _Removed in v8.0.0. Please use [configuration file](#configuring-mocha-nodejs) instead._ ### `--package ` @@ -1738,7 +1730,7 @@ tests as shown below: > _New in v6.0.0_ -In addition to supporting the deprecated [`mocha.opts`](#mochaopts) run-control format, Mocha now supports configuration files, typical of modern command-line tools, in several formats: +Mocha supports configuration files, typical of modern command-line tools, in several formats: - **JavaScript**: Create a `.mocharc.js` (or `mocharc.cjs` when using [`"type"="module"`](#nodejs-native-esm-support) in your `package.json`) in your project's root directory, and export an object (`module.exports = {/* ... */}`) containing your configuration. @@ -1746,8 +1738,6 @@ In addition to supporting the deprecated [`mocha.opts`](#mochaopts) run-control - **JSON**: Create a `.mocharc.json` (or `.mocharc.jsonc`) in your project's root directory. Comments — while not valid JSON — are allowed in this file, and will be ignored by Mocha. - **package.json**: Create a `mocha` property in your project's `package.json`. -Mocha suggests using one of the above strategies for configuration instead of the deprecated `mocha.opts` format. - ### Custom Locations You can specify a custom location for your configuration file with the `--config ` option. Mocha will use the file's extension to determine how to parse the file, and will assume JSON if unknown. @@ -1770,12 +1760,11 @@ If no custom path was given, and if there are multiple configuration files in th ### Merging -Mocha will also _merge_ any options found in `package.json` _and_ `mocha.opts` into its run-time configuration. In case of conflict, the priority is: +Mocha will also _merge_ any options found in `package.json` into its run-time configuration. In case of conflict, the priority is: 1. Arguments specified on command-line 1. Configuration file (`.mocharc.js`, `.mocharc.yml`, etc.) 1. `mocha` property of `package.json` -1. `mocha.opts` Options which can safely be repeated (e.g., `--require`) will be _concatenated_, with higher-priorty configuration sources appearing earlier in the list. For example, a `.mocharc.json` containing `"require": "bar"`, coupled with execution of `mocha --require foo`, would cause Mocha to require `foo`, then `bar`, in that order. @@ -1790,45 +1779,10 @@ Configurations can inherit from other modules using the `extends` keyword. See [ - For options containing a dash (`-`), the option name can be specified using camelCase. - Aliases are valid names, e.g., `R` instead of `reporter`. - Test files can be specified using `spec`, e.g., `"spec": "test/**/*.spec.js"`. -- Flags to `node` are _also_ supported in configuration files, like in `mocha.opts`. Use caution, as these can vary between versions of Node.js! +- Flags to `node` are _also_ supported in configuration files. Use caution, as these can vary between versions of Node.js! **For more configuration examples, see the [`example/config`][example-mocha-config] directory on GitHub.** -## `mocha.opts` - -> _`mocha.opts` file support is DEPRECATED and will be removed from a future version of Mocha. We recommend using a configuration file instead._ - -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: - -```bash -# mocha.opts - --require should - --reporter dot - --ui bdd -``` - -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 changing the reporter to `list` and setting the -slow threshold to half a second: - -```bash -$ mocha --reporter list --slow 500 -``` - -To ignore your `mocha.opts`, use the `--no-opts` option. - ## The `test/` Directory By default, `mocha` looks for the glob `"./test/*.js"`, so you may want to put