Skip to content

Commit

Permalink
fix --reporter-option to allow comma-separated options; closes #3706
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hiller <[email protected]>
  • Loading branch information
boneskull committed Feb 11, 2019
1 parent 186ca36 commit 9be633b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

function ReporterWithOptions(runner, options) {
console.log(JSON.stringify(options.reporterOption));
}

module.exports = ReporterWithOptions;
61 changes: 61 additions & 0 deletions test/integration/options/reporter-option.spec.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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'
);
});
});
});

0 comments on commit 9be633b

Please sign in to comment.