From 21aa6440e7842e63c767baa1fa0fa24c5c76589e Mon Sep 17 00:00:00 2001 From: Christian Holm Date: Tue, 14 Jan 2020 09:54:04 +0100 Subject: [PATCH] closes #4142 In https://github.com/mochajs/mocha/pull/4004 there was a change to use the documented `reporterOption` in favour of the setting that had always been used in practice called `reporterOptions`. This broke a lot of configurations that used the `reporterOptions`, which was the only way it every worked AFAIK. This changes the documentation to specify `reporterOptions` instead and ensure that any one that has switched to `reporterOption` after upgrade, still works. --- lib/mocha.js | 10 ++++++---- .../options/reporter-with-options.fixture.js | 2 +- test/unit/mocha.spec.js | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/mocha.js b/lib/mocha.js index d306f995cd..9a7bd5ae87 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -84,7 +84,7 @@ exports.Test = require('./test'); * @param {boolean} [options.invert] - Invert test filter matches? * @param {boolean} [options.noHighlighting] - Disable syntax highlighting? * @param {string|constructor} [options.reporter] - Reporter name or constructor. - * @param {Object} [options.reporterOption] - Reporter settings object. + * @param {Object} [options.reporterOptions] - Reporter settings object. * @param {number} [options.retries] - Number of times to retry failed tests. * @param {number} [options.slow] - Slow threshold value. * @param {number|string} [options.timeout] - Timeout threshold value. @@ -100,7 +100,10 @@ function Mocha(options) { this.grep(options.grep) .fgrep(options.fgrep) .ui(options.ui) - .reporter(options.reporter, options.reporterOption) + .reporter( + options.reporter, + options.reporterOptions || options.reporterOption // reporterOption was previously documented (but not used) + ) .slow(options.slow) .global(options.global); @@ -229,9 +232,8 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) { } this._reporter = _reporter; } - this.options.reporterOption = reporterOptions; - // alias option name is used in public reporters xunit/tap/progress this.options.reporterOptions = reporterOptions; + return this; }; diff --git a/test/integration/fixtures/options/reporter-with-options.fixture.js b/test/integration/fixtures/options/reporter-with-options.fixture.js index 791d65909e..625728cd21 100644 --- a/test/integration/fixtures/options/reporter-with-options.fixture.js +++ b/test/integration/fixtures/options/reporter-with-options.fixture.js @@ -1,7 +1,7 @@ 'use strict'; function ReporterWithOptions(runner, options) { - console.log(JSON.stringify(options.reporterOption)); + console.log(JSON.stringify(options.reporterOptions)); } module.exports = ReporterWithOptions; diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js index 71d804814c..8c583a6c6a 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -446,6 +446,26 @@ describe('Mocha', function() { var mocha = new Mocha(opts); expect(mocha.reporter(), 'to be', mocha); }); + + it('should keep reporterOptions on options', function() { + var mocha = new Mocha({ + reporter: 'spec', + reporterOptions: { + foo: 'bar' + } + }); + expect(mocha.options.reporterOptions, 'to have property', 'foo', 'bar'); + }); + + it('should alias legacy reporterOption to reporterOptions', function() { + var mocha = new Mocha({ + reporter: 'spec', + reporterOption: { + foo: 'bar' + } + }); + expect(mocha.options.reporterOptions, 'to have property', 'foo', 'bar'); + }); }); describe('#run(fn)', function() {