-
Notifications
You must be signed in to change notification settings - Fork 14
/
report-generic.js
46 lines (40 loc) · 1.36 KB
/
report-generic.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
import CoverageData from './../services/coverage-data';
import Core from './../services/core';
import ReportCommon from './report-common';
import Conf from '../context/conf';
const ReportImpl = Npm.require('istanbul-reports');
/**
* Used by type lcovonly and json
* create the corresponding file using istanbul api
* @type {any}
*/
export default class {
constructor(res, type, options) {
this.res = res;
this.options = options;
this.report = ReportImpl.create(type, this.options);
this.report.file = this.options.path;
this.context = ReportCommon.getContext(this.report.file);
}
generate() {
const coverage = Core.getCoverageObject();
let childs = CoverageData.getLcovonlyReport(coverage);
this.report.onStart(null, this.context);
/* istanbul ignore else */
if (childs.length === 0) {
this.res.setHeader('Content-type', 'text/plain');
this.res.statusCode = 500;
return this.res.end('{"type":"No coverage to export"}');
}
this.writeFile(childs);
this.res.end('{"type":"success"}');
}
writeFile(childs) {
for (let i = 0; i < childs.length; i++) {
// Remove the COVERAGE_APP_FOLDER from the filepath
childs[i].fileCoverage.data.path = childs[i].fileCoverage.data.path.replace(Conf.COVERAGE_APP_FOLDER, '');
this.report.onDetail(childs[i]);
}
this.report.onEnd();
}
}