forked from DxCx/mocha-istanbul-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (40 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var ISTANBUL = require('istanbul'),
Report = ISTANBUL.Report,
Collector = ISTANBUL.Collector;
var inherits = require('mocha').utils.inherits;
var SPEC = require('mocha').reporters.spec
var ISTANBUL_REMAP = require('remap-istanbul/lib/remap');
/**
* Expose `Istanbul`.
*/
exports = module.exports = Istanbul;
/**
* Initialize a new Istanbul reporter.
*
* @param {Runner} runner
* @public
*/
function Istanbul(runner) {
SPEC.call(this, runner);
runner.on('end', function(){
var reporters;
if (process.env.ISTANBUL_REPORTERS) {
reporters = process.env.ISTANBUL_REPORTERS.split(',');
} else {
reporters = ['text-summary', 'html'];
}
var reportDir = process.env.ISTANBUL_REPORT_DIR;
var opts = {};
if (reportDir) {
opts.dir = reportDir;
}
var cov = global.__coverage__ || {},
collector = new Collector();
collector.add(cov);
collector = ISTANBUL_REMAP(collector.getFinalCoverage());
reporters.forEach(function(reporter) {
Report.create(reporter, opts).writeReport(collector, true);
});
});
}
inherits(Istanbul, SPEC);