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

Commit

Permalink
Array options (#67)
Browse files Browse the repository at this point in the history
* - Enhancement: Make it posible to supply `reporterEnabled` or `cmrOutput` as arrays; fixes #38

* - Maintenance: Add `.ncurc.js` to allow `npm-check-updates` to avoid updating peerDeps by default
  • Loading branch information
brettz9 authored May 12, 2020
1 parent 07abed1 commit 90a3338
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .ncurc.js
Original file line number Diff line number Diff line change
@@ -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"
};
19 changes: 14 additions & 5 deletions lib/MultiReporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/custom-internal-config-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"reporterEnabled": ["dot", "tests/custom-internal-reporter"],

"xunitReporterOptions": {
"output": "artifacts/test/custom-xunit.xml"
}
}
28 changes: 28 additions & 0 deletions tests/lib/MultiReporters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'
});
});
});

Expand Down

0 comments on commit 90a3338

Please sign in to comment.