Skip to content

Commit

Permalink
feat: allow multiple report types
Browse files Browse the repository at this point in the history
This change refactors the way the coverageReporter configuration
works by adding a new 'reporters' property.  This property is a list
of configurations for any reporters that should be used.  This allows
the user to ask for multiple output types at the same time.

For example:

coverageReporter: {
    dir : 'coverage/',
    reporters: [{
      type: 'html'
    }, {
      type: 'text'
    }, {
        type: 'cobertura'
    }]
}

This configuration outputs reports in html, text, and cobertura
from the same run of karma.

Note: the code is designed to be backwards compatible with the older
method of specifying the options.

SQUASH: format feature
  • Loading branch information
abierbaum authored and vojtajina committed Aug 3, 2013
1 parent ecca86a commit 4a9afb6
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ var CoverageReporter = function(rootConfig, emitter, helper, logger) {
var config = rootConfig.coverageReporter;
var basePath = rootConfig.basePath;
var outDir = config.dir;
var type = config.type;
var reporters = config.reporters;

if (!helper.isDefined(reporters)) {
reporters = [config];
}

this.adapters = [];
var collectors;
Expand All @@ -51,6 +55,10 @@ var CoverageReporter = function(rootConfig, emitter, helper, logger) {

function writeEnd() {
if (!--pendingFileWritings) {
// cleanup collectors
Object.keys(collectors).forEach(function(key) {
collectors[key].dispose();
});
fileWritingFinished();
}
}
Expand Down Expand Up @@ -93,28 +101,30 @@ var CoverageReporter = function(rootConfig, emitter, helper, logger) {
};

this.onRunComplete = function(browsers, results) {
browsers.forEach(function(browser) {
var collector = collectors[browser.id];
if (collector) {
pendingFileWritings++;
var out = path.resolve(outDir, browser.name);
helper.mkdirIfNotExists(out, function() {
var options = helper.merge({}, config, {
dir : out,
sourceStore : new BasePathStore({
basePath : basePath
})
reporters.forEach(function(reporterConfig) {
browsers.forEach(function(browser) {
var collector = collectors[browser.id];
if (collector) {
pendingFileWritings++;
var out = path.resolve(outDir, browser.name);
helper.mkdirIfNotExists(out, function() {
var options = helper.merge({}, reporterConfig, {
dir : out,
sourceStore : new BasePathStore({
basePath : basePath
})
});
var reporter = istanbul.Report.create(reporterConfig.type, options);
try {
reporter.writeReport(collector, true);
} catch (e) {
log.error(e);
}
collector.dispose();
writeEnd();
});
var reporter = istanbul.Report.create(type, options);
try {
reporter.writeReport(collector, true);
} catch (e) {
log.error(e);
}
collector.dispose();
writeEnd();
});
}
}
});
});
};

Expand Down

0 comments on commit 4a9afb6

Please sign in to comment.