Skip to content

Commit

Permalink
feat(reporter): Add callbacks for "writeReport" and "onExit" methods
Browse files Browse the repository at this point in the history
Enables direct use of reporters by allowing full control over the "collector"
object and "exit" functionality.
  • Loading branch information
m-a-r-c-e-l-i-n-o committed Jun 2, 2016
1 parent 8aa66ad commit 7e20759
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ var CoverageReporter = function (rootConfig, helper, logger, emitter) {

function writeReport (reporter, collector) {
try {
if (typeof config._onWriteReport === 'function') {
var newCollector = config._onWriteReport(collector)
if (typeof newCollector === 'object') {
collector = newCollector
}
}
reporter.writeReport(collector, true)
} catch (e) {
log.error(e)
Expand Down Expand Up @@ -298,9 +304,13 @@ var CoverageReporter = function (rootConfig, helper, logger, emitter) {

this.onExit = function (done) {
if (pendingFileWritings) {
fileWritingFinished = done
fileWritingFinished = (
typeof config._onExit === 'function'
? (function (done) { return function () { config._onExit(done) } }(done))
: done
)
} else {
done()
(typeof config._onExit === 'function' ? config._onExit(done) : done())
}
}
}
Expand Down

0 comments on commit 7e20759

Please sign in to comment.