diff --git a/.ncurc.js b/.ncurc.js new file mode 100644 index 0000000..0849ced --- /dev/null +++ b/.ncurc.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = { + // Whitelist all for checking besides `peer` which indicates + // somewhat older versions of `eslint` we still support even + // while our devDeps point to a more recent version + "dep": "prod,dev,optional,bundle" +}; diff --git a/lib/MultiReporters.js b/lib/MultiReporters.js index a080a88..748d380 100644 --- a/lib/MultiReporters.js +++ b/lib/MultiReporters.js @@ -46,7 +46,12 @@ function MultiReporters(runner, options) { if (_.get(options, 'execute', true)) { options = this.getOptions(options); - this._reporters = _.get(options, 'reporterEnabled', 'tap').split(',').map( + let enabledReporters = _.get(options, 'reporterEnabled', 'tap'); + if (!Array.isArray(enabledReporters)) { + enabledReporters = enabledReporters.split(','); + } + + this._reporters = enabledReporters.map( function processReporterEnabled(name, index) { debug(name, index); @@ -137,7 +142,7 @@ MultiReporters.prototype.getOptions = function (options) { const cmrOutput = _.get(options, 'reporterOptions.cmrOutput'); const resultantOptions = _.merge({}, this.getDefaultOptions(), this.getCustomOptions(options), cmrOutput ? {cmrOutput} : null); - + debug('options file (resultant)', resultantOptions); return resultantOptions; }; @@ -203,10 +208,14 @@ MultiReporters.prototype.getReporterOptions = function (options, name) { const resultantReporterOptions = _.merge({}, commonReporterOptions, customReporterOptions); debug('reporter options (resultant)', _name, resultantReporterOptions); - const cmrOutput = _.get(options, 'cmrOutput'); + let cmrOutput = _.get(options, 'cmrOutput'); if (cmrOutput) { - cmrOutput.split(':').forEach((cmrOutputReporter) => { - const [targetName, prop, output] = cmrOutputReporter.split('+'); + if (!Array.isArray(cmrOutput)) { + cmrOutput = cmrOutput.split(':').map((cmrOutputReporter) => { + return cmrOutputReporter.split('+'); + }); + } + cmrOutput.forEach(([targetName, prop, output]) => { if (resultantReporterOptions[prop] && _name === targetName) { resultantReporterOptions[prop] = resultantReporterOptions[prop].replace(/\{id\}/gu, output); } diff --git a/tests/custom-internal-config-array.json b/tests/custom-internal-config-array.json new file mode 100644 index 0000000..73cdfed --- /dev/null +++ b/tests/custom-internal-config-array.json @@ -0,0 +1,7 @@ +{ + "reporterEnabled": ["dot", "tests/custom-internal-reporter"], + + "xunitReporterOptions": { + "output": "artifacts/test/custom-xunit.xml" + } +} diff --git a/tests/lib/MultiReporters.test.js b/tests/lib/MultiReporters.test.js index c1300c1..7c05455 100644 --- a/tests/lib/MultiReporters.test.js +++ b/tests/lib/MultiReporters.test.js @@ -180,6 +180,24 @@ describe('lib/MultiReporters', function () { }); }); + describe('#custom-internal-reporter (array config)', function () { + beforeEach(function() { + options = { + execute: true, + reporterOptions: { + configFile: 'tests/custom-internal-config-array.json' + } + }; + reporter = new mocha._reporter(runner, options); + }); + + it('return default options for "custom-internal-reporter"', function () { + expect(reporter.getReporterOptions(reporter.getOptions(options), 'custom-internal-reporter')).to.be.deep.equal({ + id: 'default', + }); + }); + }); + describe('#custom-erring-internal-reporter', function () { beforeEach(function() { options = { @@ -245,6 +263,16 @@ describe('lib/MultiReporters', function () { id: 'mocha-junit-reporter', mochaFile: 'junit.xml' }); + + expect(reporter.getReporterOptions(reporter.getOptions({ + reporterOptions: { + cmrOutput: ['tests/custom-internal-reporter', 'output', 'customName'], + configFile: 'tests/custom-internal-dynamic-output-config.json' + } + }), 'mocha-junit-reporter')).to.be.deep.equal({ + id: 'mocha-junit-reporter', + mochaFile: 'junit.xml' + }); }); });