Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fix backwards compability break for reporterOptions

Christian Holm9c10adab3340
diff --git a/lib/mocha.js b/lib/mocha.js
index d306f995..0b43004a 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 71d80481..33cd0fdb 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() {