@plugjs/cov8 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,212 @@
1
+ // analysis.ts
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import { assert } from "@plugjs/plug/asserts";
4
+ import { readFile } from "@plugjs/plug/fs";
5
+ import { $gry, $p } from "@plugjs/plug/logging";
6
+ import { SourceMapConsumer } from "source-map";
7
+ var CoverageAnalyserImpl = class {
8
+ constructor(_log) {
9
+ this._log = _log;
10
+ }
11
+ };
12
+ var CoverageResultAnalyser = class extends CoverageAnalyserImpl {
13
+ constructor(log, _result) {
14
+ super(log);
15
+ this._result = _result;
16
+ const _coverage = [];
17
+ for (const coveredFunction of _result.functions) {
18
+ for (const range of coveredFunction.ranges) {
19
+ for (let i = range.startOffset; i < range.endOffset; i++) {
20
+ _coverage[i] = range.count;
21
+ }
22
+ }
23
+ }
24
+ this._coverage = _coverage;
25
+ }
26
+ _coverage;
27
+ _lineLengths;
28
+ async init() {
29
+ const filename = fileURLToPath(this._result.url);
30
+ const source = await readFile(filename, "utf-8");
31
+ this._lineLengths = source.split("\n").map((line) => line.length);
32
+ return this;
33
+ }
34
+ destroy() {
35
+ }
36
+ coverage(source, line, column) {
37
+ assert(this._lineLengths, "Analyser not initialized");
38
+ assert(source === this._result.url, `Wrong source ${source} (should be ${this._result.url})`);
39
+ const { _lineLengths, _coverage } = this;
40
+ let offset = 0;
41
+ for (let l = line - 2; l >= 0; l--)
42
+ offset += _lineLengths[l] + 1;
43
+ return _coverage[offset + column] || 0;
44
+ }
45
+ };
46
+ var CoverageSitemapAnalyser = class extends CoverageResultAnalyser {
47
+ constructor(log, result, _sourceMapCache, _sourceMapBias) {
48
+ super(log, result);
49
+ this._sourceMapCache = _sourceMapCache;
50
+ this._sourceMapBias = _sourceMapBias;
51
+ this._lineLengths = _sourceMapCache.lineLengths;
52
+ }
53
+ _preciseMappings = /* @__PURE__ */ new Map();
54
+ _sourceMap;
55
+ _key(source, line, column) {
56
+ return `${line}:${column}:${source}`;
57
+ }
58
+ async init() {
59
+ const sourceMap = this._sourceMapCache.data;
60
+ assert(sourceMap, "Missing source map data from cache");
61
+ this._sourceMap = await new SourceMapConsumer(sourceMap);
62
+ if (this._sourceMapBias === "none") {
63
+ this._sourceMap.eachMapping((m) => {
64
+ const location = { line: m.generatedLine, column: m.generatedColumn };
65
+ const key = this._key(m.source, m.originalLine, m.originalColumn);
66
+ this._preciseMappings.set(key, location);
67
+ });
68
+ }
69
+ return this;
70
+ }
71
+ destroy() {
72
+ var _a;
73
+ (_a = this._sourceMap) == null ? void 0 : _a.destroy();
74
+ }
75
+ coverage(source, line, column) {
76
+ assert(this._sourceMap, "Analyser not initialized");
77
+ if (this._sourceMapBias === "none") {
78
+ const key = this._key(source, line, column);
79
+ const location = this._preciseMappings.get(key);
80
+ if (!location) {
81
+ this._log.debug(`No precise mapping for ${source}:${line}:${column}`);
82
+ return 0;
83
+ } else {
84
+ return super.coverage(this._result.url, location.line, location.column);
85
+ }
86
+ }
87
+ const bias = this._sourceMapBias === "greatest_lower_bound" ? SourceMapConsumer.GREATEST_LOWER_BOUND : this._sourceMapBias === "least_upper_bound" ? SourceMapConsumer.LEAST_UPPER_BOUND : void 0;
88
+ const generated = this._sourceMap.generatedPositionFor({ source, line, column, bias });
89
+ if (!generated) {
90
+ this._log.debug(`No position generated for ${source}:${line}:${column}`);
91
+ return 0;
92
+ }
93
+ if (generated.line == null) {
94
+ this._log.debug(`No line generated for ${source}:${line}:${column}`);
95
+ return 0;
96
+ }
97
+ if (generated.column == null) {
98
+ this._log.debug(`No column generated for ${source}:${line}:${column}`);
99
+ return 0;
100
+ }
101
+ return super.coverage(this._result.url, generated.line, generated.column);
102
+ }
103
+ };
104
+ function combineCoverage(analysers, source, line, column) {
105
+ let coverage = 0;
106
+ if (!analysers)
107
+ return coverage;
108
+ for (const analyser of analysers) {
109
+ coverage += analyser.coverage(source, line, column);
110
+ }
111
+ return coverage;
112
+ }
113
+ var SourcesCoverageAnalyser = class extends CoverageAnalyserImpl {
114
+ constructor(log, _filename) {
115
+ super(log);
116
+ this._filename = _filename;
117
+ }
118
+ _mappings = /* @__PURE__ */ new Map();
119
+ hasMappings() {
120
+ return this._mappings.size > 0;
121
+ }
122
+ add(source, analyser) {
123
+ const analysers = this._mappings.get(source) || /* @__PURE__ */ new Set();
124
+ analysers.add(analyser);
125
+ this._mappings.set(source, analysers);
126
+ }
127
+ async init() {
128
+ this._log.debug("SourcesCoverageAnalyser", $p(this._filename), $gry(`(${this._mappings.size} mappings)`));
129
+ for (const analysers of this._mappings.values()) {
130
+ for (const analyser of analysers) {
131
+ await analyser.init();
132
+ }
133
+ }
134
+ return this;
135
+ }
136
+ destroy() {
137
+ for (const analysers of this._mappings.values()) {
138
+ for (const analyser of analysers) {
139
+ analyser.destroy();
140
+ }
141
+ }
142
+ }
143
+ coverage(source, line, column) {
144
+ const analysers = this._mappings.get(source);
145
+ return combineCoverage(analysers, source, line, column);
146
+ }
147
+ };
148
+ var CombiningCoverageAnalyser = class extends CoverageAnalyserImpl {
149
+ _analysers = /* @__PURE__ */ new Set();
150
+ add(analyser) {
151
+ this._analysers.add(analyser);
152
+ }
153
+ async init() {
154
+ this._log.debug("CombiningCoverageAnalyser", $gry(`(${this._analysers.size} analysers)`));
155
+ this._log.enter();
156
+ try {
157
+ for (const analyser of this._analysers)
158
+ await analyser.init();
159
+ return this;
160
+ } finally {
161
+ this._log.leave();
162
+ }
163
+ }
164
+ destroy() {
165
+ for (const analyser of this._analysers)
166
+ analyser.destroy();
167
+ }
168
+ coverage(source, line, column) {
169
+ return combineCoverage(this._analysers, source, line, column);
170
+ }
171
+ };
172
+ async function createAnalyser(sourceFiles, coverageFiles, sourceMapBias, log) {
173
+ var _a;
174
+ const urls = sourceFiles.map((path) => pathToFileURL(path).toString());
175
+ const analyser = new CombiningCoverageAnalyser(log);
176
+ for await (const coverageFile of coverageFiles) {
177
+ const coverageFileAnalyser = new SourcesCoverageAnalyser(log, coverageFile);
178
+ log.info("Parsing coverage file", $p(coverageFile));
179
+ const contents = await readFile(coverageFile, "utf-8");
180
+ const coverage = JSON.parse(contents);
181
+ for (const result of coverage.result) {
182
+ if (!result.url.startsWith("node:")) {
183
+ log.debug("Found coverage data for", result.url);
184
+ }
185
+ const mapping = (_a = coverage["source-map-cache"]) == null ? void 0 : _a[result.url];
186
+ if (mapping) {
187
+ log.debug("Found source mapping for", result.url, mapping.data);
188
+ const matches = urls.filter((url) => {
189
+ var _a2;
190
+ return (_a2 = mapping.data) == null ? void 0 : _a2.sources.includes(url);
191
+ });
192
+ if (matches.length) {
193
+ log.debug("Found source mapping matches", matches);
194
+ const sourceAnalyser = new CoverageSitemapAnalyser(log, result, mapping, sourceMapBias);
195
+ for (const match of matches)
196
+ coverageFileAnalyser.add(match, sourceAnalyser);
197
+ }
198
+ } else if (urls.includes(result.url)) {
199
+ coverageFileAnalyser.add(result.url, new CoverageResultAnalyser(log, result));
200
+ }
201
+ }
202
+ if (coverageFileAnalyser.hasMappings())
203
+ analyser.add(coverageFileAnalyser);
204
+ }
205
+ return await analyser.init();
206
+ }
207
+ export {
208
+ CombiningCoverageAnalyser,
209
+ SourcesCoverageAnalyser,
210
+ createAnalyser
211
+ };
212
+ //# sourceMappingURL=analysis.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/analysis.ts"],
4
+ "mappings": ";AAAA,SAAS,eAAe,qBAAqB;AAE7C,SAAS,cAAc;AACvB,SAAS,gBAAgB;AACzB,SAAS,MAAM,UAAU;AACzB,SAAS,yBAAyB;AA4FlC,IAAe,uBAAf,MAAgE;AAAA,EAC9D,YAA+B,MAAc;AAAd;AAAA,EAAe;AAKhD;AAMA,IAAM,yBAAN,cAAqC,qBAAqB;AAAA,EAMxD,YACI,KACmB,SACrB;AACA,UAAM,GAAG;AAFY;AAIrB,UAAM,YAAoC,CAAC;AAE3C,eAAW,m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QAAQ,SAAS;AAAA,SAAI;AAGxE,YAAI,QAAQ,QAAQ;AAClB,cAAI,MAAM,gCAAgC,OAAO;AAEjD,gBAAM,iBAAiB,IAAI,wBAAwB,KAAK,QAAQ,SAAS,aAAa;AACtF,qBAAW,SAAS;AAAS,iCAAqB,IAAI,OAAO,cAAc;AAAA,QAC7E;AAAA,MAMF,WAAW,KAAK,SAAS,OAAO,GAAG,GAAG;AACpC,6BAAqB,IAAI,OAAO,KAAK,IAAI,uBAAuB,KAAK,MAAM,CAAC;AAAA,MAC9E;AAAA,IACF;AAGA,QAAI,qBAAqB,YAAY;AAAG,eAAS,IAAI,oBAAoB;AAAA,EAC3E;AAEA,SAAO,MAAM,SAAS,KAAK;AAC7B;",
5
+ "names": ["_a"]
6
+ }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // coverage.ts
21
+ var coverage_exports = {};
22
+ __export(coverage_exports, {
23
+ Coverage: () => Coverage
24
+ });
25
+ module.exports = __toCommonJS(coverage_exports);
26
+ var import_node_path = require("node:path");
27
+ var import_cov8_html = require("@plugjs/cov8-html");
28
+ var import_files = require("@plugjs/plug/files");
29
+ var import_logging = require("@plugjs/plug/logging");
30
+ var import_paths = require("@plugjs/plug/paths");
31
+ var import_utils = require("@plugjs/plug/utils");
32
+ var import_analysis = require("./analysis.cjs");
33
+ var import_report = require("./report.cjs");
34
+ var Coverage = class {
35
+ constructor(_coverageDir, _options = {}) {
36
+ this._coverageDir = _coverageDir;
37
+ this._options = _options;
38
+ }
39
+ async pipe(files, context) {
40
+ const coverageDir = context.resolve(this._coverageDir);
41
+ const coverageFiles = [];
42
+ for await (const file of (0, import_utils.walk)(coverageDir, ["coverage-*.json"])) {
43
+ coverageFiles.push((0, import_paths.resolveAbsolutePath)(coverageDir, file));
44
+ }
45
+ if (coverageFiles.length === 0) {
46
+ throw context.log.fail(`No coverage files found in ${(0, import_logging.$p)(coverageDir)}`);
47
+ }
48
+ const sourceFiles = [...files.absolutePaths()];
49
+ const ms1 = Date.now();
50
+ const analyser = await (0, import_analysis.createAnalyser)(
51
+ sourceFiles,
52
+ coverageFiles,
53
+ this._options.sourceMapBias || "least_upper_bound",
54
+ context.log
55
+ );
56
+ context.log.info("Parsed", coverageFiles.length, "coverage files", (0, import_logging.$ms)(Date.now() - ms1));
57
+ const ms2 = Date.now();
58
+ const report = await (0, import_report.coverageReport)(analyser, sourceFiles, context.log);
59
+ context.log.info("Analysed", sourceFiles.length, "source files", (0, import_logging.$ms)(Date.now() - ms2));
60
+ analyser.destroy();
61
+ const {
62
+ minimumCoverage = 50,
63
+ minimumFileCoverage = minimumCoverage,
64
+ optimalCoverage = Math.round((100 + minimumCoverage) / 2),
65
+ optimalFileCoverage = Math.round((100 + minimumFileCoverage) / 2)
66
+ } = this._options;
67
+ let max = 0;
68
+ for (const file in report) {
69
+ if (file.length > max)
70
+ max = file.length;
71
+ }
72
+ let maxLength = 0;
73
+ for (const file in report.results) {
74
+ if (file.length > maxLength)
75
+ maxLength = file.length;
76
+ }
77
+ let fileErrors = 0;
78
+ let fileWarnings = 0;
79
+ const _report = context.log.report("Coverage report");
80
+ for (const [_file, result] of Object.entries(report.results)) {
81
+ const { coverage } = result.nodeCoverage;
82
+ const file = _file;
83
+ if (coverage == null) {
84
+ _report.annotate(import_logging.NOTICE, file, "n/a");
85
+ } else if (coverage < minimumFileCoverage) {
86
+ _report.annotate(import_logging.ERROR, file, `${coverage} %`);
87
+ fileErrors++;
88
+ } else if (coverage < optimalFileCoverage) {
89
+ _report.annotate(import_logging.WARN, file, `${coverage} %`);
90
+ fileWarnings++;
91
+ } else {
92
+ _report.annotate(import_logging.NOTICE, file, `${coverage} %`);
93
+ }
94
+ }
95
+ if (report.nodes.coverage == null) {
96
+ const message = "No coverage data collected";
97
+ _report.add({ level: import_logging.WARN, message });
98
+ } else if (report.nodes.coverage < minimumCoverage) {
99
+ const message = `${(0, import_logging.$red)(`${report.nodes.coverage}%`)} does not meet minimum coverage ${(0, import_logging.$gry)(`(${minimumCoverage}%)`)}`;
100
+ _report.add({ level: import_logging.ERROR, message });
101
+ } else if (report.nodes.coverage < optimalCoverage) {
102
+ const message = `${(0, import_logging.$ylw)(`${report.nodes.coverage}%`)} does not meet optimal coverage ${(0, import_logging.$gry)(`(${optimalCoverage}%)`)}`;
103
+ _report.add({ level: import_logging.WARN, message });
104
+ }
105
+ if (fileErrors) {
106
+ const message = `${(0, import_logging.$red)(fileErrors)} files do not meet minimum file coverage ${(0, import_logging.$gry)(`(${minimumFileCoverage}%)`)}`;
107
+ _report.add({ level: import_logging.ERROR, message });
108
+ }
109
+ if (fileWarnings) {
110
+ const message = `${(0, import_logging.$ylw)(fileWarnings)} files do not meet optimal file coverage ${(0, import_logging.$gry)(`(${optimalFileCoverage}%)`)}`;
111
+ _report.add({ level: import_logging.WARN, message });
112
+ }
113
+ if (this._options.reportDir == null)
114
+ return _report.done(false);
115
+ const reportDir = context.resolve(this._options.reportDir);
116
+ const builder = import_files.Files.builder(reportDir);
117
+ const date = new Date().toISOString();
118
+ const thresholds = {
119
+ minimumCoverage,
120
+ minimumFileCoverage,
121
+ optimalCoverage,
122
+ optimalFileCoverage
123
+ };
124
+ await builder.write("report.json", JSON.stringify({ ...report, thresholds, date }));
125
+ await builder.write("index.html", import_cov8_html.html);
126
+ const results = {};
127
+ for (const [rel, abs] of files.pathMappings()) {
128
+ results[rel] = report.results[abs];
129
+ }
130
+ const tree = {};
131
+ for (const relative of Object.keys(results)) {
132
+ const directories = relative.split(import_node_path.sep);
133
+ const file = directories.pop();
134
+ let node = tree;
135
+ for (const dir of directories) {
136
+ node = node[dir] = node[dir] || {};
137
+ }
138
+ node[file] = relative;
139
+ }
140
+ const jsonp = JSON.stringify({ ...report, results, thresholds, tree, date });
141
+ await builder.write("report.js", `${import_cov8_html.initFunction}(${jsonp});`);
142
+ _report.done(false);
143
+ return builder.build();
144
+ }
145
+ };
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ Coverage
149
+ });
150
+ //# sourceMappingURL=coverage.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/coverage.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAoB;AAEpB,uBAAmC;AACnC,mBAAsB;AACtB,qBAA+D;AAC/D,mBAAoC;AACpC,mBAAqB;AAErB,sBAA+B;AAC/B,oBAA+B;AAOxB,IAAM,WAAN,MAAkD;AAAA,EAEvD,YACqB,cACA,WAA2C,CAAC,GAC/D;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,MAAM,KAAK,OAAc,SAA8C;AACrE,UAAM,cAAc,QAAQ,QAAQ,KAAK,YAAY;AACrD,UAAM,gBAAgC,CAAC;AACvC,qBAAiB,YAAQ,mBAAK,aAAa,CAAE,iBAAkB,CAAC,GAAG;AACjE,oBAAc,SAAK,kCAAoB,aAAa,IAAI,CAAC;AAAA,IAC3D;AAEA,QAAI,cAAc,WAAW,GAAG;AAC9B,YAAM,QAAQ,IAAI,KAAK,kCAA8B,mBAAG,WAAW,GAAG;AAAA,IACxE;AAEA,UAAM,cAAc,CAAE,GAAG,MAA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YAAY,KAAK,CAAC,CAAC;AAGlF,UAAM,QAAQ,MAAM,cAAc,qBAAI;AAGtC,UAAM,UAA0C,CAAC;AACjD,eAAW,CAAE,KAAK,GAAI,KAAK,MAAM,aAAa,GAAG;AAC/C,cAAQ,OAAO,OAAO,QAAQ;AAAA,IAChC;AAEA,UAAM,OAA4B,CAAC;AACnC,eAAW,YAAY,OAAO,KAAK,OAAO,GAAG;AAC3C,YAAM,cAAc,SAAS,MAAM,oBAAG;AACtC,YAAM,OAAO,YAAY,IAAI;AAE7B,UAAI,OAAO;AACX,iBAAW,OAAO,aAAa;AAC7B,eAAO,KAAK,OAAO,KAAK,QAAQ,CAAC;AAAA,MACnC;AAEA,WAAK,QAAQ;AAAA,IACf;AAEA,UAAM,QAAQ,KAAK,UAAU,EAAE,GAAG,QAAQ,SAAS,YAAY,MAAM,KAAK,CAAC;AAC3E,UAAM,QAAQ,MAAM,aAAa,GAAG,iCAAgB,SAAS;AAG7D,YAAQ,KAAK,KAAK;AAGlB,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference path="index.d.ts" />
2
+ import { Files } from '@plugjs/plug/files';
3
+ import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe';
4
+ export declare class Coverage implements Plug<Files | undefined> {
5
+ private readonly _coverageDir;
6
+ private readonly _options;
7
+ constructor(...args: PipeParameters<'coverage'>);
8
+ pipe(files: Files, context: Context): Promise<Files | undefined>;
9
+ }
@@ -0,0 +1,125 @@
1
+ // coverage.ts
2
+ import { sep } from "node:path";
3
+ import { html, initFunction } from "@plugjs/cov8-html";
4
+ import { Files } from "@plugjs/plug/files";
5
+ import { $gry, $ms, $p, $red, $ylw, ERROR, NOTICE, WARN } from "@plugjs/plug/logging";
6
+ import { resolveAbsolutePath } from "@plugjs/plug/paths";
7
+ import { walk } from "@plugjs/plug/utils";
8
+ import { createAnalyser } from "./analysis.mjs";
9
+ import { coverageReport } from "./report.mjs";
10
+ var Coverage = class {
11
+ constructor(_coverageDir, _options = {}) {
12
+ this._coverageDir = _coverageDir;
13
+ this._options = _options;
14
+ }
15
+ async pipe(files, context) {
16
+ const coverageDir = context.resolve(this._coverageDir);
17
+ const coverageFiles = [];
18
+ for await (const file of walk(coverageDir, ["coverage-*.json"])) {
19
+ coverageFiles.push(resolveAbsolutePath(coverageDir, file));
20
+ }
21
+ if (coverageFiles.length === 0) {
22
+ throw context.log.fail(`No coverage files found in ${$p(coverageDir)}`);
23
+ }
24
+ const sourceFiles = [...files.absolutePaths()];
25
+ const ms1 = Date.now();
26
+ const analyser = await createAnalyser(
27
+ sourceFiles,
28
+ coverageFiles,
29
+ this._options.sourceMapBias || "least_upper_bound",
30
+ context.log
31
+ );
32
+ context.log.info("Parsed", coverageFiles.length, "coverage files", $ms(Date.now() - ms1));
33
+ const ms2 = Date.now();
34
+ const report = await coverageReport(analyser, sourceFiles, context.log);
35
+ context.log.info("Analysed", sourceFiles.length, "source files", $ms(Date.now() - ms2));
36
+ analyser.destroy();
37
+ const {
38
+ minimumCoverage = 50,
39
+ minimumFileCoverage = minimumCoverage,
40
+ optimalCoverage = Math.round((100 + minimumCoverage) / 2),
41
+ optimalFileCoverage = Math.round((100 + minimumFileCoverage) / 2)
42
+ } = this._options;
43
+ let max = 0;
44
+ for (const file in report) {
45
+ if (file.length > max)
46
+ max = file.length;
47
+ }
48
+ let maxLength = 0;
49
+ for (const file in report.results) {
50
+ if (file.length > maxLength)
51
+ maxLength = file.length;
52
+ }
53
+ let fileErrors = 0;
54
+ let fileWarnings = 0;
55
+ const _report = context.log.report("Coverage report");
56
+ for (const [_file, result] of Object.entries(report.results)) {
57
+ const { coverage } = result.nodeCoverage;
58
+ const file = _file;
59
+ if (coverage == null) {
60
+ _report.annotate(NOTICE, file, "n/a");
61
+ } else if (coverage < minimumFileCoverage) {
62
+ _report.annotate(ERROR, file, `${coverage} %`);
63
+ fileErrors++;
64
+ } else if (coverage < optimalFileCoverage) {
65
+ _report.annotate(WARN, file, `${coverage} %`);
66
+ fileWarnings++;
67
+ } else {
68
+ _report.annotate(NOTICE, file, `${coverage} %`);
69
+ }
70
+ }
71
+ if (report.nodes.coverage == null) {
72
+ const message = "No coverage data collected";
73
+ _report.add({ level: WARN, message });
74
+ } else if (report.nodes.coverage < minimumCoverage) {
75
+ const message = `${$red(`${report.nodes.coverage}%`)} does not meet minimum coverage ${$gry(`(${minimumCoverage}%)`)}`;
76
+ _report.add({ level: ERROR, message });
77
+ } else if (report.nodes.coverage < optimalCoverage) {
78
+ const message = `${$ylw(`${report.nodes.coverage}%`)} does not meet optimal coverage ${$gry(`(${optimalCoverage}%)`)}`;
79
+ _report.add({ level: WARN, message });
80
+ }
81
+ if (fileErrors) {
82
+ const message = `${$red(fileErrors)} files do not meet minimum file coverage ${$gry(`(${minimumFileCoverage}%)`)}`;
83
+ _report.add({ level: ERROR, message });
84
+ }
85
+ if (fileWarnings) {
86
+ const message = `${$ylw(fileWarnings)} files do not meet optimal file coverage ${$gry(`(${optimalFileCoverage}%)`)}`;
87
+ _report.add({ level: WARN, message });
88
+ }
89
+ if (this._options.reportDir == null)
90
+ return _report.done(false);
91
+ const reportDir = context.resolve(this._options.reportDir);
92
+ const builder = Files.builder(reportDir);
93
+ const date = new Date().toISOString();
94
+ const thresholds = {
95
+ minimumCoverage,
96
+ minimumFileCoverage,
97
+ optimalCoverage,
98
+ optimalFileCoverage
99
+ };
100
+ await builder.write("report.json", JSON.stringify({ ...report, thresholds, date }));
101
+ await builder.write("index.html", html);
102
+ const results = {};
103
+ for (const [rel, abs] of files.pathMappings()) {
104
+ results[rel] = report.results[abs];
105
+ }
106
+ const tree = {};
107
+ for (const relative of Object.keys(results)) {
108
+ const directories = relative.split(sep);
109
+ const file = directories.pop();
110
+ let node = tree;
111
+ for (const dir of directories) {
112
+ node = node[dir] = node[dir] || {};
113
+ }
114
+ node[file] = relative;
115
+ }
116
+ const jsonp = JSON.stringify({ ...report, results, thresholds, tree, date });
117
+ await builder.write("report.js", `${initFunction}(${jsonp});`);
118
+ _report.done(false);
119
+ return builder.build();
120
+ }
121
+ };
122
+ export {
123
+ Coverage
124
+ };
125
+ //# sourceMappingURL=coverage.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/coverage.ts"],
4
+ "mappings": ";AAGA,SAAS,WAAW;AAEpB,SAAS,MAAM,oBAAoB;AACnC,SAAS,aAAa;AACtB,SAAS,MAAM,KAAK,IAAI,MAAM,MAAM,OAAO,QAAQ,YAAY;AAC/D,SAAS,2BAA2B;AACpC,SAAS,YAAY;AAErB,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAOxB,IAAM,WAAN,MAAkD;AAAA,EAEvD,YACqB,cACA,WAA2C,CAAC,GAC/D;AAFmB;AACA;AAAA,EAClB;AAAA,EAEH,MAAM,KAAK,OAAc,SAA8C;AACrE,UAAM,cAAc,QAAQ,QAAQ,KAAK,YAAY;AACrD,UAAM,gBAAgC,CAAC;AACvC,qBAAiB,QAAQ,KAAK,aAAa,CAAE,iBAAkB,CAAC,GAAG;AACjE,oBAAc,KAAK,oBAAoB,aAAa,IAAI,CAAC;AAAA,IAC3D;AAEA,QAAI,cAAc,WAAW,GAAG;AAC9B,YAAM,QAAQ,IAAI,KAAK,8BAA8B,GAAG,WAAW,GAAG;AAAA,IACxE;AAEA,UAAM,cAAc,CAAE,GAAG,MAAM,cAAc,CAAE;AAE/C,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,WAAW,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,MACA,KAAK,SAAS,iBAAiB;AAAA,MAC/B,QAAQ;AAAA,IACZ;AACA,YAAQ,IAAI,KAAK,UAAU,cAAc,QAAQ,kBAAkB,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC;AAExF,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,SAAS,MAAM,eAAe,UAAU,aAAa,QAAQ,GAAG;AACtE,YAAQ,IAAI,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eAAO,KAAK,OAAO,KAAK,QAAQ,CAAC;AAAA,MACnC;AAEA,WAAK,QAAQ;AAAA,IACf;AAEA,UAAM,QAAQ,KAAK,UAAU,EAAE,GAAG,QAAQ,SAAS,YAAY,MAAM,KAAK,CAAC;AAC3E,UAAM,QAAQ,MAAM,aAAa,GAAG,gBAAgB,SAAS;AAG7D,YAAQ,KAAK,KAAK;AAGlB,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
5
+ "names": []
6
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // index.ts
17
+ var src_exports = {};
18
+ module.exports = __toCommonJS(src_exports);
19
+ var import_pipe = require("@plugjs/plug/pipe");
20
+ var import_coverage = require("./coverage.cjs");
21
+ (0, import_pipe.install)("coverage", import_coverage.Coverage);
22
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,kBAAwB;AAExB,sBAAyB;AAAA,IA2DzB,qBAAQ,YAAY,wBAAQ;",
5
+ "names": []
6
+ }
@@ -0,0 +1,49 @@
1
+ import type { SourceMapBias } from './analysis';
2
+ /** Options to analyse coverage reports */
3
+ export interface CoverageOptions {
4
+ /** The bias for source map analisys (defaults to `greatest_lower_bound`) */
5
+ sourceMapBias?: SourceMapBias;
6
+ /** Minimum _overall_ coverage (as a percentage, defaults to 50) */
7
+ minimumCoverage?: number;
8
+ /** Optimal _overall_ coverage (as a percentage, defaults to 50) */
9
+ optimalCoverage?: number;
10
+ /** Minimum _per-file_ coverage (as a percentage, defaults to 75) */
11
+ minimumFileCoverage?: number;
12
+ /** Optimal _per-file_ coverage (as a percentage, defaults to 75) */
13
+ optimalFileCoverage?: number;
14
+ }
15
+ export interface CoverageReportOptions extends CoverageOptions {
16
+ /** If specified, a JSON and HTML report will be written to this directory */
17
+ reportDir: string;
18
+ }
19
+ declare module '@plugjs/plug' {
20
+ interface Pipe {
21
+ /**
22
+ * Analyse coverage using files generated by V8/NodeJS.
23
+ *
24
+ * @param coverageDir The directory where the `coverage-XXX.json` files
25
+ * generated by V8/NodeJS can be found.
26
+ */
27
+ coverage(coverageDir: string): Promise<undefined>;
28
+ /**
29
+ * Analyse coverage using files generated by V8/NodeJS.
30
+ *
31
+ * @param coverageDir The directory where the `coverage-XXX.json` files
32
+ * generated by V8/NodeJS can be found.
33
+ * @param options Extra {@link CoverageOptions | options} allowing to
34
+ * specify coverage thresholds.
35
+ */
36
+ coverage(coverageDir: string, options: CoverageOptions): Promise<undefined>;
37
+ /**
38
+ * Analyse coverage using files generated by V8/NodeJS and produce an HTML
39
+ * report in the directory specified in `options`.
40
+ *
41
+ * @param coverageDir The directory where the `coverage-XXX.json` files
42
+ * generated by V8/NodeJS can be found.
43
+ * @param options Extra {@link CoverageOptions | options} allowing to
44
+ * specify coverage thresholds where the HTML report should
45
+ * be written to.
46
+ */
47
+ coverage(coverageDir: string, options: CoverageReportOptions): Pipe;
48
+ }
49
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ // index.ts
2
+ import { install } from "@plugjs/plug/pipe";
3
+ import { Coverage } from "./coverage.mjs";
4
+ install("coverage", Coverage);
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "mappings": ";AAAA,SAAS,eAAe;AAExB,SAAS,gBAAgB;AA2DzB,QAAQ,YAAY,QAAQ;",
5
+ "names": []
6
+ }