Skip to content

armgit / mocha

Public Imported from GitHub
0

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

fix --reporter-option to allow comma-separated options; closes #3706

Christopher Hiller94c932095b4b
diff --git a/lib/cli/run.js b/lib/cli/run.js
index 9fadeb4f..d10b89f6 100644
--- a/lib/cli/run.js
+++ b/lib/cli/run.js
@@ -190,7 +190,7 @@ exports.builder = yargs =>
},
'reporter-option': {
coerce: opts =>
- opts.reduce((acc, opt) => {
+ list(opts).reduce((acc, opt) => {
const pair = opt.split('=');
if (pair.length > 2 || !pair.length) {
diff --git a/test/integration/fixtures/options/reporter-with-options.fixture.js b/test/integration/fixtures/options/reporter-with-options.fixture.js
new file mode 100644
index 00000000..791d6590
--- /dev/null
+++ b/test/integration/fixtures/options/reporter-with-options.fixture.js
@@ -0,0 +1,7 @@
+'use strict';
+
+function ReporterWithOptions(runner, options) {
+ console.log(JSON.stringify(options.reporterOption));
+}
+
+module.exports = ReporterWithOptions;
diff --git a/test/integration/options/reporter-option.spec.js b/test/integration/options/reporter-option.spec.js
index 50d84ca5..976087fb 100644
--- a/test/integration/options/reporter-option.spec.js
+++ b/test/integration/options/reporter-option.spec.js
@@ -1,6 +1,7 @@
'use strict';
var runMocha = require('../helpers').runMocha;
+var path = require('path');
describe('--reporter-option', function() {
describe('when given options w/ invalid format', function() {
@@ -21,5 +22,65 @@ describe('--reporter-option', function() {
'pipe'
);
});
+
+ it('should allow comma-separated values', function(done) {
+ runMocha(
+ 'passing.fixture.js',
+ [
+ '--reporter',
+ path.join(
+ __dirname,
+ '..',
+ 'fixtures',
+ 'options',
+ 'reporter-with-options.fixture.js'
+ ),
+ '--reporter-option',
+ 'foo=bar,baz=quux'
+ ],
+ function(err, res) {
+ if (err) {
+ return done(err);
+ }
+ expect(res, 'to have passed').and(
+ 'to contain output',
+ /{"foo":"bar","baz":"quux"}/
+ );
+ done();
+ },
+ 'pipe'
+ );
+ });
+
+ it('should allow repeated options', function(done) {
+ runMocha(
+ 'passing.fixture.js',
+ [
+ '--reporter',
+ path.join(
+ __dirname,
+ '..',
+ 'fixtures',
+ 'options',
+ 'reporter-with-options.fixture.js'
+ ),
+ '--reporter-option',
+ 'foo=bar',
+ '--reporter-option',
+ 'baz=quux'
+ ],
+ function(err, res) {
+ if (err) {
+ return done(err);
+ }
+ expect(res, 'to have passed').and(
+ 'to contain output',
+ /{"foo":"bar","baz":"quux"}/
+ );
+ done();
+ },
+ 'pipe'
+ );
+ });
});
});