@plugjs/cov8 0.6.117 → 0.7.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.
- package/dist/analysis.d.ts +1 -0
- package/dist/analysis.d.ts.map +1 -0
- package/dist/analysis.js +264 -0
- package/dist/analysis.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +197 -0
- package/dist/cli.js.map +1 -0
- package/dist/coverage.d.ts +1 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +130 -0
- package/dist/coverage.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/report.d.ts +2 -1
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +288 -0
- package/dist/report.js.map +1 -0
- package/package.json +13 -23
- package/src/analysis.ts +3 -3
- package/src/{cli.mts → cli.ts} +20 -8
- package/src/coverage.ts +4 -4
- package/src/index.ts +2 -2
- package/src/report.ts +1 -1
- package/dist/analysis.cjs +0 -241
- package/dist/analysis.cjs.map +0 -6
- package/dist/analysis.mjs +0 -214
- package/dist/analysis.mjs.map +0 -6
- package/dist/cli.d.mts +0 -2
- package/dist/cli.mjs +0 -168
- package/dist/cli.mjs.map +0 -6
- package/dist/coverage.cjs +0 -150
- package/dist/coverage.cjs.map +0 -6
- package/dist/coverage.mjs +0 -125
- package/dist/coverage.mjs.map +0 -6
- package/dist/index.cjs +0 -22
- package/dist/index.cjs.map +0 -6
- package/dist/index.mjs +0 -5
- package/dist/index.mjs.map +0 -6
- package/dist/report.cjs +0 -236
- package/dist/report.cjs.map +0 -6
- package/dist/report.mjs +0 -221
- package/dist/report.mjs.map +0 -6
package/dist/analysis.d.ts
CHANGED
|
@@ -102,3 +102,4 @@ export declare class CombiningCoverageAnalyser extends CoverageAnalyserImpl {
|
|
|
102
102
|
*/
|
|
103
103
|
export declare function createAnalyser(sourceFiles: AbsolutePath[], coverageFiles: AbsolutePath[], sourceMapBias: SourceMapBias, log: Logger): Promise<CoverageAnalyser>;
|
|
104
104
|
export {};
|
|
105
|
+
//# sourceMappingURL=analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../src/analysis.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAM9C,qBAAqB;AACrB,MAAM,WAAW,cAAc;IAC7B,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;CACf;AAED,sDAAsD;AACtD,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,eAAe,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED,6DAA6D;AAC7D,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,GAAG,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,SAAS,EAAE,iBAAiB,EAAE,CAAA;CAC/B;AAED,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,yDAAyD;IACzD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,yDAAyD;IACzD,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1B,sEAAsE;IACtE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,iEAAiE;AACjE,MAAM,WAAW,cAAc;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AM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;CAI/D;AAED,mEAAmE;AACnE,qBAAa,yBAA0B,SAAQ,oBAAoB;IACjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAkC;IAE7D,GAAG,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI;IAInC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,OAAO,IAAI,IAAI;IAIf,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;CAG/D;AAID;;;GAGG;AACH,wBAAsB,cAAc,CAChC,WAAW,EAAE,YAAY,EAAE,EAC3B,aAAa,EAAE,YAAY,EAAE,EAC7B,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,MAAM,GACZ,OAAO,CAAC,gBAAgB,CAAC,CA6D3B"}
|
package/dist/analysis.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import { assert } from '@plugjs/plug/asserts';
|
|
3
|
+
import { readFile } from '@plugjs/plug/fs';
|
|
4
|
+
import { $gry, $p } from '@plugjs/plug/logging';
|
|
5
|
+
import { SourceMapConsumer } from 'source-map';
|
|
6
|
+
/* ========================================================================== */
|
|
7
|
+
/** Basic abstract class implementing the {@link CoverageAnalyser} class */
|
|
8
|
+
class CoverageAnalyserImpl {
|
|
9
|
+
_log;
|
|
10
|
+
constructor(_log) {
|
|
11
|
+
this._log = _log;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/* ========================================================================== */
|
|
15
|
+
/** Return coverage data from a V8 {@link V8CoverageResult} structure */
|
|
16
|
+
class CoverageResultAnalyser extends CoverageAnalyserImpl {
|
|
17
|
+
_result;
|
|
18
|
+
/** Number of passes at each character in the result */
|
|
19
|
+
_coverage;
|
|
20
|
+
/** Internal private field for init/_lineLengths getter */
|
|
21
|
+
_lineLengths;
|
|
22
|
+
constructor(log, _result) {
|
|
23
|
+
super(log);
|
|
24
|
+
this._result = _result;
|
|
25
|
+
const _coverage = [];
|
|
26
|
+
for (const coveredFunction of _result.functions) {
|
|
27
|
+
for (const range of coveredFunction.ranges) {
|
|
28
|
+
for (let i = range.startOffset; i < range.endOffset; i++) {
|
|
29
|
+
_coverage[i] = range.count;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
this._coverage = _coverage;
|
|
34
|
+
}
|
|
35
|
+
async init() {
|
|
36
|
+
const filename = fileURLToPath(this._result.url);
|
|
37
|
+
const source = await readFile(filename, 'utf-8');
|
|
38
|
+
this._lineLengths = source.split('\n').map((line) => line.length);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
destroy() {
|
|
42
|
+
// Nothing to do
|
|
43
|
+
}
|
|
44
|
+
/** Return the number of coverage passes for the given location */
|
|
45
|
+
coverage(source, line, column) {
|
|
46
|
+
assert(this._lineLengths, 'Analyser not initialized');
|
|
47
|
+
assert(source === this._result.url, `Wrong source ${source} (should be ${this._result.url})`);
|
|
48
|
+
const { _lineLengths, _coverage } = this;
|
|
49
|
+
let offset = 0;
|
|
50
|
+
/* Calculate the offset at the beginning of the line */
|
|
51
|
+
for (let l = line - 2; l >= 0; l--)
|
|
52
|
+
offset += _lineLengths[l] + 1;
|
|
53
|
+
/* Return the number of passes from the coverage data */
|
|
54
|
+
return _coverage[offset + column] || 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/* ========================================================================== */
|
|
58
|
+
/** Return coverage from a V8 {@link V8CoverageResult} with a sitemap */
|
|
59
|
+
class CoverageSitemapAnalyser extends CoverageResultAnalyser {
|
|
60
|
+
_sourceMapCache;
|
|
61
|
+
_sourceMapBias;
|
|
62
|
+
_preciseMappings = new Map();
|
|
63
|
+
_sourceMap;
|
|
64
|
+
constructor(log, result, _sourceMapCache, _sourceMapBias) {
|
|
65
|
+
super(log, result);
|
|
66
|
+
this._sourceMapCache = _sourceMapCache;
|
|
67
|
+
this._sourceMapBias = _sourceMapBias;
|
|
68
|
+
this._lineLengths = _sourceMapCache.lineLengths;
|
|
69
|
+
}
|
|
70
|
+
_key(source, line, column) {
|
|
71
|
+
return `${line}:${column}:${source}`;
|
|
72
|
+
}
|
|
73
|
+
async init() {
|
|
74
|
+
const sourceMap = this._sourceMapCache.data;
|
|
75
|
+
assert(sourceMap, 'Missing source map data from cache');
|
|
76
|
+
this._sourceMap = await new SourceMapConsumer(sourceMap);
|
|
77
|
+
if (this._sourceMapBias === 'none') {
|
|
78
|
+
this._sourceMap.eachMapping((m) => {
|
|
79
|
+
const location = { line: m.generatedLine, column: m.generatedColumn };
|
|
80
|
+
const key = this._key(m.source, m.originalLine, m.originalColumn);
|
|
81
|
+
this._preciseMappings.set(key, location);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
this._sourceMap?.destroy();
|
|
88
|
+
}
|
|
89
|
+
coverage(source, line, column) {
|
|
90
|
+
assert(this._sourceMap, 'Analyser not initialized');
|
|
91
|
+
if (this._sourceMapBias === 'none') {
|
|
92
|
+
const key = this._key(source, line, column);
|
|
93
|
+
const location = this._preciseMappings.get(key);
|
|
94
|
+
if (!location) {
|
|
95
|
+
this._log.debug(`No precise mapping for ${source}:${line}:${column}`);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return super.coverage(this._result.url, location.line, location.column);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const bias = mapBias(this._sourceMapBias);
|
|
103
|
+
const generated = this._sourceMap.generatedPositionFor({ source, line, column, bias });
|
|
104
|
+
/* coverage ignore if */
|
|
105
|
+
if (!generated) {
|
|
106
|
+
this._log.debug(`No position generated for ${source}:${line}:${column}`);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
/* coverage ignore if */
|
|
110
|
+
if (generated.line == null) {
|
|
111
|
+
this._log.debug(`No line generated for ${source}:${line}:${column}`);
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
/* coverage ignore if */
|
|
115
|
+
if (generated.column == null) {
|
|
116
|
+
this._log.debug(`No column generated for ${source}:${line}:${column}`);
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
return super.coverage(this._result.url, generated.line, generated.column);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/* ========================================================================== */
|
|
123
|
+
function mapBias(bias) {
|
|
124
|
+
if (bias === 'greatest_lower_bound')
|
|
125
|
+
return SourceMapConsumer.GREATEST_LOWER_BOUND;
|
|
126
|
+
if (bias === 'least_upper_bound')
|
|
127
|
+
return SourceMapConsumer.LEAST_UPPER_BOUND;
|
|
128
|
+
/* coverage ignore next */
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
/** Combine (add) all coverage data from all analysers */
|
|
132
|
+
function combineCoverage(analysers, source, line, column) {
|
|
133
|
+
let coverage = 0;
|
|
134
|
+
if (!analysers)
|
|
135
|
+
return coverage;
|
|
136
|
+
for (const analyser of analysers) {
|
|
137
|
+
coverage += analyser.coverage(source, line, column);
|
|
138
|
+
}
|
|
139
|
+
return coverage;
|
|
140
|
+
}
|
|
141
|
+
/* ========================================================================== */
|
|
142
|
+
/** Associate one or more {@link CoverageAnalyser} with different sources */
|
|
143
|
+
export class SourcesCoverageAnalyser extends CoverageAnalyserImpl {
|
|
144
|
+
_filename;
|
|
145
|
+
_mappings = new Map();
|
|
146
|
+
constructor(log, _filename) {
|
|
147
|
+
super(log);
|
|
148
|
+
this._filename = _filename;
|
|
149
|
+
}
|
|
150
|
+
hasMappings() {
|
|
151
|
+
return this._mappings.size > 0;
|
|
152
|
+
}
|
|
153
|
+
add(source, analyser) {
|
|
154
|
+
const analysers = this._mappings.get(source) || new Set();
|
|
155
|
+
analysers.add(analyser);
|
|
156
|
+
this._mappings.set(source, analysers);
|
|
157
|
+
}
|
|
158
|
+
async init() {
|
|
159
|
+
this._log.debug('SourcesCoverageAnalyser', $p(this._filename), $gry(`(${this._mappings.size} mappings)`));
|
|
160
|
+
for (const analysers of this._mappings.values()) {
|
|
161
|
+
for (const analyser of analysers) {
|
|
162
|
+
await analyser.init();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
destroy() {
|
|
168
|
+
for (const analysers of this._mappings.values()) {
|
|
169
|
+
for (const analyser of analysers) {
|
|
170
|
+
analyser.destroy();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
coverage(source, line, column) {
|
|
175
|
+
const analysers = this._mappings.get(source);
|
|
176
|
+
return combineCoverage(analysers, source, line, column);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** Combine multiple {@link CoverageAnalyser} instances together */
|
|
180
|
+
export class CombiningCoverageAnalyser extends CoverageAnalyserImpl {
|
|
181
|
+
_analysers = new Set();
|
|
182
|
+
add(analyser) {
|
|
183
|
+
this._analysers.add(analyser);
|
|
184
|
+
}
|
|
185
|
+
async init() {
|
|
186
|
+
this._log.debug('CombiningCoverageAnalyser', $gry(`(${this._analysers.size} analysers)`));
|
|
187
|
+
this._log.enter();
|
|
188
|
+
try {
|
|
189
|
+
for (const analyser of this._analysers)
|
|
190
|
+
await analyser.init();
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
this._log.leave();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
destroy() {
|
|
198
|
+
for (const analyser of this._analysers)
|
|
199
|
+
analyser.destroy();
|
|
200
|
+
}
|
|
201
|
+
coverage(source, line, column) {
|
|
202
|
+
return combineCoverage(this._analysers, source, line, column);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/* ========================================================================== */
|
|
206
|
+
/**
|
|
207
|
+
* Analyse coverage for the specified source files, using the data from the
|
|
208
|
+
* specified coverage files and produce a {@link CoverageReport}.
|
|
209
|
+
*/
|
|
210
|
+
export async function createAnalyser(sourceFiles, coverageFiles, sourceMapBias, log) {
|
|
211
|
+
/* Internally V8 coverage uses URLs for everything */
|
|
212
|
+
const urls = sourceFiles.map((path) => pathToFileURL(path).toString());
|
|
213
|
+
/* The coverage analyser combining all coverage files in the directory */
|
|
214
|
+
const analyser = new CombiningCoverageAnalyser(log);
|
|
215
|
+
/* Resolve and walk the coverage directory, finding "coverage-*.json" files */
|
|
216
|
+
for await (const coverageFile of coverageFiles) {
|
|
217
|
+
/* The "SourceCoverageAnalyser" for this coverage file */
|
|
218
|
+
const coverageFileAnalyser = new SourcesCoverageAnalyser(log, coverageFile);
|
|
219
|
+
/* Parse our coverage file from JSON */
|
|
220
|
+
log.info('Parsing coverage file', $p(coverageFile));
|
|
221
|
+
const contents = await readFile(coverageFile, 'utf-8');
|
|
222
|
+
const coverage = JSON.parse(contents);
|
|
223
|
+
/* Let's look inside of the coverage file... */
|
|
224
|
+
for (const result of coverage.result) {
|
|
225
|
+
if (!result.url.startsWith('node:')) {
|
|
226
|
+
log.debug('Found coverage data for', result.url);
|
|
227
|
+
}
|
|
228
|
+
/*
|
|
229
|
+
* Each coverage result (script) can be associated with a sitemap or
|
|
230
|
+
* not... Sometimes (as in with ts-node) the sitemap simply points to
|
|
231
|
+
* itself (same file), but embeds all the transformation information
|
|
232
|
+
* between the file on disk, and what's been used by Node.JS.
|
|
233
|
+
*/
|
|
234
|
+
const mapping = coverage['source-map-cache']?.[result.url];
|
|
235
|
+
if (mapping) {
|
|
236
|
+
log.debug('Found source mapping for', result.url, mapping.data);
|
|
237
|
+
/*
|
|
238
|
+
* If we have mapping, we want to see if any of the sourcemap's source
|
|
239
|
+
* files matches one of the sources we have to analyse.
|
|
240
|
+
*/
|
|
241
|
+
const matches = urls.filter((url) => mapping.data?.sources.includes(url));
|
|
242
|
+
/* If we map any file, we associate it with our source map analyser */
|
|
243
|
+
if (matches.length) {
|
|
244
|
+
log.debug('Found source mapping matches', matches);
|
|
245
|
+
const sourceAnalyser = new CoverageSitemapAnalyser(log, result, mapping, sourceMapBias);
|
|
246
|
+
for (const match of matches)
|
|
247
|
+
coverageFileAnalyser.add(match, sourceAnalyser);
|
|
248
|
+
}
|
|
249
|
+
/*
|
|
250
|
+
* If we have no source map for the file, but it matches one of the
|
|
251
|
+
* ones we have to analyse coverage for, we add that directly...
|
|
252
|
+
*/
|
|
253
|
+
}
|
|
254
|
+
else if (urls.includes(result.url)) {
|
|
255
|
+
coverageFileAnalyser.add(result.url, new CoverageResultAnalyser(log, result));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/* Add the analyser if it has some mappings */
|
|
259
|
+
if (coverageFileAnalyser.hasMappings())
|
|
260
|
+
analyser.add(coverageFileAnalyser);
|
|
261
|
+
}
|
|
262
|
+
return await analyser.init();
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=analysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis.js","sourceRoot":"","sources":["../src/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAyF9C,gFAAgF;AAEhF,2EAA2E;AAC3E,MAAe,oBAAoB;IACF;IAA/B,YAA+B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;CAKhD;AAGD,gFAAgF;AAEhF,wEAAwE;AACxE,MAAM,sBAAuB,SAAQ,oBAAoB;IAQhC;IAPvB,uDAAuD;IACpC,SAAS,CAA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G,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;gBAE/D;;;oBAGI;gBACJ,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;gBAEzE,sEAAsE;gBACtE,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;oBACnB,GAAG,CAAC,KAAK,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAA;oBAElD,MAAM,cAAc,GAAG,IAAI,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;oBACvF,KAAK,MAAM,KAAK,IAAI,OAAO;wBAAE,oBAAoB,CAAC,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;gBAC9E,CAAC;gBAEH;;;oBAGI;YACJ,CAAC;iBAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrC,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,sBAAsB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;YAC/E,CAAC;QACH,CAAC;QAED,8CAA8C;QAC9C,IAAI,oBAAoB,CAAC,WAAW,EAAE;YAAE,QAAQ,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;IAC5E,CAAC;IAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;AAC9B,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* coverage ignore file / not tested in unit tests */
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
import _fs from 'node:fs';
|
|
5
|
+
import _path from 'node:path';
|
|
6
|
+
import { async, find, logging, mkdtemp, paths, pipe, rmrf, utils } from '@plugjs/plug';
|
|
7
|
+
import { main, yargsParser } from '@plugjs/tsrun';
|
|
8
|
+
import { Coverage } from "./coverage.js";
|
|
9
|
+
const { $blu, $und, $gry, $wht, $p } = logging;
|
|
10
|
+
const $gnd = (s) => $gry($und(s));
|
|
11
|
+
const $bnd = (s) => $blu($und(s));
|
|
12
|
+
const $wnd = (s) => $wht($und(s));
|
|
13
|
+
/** Version resolved from "package.json" */
|
|
14
|
+
function version() {
|
|
15
|
+
try {
|
|
16
|
+
const packageJsonPath = _path.resolve(import.meta.dirname, '..', 'package.json');
|
|
17
|
+
const packageJson = JSON.parse(_fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
18
|
+
return (typeof packageJson.version === 'string' && packageJson.version)
|
|
19
|
+
? packageJson.version
|
|
20
|
+
: '0.0.0-dev';
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return '0.0.0-dev';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/* ========================================================================== *
|
|
27
|
+
* HELP SCREEN *
|
|
28
|
+
* ========================================================================== */
|
|
29
|
+
/** Show help screen */
|
|
30
|
+
function help() {
|
|
31
|
+
console.log(`${$blu($und('Usage:'))}
|
|
32
|
+
|
|
33
|
+
${$wht('cov8')} ${$gry('[')}--options${$gry('] [--] [...')}command${$gry('...]')}
|
|
34
|
+
|
|
35
|
+
${$bnd('Options:')}
|
|
36
|
+
|
|
37
|
+
${$wht('-c --coverage-dir')} ${$gnd('dir')} The directory containing all coverage data files
|
|
38
|
+
${$wht('-r --report-dir')} ${$gnd('dir')} Write an HTML report to this directory
|
|
39
|
+
${$wht('-d --source-dir')} ${$gnd('dir')} The directory where source files are located
|
|
40
|
+
${$wht('-s --sources')} ${$gnd('glob')} A glob for the sources to be reported upon
|
|
41
|
+
${$wht('-m --minimum')} ${$gnd('num')} The desired minimum coverage level to achieve
|
|
42
|
+
${$wht('-o --optimal')} ${$gnd('num')} The desired optimal coverage level to achieve
|
|
43
|
+
${$wht('-h --help ')} Help! You're reading it now!
|
|
44
|
+
${$wht(' --version')} Version! This one: ${version()}!
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
${$bnd('Usave:')}
|
|
48
|
+
|
|
49
|
+
This utility can process and create reports for ${$und('existing')} Node.js coverage
|
|
50
|
+
data, or execute a command and verify the execution's coverage.
|
|
51
|
+
|
|
52
|
+
When a command is not specified, the ${$wht('--coverage-dir')} option must be
|
|
53
|
+
specified, and point to a directory containing one or more Node.js JSON
|
|
54
|
+
coverage files. Those can be generated running node and specifying the
|
|
55
|
+
${$wnd('NODE_V8_COVERAGE')} environment variable.
|
|
56
|
+
|
|
57
|
+
When a command is specified, the command will be executed, and coverage
|
|
58
|
+
will be collected automatically in a temporary directory (or in the
|
|
59
|
+
directory specified by ${$wht('--coverage-dir')}).
|
|
60
|
+
|
|
61
|
+
The sources to report upon can be specified with the ${$wht('--source-dir')} option,
|
|
62
|
+
indicating the directory where sources can be found (defailts to the current
|
|
63
|
+
directory) and the ${$wht('--sources')} option (can be specified multiple times)
|
|
64
|
+
indicating the globs matching the source files to report upon.
|
|
65
|
+
|
|
66
|
+
The default is to report upon all JavaScript and TypeScript files in the
|
|
67
|
+
${$wnd('./src')} directory.
|
|
68
|
+
|
|
69
|
+
${$bnd('Environment Variables:')}
|
|
70
|
+
|
|
71
|
+
${$wht('LOG_LEVEL$ ')} The default ${$wnd('notice')}, or ${$gnd('debug')}, ${$gnd('info')}, ${$gnd('warn')} or ${$gnd('error')}.
|
|
72
|
+
|
|
73
|
+
${$bnd('TypeScript module format:')}
|
|
74
|
+
|
|
75
|
+
Normally our TypeScript loader will transpile ${$wnd('.ts')} files to the type
|
|
76
|
+
specified in ${$wnd('package.json')}, either ${$wnd('commonjs')} (the default) or ${$wnd('module')}.
|
|
77
|
+
|
|
78
|
+
To force a specific module format use one of the following flags:
|
|
79
|
+
|
|
80
|
+
${$wht('--force-esm')} Force transpilation of ${$wnd('.ts')} files to EcmaScript modules
|
|
81
|
+
${$wht('--force-cjs')} Force transpilation of ${$wnd('.ts')} files to CommonJS modules
|
|
82
|
+
`);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
/* ========================================================================== *
|
|
86
|
+
* MAIN TEST RUNNER *
|
|
87
|
+
* ========================================================================== */
|
|
88
|
+
/** Parse command line and run tests */
|
|
89
|
+
main(import.meta.url, async (args) => {
|
|
90
|
+
logging.logOptions.spinner = false;
|
|
91
|
+
const filename = paths.requireFilename(import.meta.url); // self, for context
|
|
92
|
+
const context = new pipe.Context(filename, ''); // context for pipes
|
|
93
|
+
const command = []; // empty command line
|
|
94
|
+
const globs = []; // empty globs list
|
|
95
|
+
let minimumCoverage = undefined;
|
|
96
|
+
let optimalCoverage = undefined;
|
|
97
|
+
let coverageDir;
|
|
98
|
+
let reportDir;
|
|
99
|
+
let sourceDir;
|
|
100
|
+
const parsed = yargsParser(args, {
|
|
101
|
+
configuration: {
|
|
102
|
+
'camel-case-expansion': false,
|
|
103
|
+
'halt-at-non-option': true,
|
|
104
|
+
'strip-aliased': true,
|
|
105
|
+
'strip-dashed': true,
|
|
106
|
+
},
|
|
107
|
+
alias: {
|
|
108
|
+
'coverage-dir': ['c'],
|
|
109
|
+
'report-dir': ['r'],
|
|
110
|
+
'source-dir': ['d'],
|
|
111
|
+
'minimum': ['m'],
|
|
112
|
+
'optimal': ['o'],
|
|
113
|
+
'sources': ['s'],
|
|
114
|
+
'help': ['h'],
|
|
115
|
+
},
|
|
116
|
+
string: ['coverage-dir', 'report-dir', 'source-dir', 'sources'],
|
|
117
|
+
number: ['minimum', 'optimal'],
|
|
118
|
+
boolean: ['help', 'version'],
|
|
119
|
+
});
|
|
120
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
121
|
+
switch (key) {
|
|
122
|
+
case '_': // extra command line as args
|
|
123
|
+
command.push(...value);
|
|
124
|
+
break;
|
|
125
|
+
case 'coverage-dir':
|
|
126
|
+
coverageDir = value;
|
|
127
|
+
break;
|
|
128
|
+
case 'report-dir':
|
|
129
|
+
reportDir = value;
|
|
130
|
+
break;
|
|
131
|
+
case 'source-dir':
|
|
132
|
+
sourceDir = value;
|
|
133
|
+
break;
|
|
134
|
+
case 'sources':
|
|
135
|
+
globs.push(value);
|
|
136
|
+
break;
|
|
137
|
+
case 'minimum':
|
|
138
|
+
minimumCoverage = value;
|
|
139
|
+
break;
|
|
140
|
+
case 'optimal':
|
|
141
|
+
optimalCoverage = value;
|
|
142
|
+
break;
|
|
143
|
+
case 'help':
|
|
144
|
+
return help();
|
|
145
|
+
case 'version':
|
|
146
|
+
return context.log.notice(`Cov8 ${$gry('ver.')} ${$wnd(version())}`);
|
|
147
|
+
default:
|
|
148
|
+
context.log.error(`Unsupported option ${$wnd(key)} (try ${$wnd('--help')})`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Extra check for command or coverage dir requirement
|
|
153
|
+
if ((command.length === 0) && (!coverageDir)) {
|
|
154
|
+
context.log.error(`Either ${$wnd('--coverage-dir')} or a command must me specified`);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
// Default glob (all JS/TS in the 'src' directory)
|
|
158
|
+
const glob = globs.shift() || '**/*.([cm])?[jt]s';
|
|
159
|
+
const ignore = '**/*.d.([cm])?ts'; // ignore .d.ts!
|
|
160
|
+
// Simply create the Test plug and pass everything to it
|
|
161
|
+
try {
|
|
162
|
+
process.exitCode = 0;
|
|
163
|
+
await async.runAsync(context, async () => {
|
|
164
|
+
let tempDir = undefined;
|
|
165
|
+
if (!coverageDir) {
|
|
166
|
+
const directory = mkdtemp();
|
|
167
|
+
context.log.notice(`Writing coverage data in ${$p(directory)}`);
|
|
168
|
+
coverageDir = tempDir = directory;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const [cmd, ...args] = command;
|
|
172
|
+
if (cmd) {
|
|
173
|
+
const env = {
|
|
174
|
+
...process.env,
|
|
175
|
+
...logging.logOptions.forkEnv(),
|
|
176
|
+
};
|
|
177
|
+
await utils.execChild(cmd, args, { coverageDir, env }, context);
|
|
178
|
+
}
|
|
179
|
+
await find(glob, ...globs, { directory: sourceDir || 'src', ignore })
|
|
180
|
+
.plug(new Coverage(coverageDir, {
|
|
181
|
+
reportDir: reportDir,
|
|
182
|
+
minimumCoverage,
|
|
183
|
+
optimalCoverage,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
if (tempDir)
|
|
188
|
+
await rmrf(tempDir);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
context.log.error(error);
|
|
194
|
+
process.exitCode = 1;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,qDAAqD;AACrD,+BAA+B;AAE/B,OAAO,GAAG,MAAM,SAAS,CAAA;AACzB,OAAO,KAAK,MAAM,WAAW,CAAA;AAE7B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAA;AAC9C,MAAM,IAAI,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,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,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACxB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACtB,CAAC;AACH,CAAC,CAAC,CAAA"}
|
package/dist/coverage.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAS1C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAItE,qBAAa,QAAS,YAAW,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IAGlD,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAHjB,GAAG,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC;IAMzC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CA0IvE"}
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { sep } from 'node:path';
|
|
2
|
+
import { html, initFunction } from '@plugjs/cov8-html';
|
|
3
|
+
import { assert } from '@plugjs/plug/asserts';
|
|
4
|
+
import { Files } from '@plugjs/plug/files';
|
|
5
|
+
import { $gry, $ms, $p, $plur, $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.js";
|
|
9
|
+
import { coverageReport } from "./report.js";
|
|
10
|
+
export class Coverage {
|
|
11
|
+
_coverageDir;
|
|
12
|
+
_options;
|
|
13
|
+
constructor(_coverageDir, _options = {}) {
|
|
14
|
+
this._coverageDir = _coverageDir;
|
|
15
|
+
this._options = _options;
|
|
16
|
+
}
|
|
17
|
+
async pipe(files, context) {
|
|
18
|
+
const coverageDir = context.resolve(this._coverageDir);
|
|
19
|
+
const coverageFiles = [];
|
|
20
|
+
for await (const file of walk(coverageDir, ['coverage-*.json'])) {
|
|
21
|
+
coverageFiles.push(resolveAbsolutePath(coverageDir, file));
|
|
22
|
+
}
|
|
23
|
+
assert(coverageFiles.length > 0, `No coverage files found in ${$p(coverageDir)}`);
|
|
24
|
+
const sourceFiles = [...files.absolutePaths()];
|
|
25
|
+
const ms1 = Date.now();
|
|
26
|
+
const analyser = await createAnalyser(sourceFiles, coverageFiles, this._options.sourceMapBias || 'least_upper_bound', context.log);
|
|
27
|
+
context.log.info('Parsed', coverageFiles.length, 'coverage files', $ms(Date.now() - ms1));
|
|
28
|
+
const ms2 = Date.now();
|
|
29
|
+
const report = await coverageReport(analyser, sourceFiles, context.log);
|
|
30
|
+
context.log.info('Analysed', sourceFiles.length, 'source files', $ms(Date.now() - ms2));
|
|
31
|
+
analyser.destroy();
|
|
32
|
+
const { minimumCoverage = 50, minimumFileCoverage = minimumCoverage, optimalCoverage = Math.round((100 + minimumCoverage) / 2), optimalFileCoverage = Math.round((100 + minimumFileCoverage) / 2), } = this._options;
|
|
33
|
+
let max = 0;
|
|
34
|
+
for (const file in report) {
|
|
35
|
+
if (file.length > max)
|
|
36
|
+
max = file.length;
|
|
37
|
+
}
|
|
38
|
+
let maxLength = 0;
|
|
39
|
+
for (const file in report.results) {
|
|
40
|
+
if (file.length > maxLength)
|
|
41
|
+
maxLength = file.length;
|
|
42
|
+
}
|
|
43
|
+
let fileErrors = 0;
|
|
44
|
+
let fileWarnings = 0;
|
|
45
|
+
const _report = context.log.report('Coverage report');
|
|
46
|
+
for (const [_file, result] of Object.entries(report.results)) {
|
|
47
|
+
const { coverage } = result.nodeCoverage;
|
|
48
|
+
const file = _file;
|
|
49
|
+
if (coverage == null) {
|
|
50
|
+
_report.annotate(NOTICE, file, 'n/a');
|
|
51
|
+
}
|
|
52
|
+
else if (coverage < minimumFileCoverage) {
|
|
53
|
+
_report.annotate(ERROR, file, `${coverage} %`);
|
|
54
|
+
fileErrors++;
|
|
55
|
+
}
|
|
56
|
+
else if (coverage < optimalFileCoverage) {
|
|
57
|
+
_report.annotate(WARN, file, `${coverage} %`);
|
|
58
|
+
fileWarnings++;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
_report.annotate(NOTICE, file, `${coverage} %`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/* coverage ignore if */
|
|
65
|
+
if (report.nodes.coverage == null) {
|
|
66
|
+
const message = 'No coverage data collected';
|
|
67
|
+
_report.add({ level: WARN, message });
|
|
68
|
+
}
|
|
69
|
+
else if (report.nodes.coverage < minimumCoverage) {
|
|
70
|
+
const message = `${$red(`${report.nodes.coverage}%`)} does not meet minimum coverage ${$gry(`(${minimumCoverage}%)`)}`;
|
|
71
|
+
_report.add({ level: ERROR, message });
|
|
72
|
+
}
|
|
73
|
+
else if (report.nodes.coverage < optimalCoverage) {
|
|
74
|
+
const message = `${$ylw(`${report.nodes.coverage}%`)} does not meet optimal coverage ${$gry(`(${optimalCoverage}%)`)}`;
|
|
75
|
+
_report.add({ level: WARN, message });
|
|
76
|
+
}
|
|
77
|
+
if (fileErrors) {
|
|
78
|
+
/* coverage ignore next */
|
|
79
|
+
const f = $plur(fileErrors, 'file does', 'files do');
|
|
80
|
+
const message = `${f} not meet minimum file coverage ${$gry(`(${minimumFileCoverage}%)`)}`;
|
|
81
|
+
_report.add({ level: ERROR, message });
|
|
82
|
+
}
|
|
83
|
+
if (fileWarnings) {
|
|
84
|
+
/* coverage ignore next */
|
|
85
|
+
const f = $plur(fileWarnings, 'file does', 'files do');
|
|
86
|
+
const message = `${f} not meet optimal file coverage ${$gry(`(${optimalFileCoverage}%)`)}`;
|
|
87
|
+
_report.add({ level: WARN, message });
|
|
88
|
+
}
|
|
89
|
+
/* If we don't have to write a report, pass-through the coverage files */
|
|
90
|
+
if (this._options.reportDir == null)
|
|
91
|
+
return _report.done(false);
|
|
92
|
+
/* Create a builder to emit our reports */
|
|
93
|
+
const reportDir = context.resolve(this._options.reportDir);
|
|
94
|
+
const builder = Files.builder(reportDir);
|
|
95
|
+
/* Thresholds to inject in the report */
|
|
96
|
+
const date = new Date().toISOString();
|
|
97
|
+
const thresholds = {
|
|
98
|
+
minimumCoverage,
|
|
99
|
+
minimumFileCoverage,
|
|
100
|
+
optimalCoverage,
|
|
101
|
+
optimalFileCoverage,
|
|
102
|
+
};
|
|
103
|
+
/* The JSON file in the report has *absolute* file paths */
|
|
104
|
+
await builder.write('report.json', JSON.stringify({ ...report, thresholds, date }));
|
|
105
|
+
/* The HTML file rendering our report */
|
|
106
|
+
await builder.write('index.html', html);
|
|
107
|
+
/* The JSONP file (for our HTML report) has relative files and a tree */
|
|
108
|
+
const results = {};
|
|
109
|
+
for (const [rel, abs] of files.pathMappings()) {
|
|
110
|
+
results[rel] = report.results[abs];
|
|
111
|
+
}
|
|
112
|
+
const tree = {};
|
|
113
|
+
for (const relative of Object.keys(results)) {
|
|
114
|
+
const directories = relative.split(sep);
|
|
115
|
+
const file = directories.pop();
|
|
116
|
+
let node = tree;
|
|
117
|
+
for (const dir of directories) {
|
|
118
|
+
node = node[dir] = node[dir] || {};
|
|
119
|
+
}
|
|
120
|
+
node[file] = relative;
|
|
121
|
+
}
|
|
122
|
+
const jsonp = JSON.stringify({ ...report, results, thresholds, tree, date });
|
|
123
|
+
await builder.write('report.js', `${initFunction}(${jsonp});`);
|
|
124
|
+
/* Emit our coverage report */
|
|
125
|
+
_report.done(false);
|
|
126
|
+
/* Return emitted files */
|
|
127
|
+
return builder.build();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=coverage.js.map
|