diff --git a/lib/mocha.js b/lib/mocha.js index d306f995cd..0b43004abc 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); diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js index 71d804814c..33cd0fdb8e 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -446,6 +446,30 @@ 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'); + // To support the legacy property name that can be used by reporters + 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'); + // To support the legacy property name that can be used by reporters + expect(mocha.options.reporterOptions, 'to have property', 'foo', 'bar'); + }); }); describe('#run(fn)', function() {