Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cli/run.js
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
@@ -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
@@ -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'
);
});
});
});