Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
fix --reporter-option to allow comma-separated options; closes mochaj…
Browse files Browse the repository at this point in the history
…s#3706

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Feb 13, 2019
1 parent 4d0b516 commit fd41d18
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 fd41d18

Please sign in to comment.