From cdd20c50536da4ce2e54a6877b9cb3e7d8b1a7df Mon Sep 17 00:00:00 2001 From: juergba Date: Sun, 21 Jul 2019 09:53:11 +0200 Subject: [PATCH 1/2] soft deprecate configuration via mocha.opts --- lib/cli/options.js | 3 +++ lib/cli/run.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cli/options.js b/lib/cli/options.js index a88dbfbf17..c7b73ff59d 100644 --- a/lib/cli/options.js +++ b/lib/cli/options.js @@ -230,6 +230,9 @@ const loadMochaOpts = (args = {}) => { // 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`); } diff --git a/lib/cli/run.js b/lib/cli/run.js index bb7c021998..0a5ce4ff1d 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -162,7 +162,7 @@ exports.builder = yargs => }, opts: { default: defaults.opts, - description: 'Path to `mocha.opts`', + description: 'Path to `mocha.opts` (DEPRECATED)', group: GROUPS.CONFIG, normalize: true, requiresArg: true From cdcc7567ce20f8dc65188f169a11962abf8d4b9e Mon Sep 17 00:00:00 2001 From: juergba Date: Mon, 22 Jul 2019 18:20:31 +0200 Subject: [PATCH 2/2] additional test --- test/integration/options/opts.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/integration/options/opts.spec.js b/test/integration/options/opts.spec.js index 51f49fec8b..e3d98581ed 100644 --- a/test/integration/options/opts.spec.js +++ b/test/integration/options/opts.spec.js @@ -10,6 +10,24 @@ 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) {