diff --git a/lib/mocha.js b/lib/mocha.js index d306f995cd..be641d9a64 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -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.reporterOption || options.reporterOptions // reporterOptions was previously the only way to specify options to reporter + ) .slow(options.slow) .global(options.global); @@ -232,6 +235,7 @@ Mocha.prototype.reporter = function(reporter, reporterOptions) { 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..0a3000090b 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -446,6 +446,36 @@ describe('Mocha', function() { var mocha = new Mocha(opts); expect(mocha.reporter(), 'to be', mocha); }); + + it('should keep reporterOption on options', function() { + var mocha = new Mocha({ + reporter: 'spec', + reporterOption: { + foo: 'bar' + } + }); + expect(mocha.options.reporterOption, 'to have property', 'foo', 'bar'); + }); + + it('should alias reporterOption to legacy reporterOptions', function() { + var mocha = new Mocha({ + reporter: 'spec', + reporterOption: { + foo: 'bar' + } + }); + expect(mocha.options.reporterOptions, 'to have property', 'foo', 'bar'); + }); + + it('should support legacy reporterOptions', function() { + var mocha = new Mocha({ + reporter: 'spec', + reporterOptions: { + foo: 'bar' + } + }); + expect(mocha.options.reporterOption, 'to have property', 'foo', 'bar'); + }); }); describe('#run(fn)', function() {