UNPKG

3.7 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports", "tslib", "istanbul-lib-coverage", "istanbul-lib-report", "istanbul-reports", "./Reporter"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 var tslib_1 = require("tslib");
13 var istanbul_lib_coverage_1 = require("istanbul-lib-coverage");
14 var istanbul_lib_report_1 = require("istanbul-lib-report");
15 var istanbul_reports_1 = require("istanbul-reports");
16 var Reporter_1 = tslib_1.__importStar(require("./Reporter"));
17 var eventHandler = Reporter_1.createEventHandler();
18 var Coverage = (function (_super) {
19 tslib_1.__extends(Coverage, _super);
20 function Coverage(executor, options) {
21 if (options === void 0) { options = {}; }
22 var _this = _super.call(this, executor, options) || this;
23 if (options.filename) {
24 _this.filename = options.filename;
25 }
26 if (options.directory) {
27 _this.directory = options.directory;
28 }
29 if (options.watermarks) {
30 _this.watermarks = options.watermarks;
31 }
32 return _this;
33 }
34 Coverage.prototype.getReporterOptions = function () {
35 return {
36 file: this.filename,
37 };
38 };
39 Coverage.prototype.createCoverageReport = function (type, data) {
40 return tslib_1.__awaiter(this, void 0, void 0, function () {
41 var map, transformed, context;
42 var _this = this;
43 return tslib_1.__generator(this, function (_a) {
44 switch (_a.label) {
45 case 0:
46 if (isCoverageMap(data)) {
47 map = data;
48 }
49 else {
50 map = istanbul_lib_coverage_1.createCoverageMap(data);
51 }
52 return [4, this.executor.sourceMapStore.transformCoverage(map)];
53 case 1:
54 transformed = _a.sent();
55 context = istanbul_lib_report_1.createContext({
56 coverageMap: transformed,
57 dir: this.directory,
58 sourceFinder: function (path) {
59 return _this.executor.sourceMapStore.sourceFinder(path);
60 },
61 watermarks: this.watermarks,
62 });
63 istanbul_reports_1.create(type, this.getReporterOptions()).execute(context);
64 return [2];
65 }
66 });
67 });
68 };
69 Coverage.prototype.runEnd = function () {
70 var map = this.executor.coverageMap;
71 if (map.files().length > 0) {
72 return this.createCoverageReport(this.reportType, map);
73 }
74 };
75 tslib_1.__decorate([
76 eventHandler()
77 ], Coverage.prototype, "runEnd", null);
78 return Coverage;
79 }(Reporter_1.default));
80 exports.default = Coverage;
81 function isCoverageMap(value) {
82 return value != null && typeof value.files === 'function';
83 }
84});
85//# sourceMappingURL=Coverage.js.map
\No newline at end of file