Skip to content

Commit 94c9320

Browse files
committed
fix --reporter-option to allow comma-separated options; closes #3706
Signed-off-by: Christopher Hiller <[email protected]>
1 parent 0f546fc commit 94c9320

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

lib/cli/run.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ exports.builder = yargs =>
190190
},
191191
'reporter-option': {
192192
coerce: opts =>
193-
opts.reduce((acc, opt) => {
193+
list(opts).reduce((acc, opt) => {
194194
const pair = opt.split('=');
195195

196196
if (pair.length > 2 || !pair.length) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
function ReporterWithOptions(runner, options) {
4+
console.log(JSON.stringify(options.reporterOption));
5+
}
6+
7+
module.exports = ReporterWithOptions;

test/integration/options/reporter-option.spec.js

+61
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var runMocha = require('../helpers').runMocha;
4+
var path = require('path');
45

56
describe('--reporter-option', function() {
67
describe('when given options w/ invalid format', function() {
@@ -21,5 +22,65 @@ describe('--reporter-option', function() {
2122
'pipe'
2223
);
2324
});
25+
26+
it('should allow comma-separated values', function(done) {
27+
runMocha(
28+
'passing.fixture.js',
29+
[
30+
'--reporter',
31+
path.join(
32+
__dirname,
33+
'..',
34+
'fixtures',
35+
'options',
36+
'reporter-with-options.fixture.js'
37+
),
38+
'--reporter-option',
39+
'foo=bar,baz=quux'
40+
],
41+
function(err, res) {
42+
if (err) {
43+
return done(err);
44+
}
45+
expect(res, 'to have passed').and(
46+
'to contain output',
47+
/{"foo":"bar","baz":"quux"}/
48+
);
49+
done();
50+
},
51+
'pipe'
52+
);
53+
});
54+
55+
it('should allow repeated options', function(done) {
56+
runMocha(
57+
'passing.fixture.js',
58+
[
59+
'--reporter',
60+
path.join(
61+
__dirname,
62+
'..',
63+
'fixtures',
64+
'options',
65+
'reporter-with-options.fixture.js'
66+
),
67+
'--reporter-option',
68+
'foo=bar',
69+
'--reporter-option',
70+
'baz=quux'
71+
],
72+
function(err, res) {
73+
if (err) {
74+
return done(err);
75+
}
76+
expect(res, 'to have passed').and(
77+
'to contain output',
78+
/{"foo":"bar","baz":"quux"}/
79+
);
80+
done();
81+
},
82+
'pipe'
83+
);
84+
});
2485
});
2586
});

0 commit comments

Comments
 (0)