From 9be633bce7a5b295ff113daed954c6958758a08a Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Sun, 10 Feb 2019 11:42:06 -0800 Subject: [PATCH] fix --reporter-option to allow comma-separated options; closes #3706 Signed-off-by: Christopher Hiller --- lib/cli/run.js | 2 +- .../options/reporter-with-options.fixture.js | 7 +++ .../options/reporter-option.spec.js | 61 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/options/reporter-with-options.fixture.js diff --git a/lib/cli/run.js b/lib/cli/run.js index 9fadeb4f3e..d10b89f637 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 0000000000..791d65909e --- /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 50d84ca597..976087fb02 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' + ); + }); }); });