@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.
- package/LICENSE.md +211 -0
- package/NOTICE.md +13 -0
- package/README.md +7 -0
- package/dist/analysis.cjs +239 -0
- package/dist/analysis.cjs.map +6 -0
- package/dist/analysis.d.ts +104 -0
- package/dist/analysis.mjs +212 -0
- package/dist/analysis.mjs.map +6 -0
- package/dist/coverage.cjs +150 -0
- package/dist/coverage.cjs.map +6 -0
- package/dist/coverage.d.ts +9 -0
- package/dist/coverage.mjs +125 -0
- package/dist/coverage.mjs.map +6 -0
- package/dist/index.cjs +22 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +6 -0
- package/dist/report.cjs +236 -0
- package/dist/report.cjs.map +6 -0
- package/dist/report.d.ts +59 -0
- package/dist/report.mjs +221 -0
- package/dist/report.mjs.map +6 -0
- package/package.json +57 -0
- package/src/analysis.ts +410 -0
- package/src/coverage.ts +164 -0
- package/src/index.ts +62 -0
- package/src/report.ts +376 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
[http://www.apache.org/licenses/](http://www.apache.org/licenses/)
|
|
6
|
+
|
|
7
|
+
##### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
### 1. Definitions.
|
|
10
|
+
|
|
11
|
+
"**License**" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"**Licensor**" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"**Legal Entity**" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"**control**" means **(i)** the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, _or_ **(ii)** ownership of fifty percent (50%) or more of
|
|
23
|
+
the outstanding shares, _or_ **(iii)** beneficial ownership of such
|
|
24
|
+
entity.
|
|
25
|
+
|
|
26
|
+
"**You**" (or "**Your**") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"**Source**" form shall mean the preferred form for making
|
|
30
|
+
modifications, including but not limited to software source code,
|
|
31
|
+
documentation source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"**Object**" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but not
|
|
35
|
+
limited to compiled object code, generated documentation, and
|
|
36
|
+
conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"**Work**" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work (an example
|
|
41
|
+
is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"**Derivative Works**" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"**Contribution**" shall mean any work of authorship, including the
|
|
52
|
+
original version of the Work and any modifications or additions to that
|
|
53
|
+
Work or Derivative Works thereof, that is intentionally submitted to
|
|
54
|
+
Licensor for inclusion in the Work by the copyright owner or by an
|
|
55
|
+
individual or Legal Entity authorized to submit on behalf of the
|
|
56
|
+
copyright owner. For the purposes of this definition, "**submitted**"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent to
|
|
58
|
+
the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "**Not a
|
|
64
|
+
Contribution**".
|
|
65
|
+
|
|
66
|
+
"**Contributor**" shall mean Licensor and any individual or Legal Entity
|
|
67
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
68
|
+
subsequently incorporated within the Work.
|
|
69
|
+
|
|
70
|
+
### 2. Grant of Copyright License.
|
|
71
|
+
|
|
72
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
73
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
74
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
|
75
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
|
76
|
+
and distribute the Work and such Derivative Works in Source or Object
|
|
77
|
+
form.
|
|
78
|
+
|
|
79
|
+
### 3. Grant of Patent License.
|
|
80
|
+
|
|
81
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
82
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
83
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
|
84
|
+
license to make, have made, use, offer to sell, sell, import, and
|
|
85
|
+
otherwise transfer the Work, where such license applies only to those
|
|
86
|
+
patent claims licensable by such Contributor that are necessarily
|
|
87
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
88
|
+
Contribution(s) with the Work to which such Contribution(s) was
|
|
89
|
+
submitted. If You institute patent litigation against any entity
|
|
90
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
91
|
+
the Work or a Contribution incorporated within the Work constitutes
|
|
92
|
+
direct or contributory patent infringement, then any patent licenses
|
|
93
|
+
granted to You under this License for that Work shall terminate as of
|
|
94
|
+
the date such litigation is filed.
|
|
95
|
+
|
|
96
|
+
### 4. Redistribution.
|
|
97
|
+
|
|
98
|
+
You may reproduce and distribute copies of the Work or Derivative Works
|
|
99
|
+
thereof in any medium, with or without modifications, and in Source or
|
|
100
|
+
Object form, provided that You meet the following conditions:
|
|
101
|
+
|
|
102
|
+
<ol type="a">
|
|
103
|
+
<li>You must give any other recipients of the Work or Derivative Works
|
|
104
|
+
a copy of this License; and
|
|
105
|
+
<li>You must cause any modified files to carry prominent notices
|
|
106
|
+
stating that You changed the files; and
|
|
107
|
+
<li>You must retain, in the Source form of any Derivative Works that
|
|
108
|
+
You distribute, all copyright, patent, trademark, and attribution
|
|
109
|
+
notices from the Source form of the Work, excluding those notices
|
|
110
|
+
that do not pertain to any part of the Derivative Works; and
|
|
111
|
+
<li>If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained within
|
|
114
|
+
such NOTICE file, excluding those notices that do not pertain to any
|
|
115
|
+
part of the Derivative Works, in at least one of the following
|
|
116
|
+
places: within a NOTICE text file distributed as part of the
|
|
117
|
+
Derivative Works; within the Source form or documentation, if
|
|
118
|
+
provided along with the Derivative Works; or, within a display
|
|
119
|
+
generated by the Derivative Works, if and wherever such third-party
|
|
120
|
+
notices normally appear. The contents of the NOTICE file are for
|
|
121
|
+
informational purposes only and do not modify the License. You may
|
|
122
|
+
add Your own attribution notices within Derivative Works that You
|
|
123
|
+
distribute, alongside or as an addendum to the NOTICE text from the
|
|
124
|
+
Work, provided that such additional attribution notices cannot be
|
|
125
|
+
construed as modifying the License.
|
|
126
|
+
</ol>
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and may
|
|
129
|
+
provide additional or different license terms and conditions for use,
|
|
130
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
131
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
132
|
+
distribution of the Work otherwise complies with the conditions stated
|
|
133
|
+
in this License.
|
|
134
|
+
|
|
135
|
+
### 5. Submission of Contributions.
|
|
136
|
+
|
|
137
|
+
Unless You explicitly state otherwise, any Contribution intentionally
|
|
138
|
+
submitted for inclusion in the Work by You to the Licensor shall be
|
|
139
|
+
under the terms and conditions of this License, without any additional
|
|
140
|
+
terms or conditions. Notwithstanding the above, nothing herein shall
|
|
141
|
+
supersede or modify the terms of any separate license agreement you may
|
|
142
|
+
have executed with Licensor regarding such Contributions.
|
|
143
|
+
|
|
144
|
+
### 6. Trademarks.
|
|
145
|
+
|
|
146
|
+
This License does not grant permission to use the trade names,
|
|
147
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
148
|
+
required for reasonable and customary use in describing the origin of
|
|
149
|
+
the Work and reproducing the content of the NOTICE file.
|
|
150
|
+
|
|
151
|
+
### 7. Disclaimer of Warranty.
|
|
152
|
+
|
|
153
|
+
Unless required by applicable law or agreed to in writing, Licensor
|
|
154
|
+
provides the Work (and each Contributor provides its Contributions) on
|
|
155
|
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
156
|
+
express or implied, including, without limitation, any warranties or
|
|
157
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
|
|
158
|
+
A PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
159
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
160
|
+
associated with Your exercise of permissions under this License.
|
|
161
|
+
|
|
162
|
+
### 8. Limitation of Liability.
|
|
163
|
+
|
|
164
|
+
In no event and under no legal theory, whether in tort (including
|
|
165
|
+
negligence), contract, or otherwise, unless required by applicable law
|
|
166
|
+
(such as deliberate and grossly negligent acts) or agreed to in writing,
|
|
167
|
+
shall any Contributor be liable to You for damages, including any
|
|
168
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
169
|
+
character arising as a result of this License or out of the use or
|
|
170
|
+
inability to use the Work (including but not limited to damages for loss
|
|
171
|
+
of goodwill, work stoppage, computer failure or malfunction, or any and
|
|
172
|
+
all other commercial damages or losses), even if such Contributor has
|
|
173
|
+
been advised of the possibility of such damages.
|
|
174
|
+
|
|
175
|
+
### 9. Accepting Warranty or Additional Liability.
|
|
176
|
+
|
|
177
|
+
While redistributing the Work or Derivative Works thereof, You may
|
|
178
|
+
choose to offer, and charge a fee for, acceptance of support, warranty,
|
|
179
|
+
indemnity, or other liability obligations and/or rights consistent with
|
|
180
|
+
this License. However, in accepting such obligations, You may act only
|
|
181
|
+
on Your own behalf and on Your sole responsibility, not on behalf of any
|
|
182
|
+
other Contributor, and only if You agree to indemnify, defend, and hold
|
|
183
|
+
each Contributor harmless for any liability incurred by, or claims
|
|
184
|
+
asserted against, such Contributor by reason of your accepting any
|
|
185
|
+
such warranty or additional liability.
|
|
186
|
+
|
|
187
|
+
##### END OF TERMS AND CONDITIONS
|
|
188
|
+
|
|
189
|
+
## APPENDIX: How to apply the Apache License to your work.
|
|
190
|
+
|
|
191
|
+
To apply the Apache License to your work, attach the following
|
|
192
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
193
|
+
replaced with your own identifying information. (Don't include the
|
|
194
|
+
brackets!) The text should be enclosed in the appropriate comment
|
|
195
|
+
syntax for the file format. We also recommend that a file or class name
|
|
196
|
+
and description of purpose be included on the same "printed page" as the
|
|
197
|
+
copyright notice for easier identification within third-party archives.
|
|
198
|
+
|
|
199
|
+
> #### Copyright [yyyy] [name of copyright owner]
|
|
200
|
+
>
|
|
201
|
+
> Licensed under the Apache License, Version 2.0 (the "License");
|
|
202
|
+
> you may not use this file except in compliance with the License.
|
|
203
|
+
> You may obtain a copy of the License at
|
|
204
|
+
>
|
|
205
|
+
> [http://www.apache.org/licenses/](http://www.apache.org/licenses/)
|
|
206
|
+
>
|
|
207
|
+
> Unless required by applicable law or agreed to in writing, software
|
|
208
|
+
> distributed under the License is distributed on an "AS IS" BASIS,
|
|
209
|
+
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
210
|
+
> See the License for the specific language governing permissions and
|
|
211
|
+
> limitations under the License.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2022 Juit GmbH
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
[http://www.apache.org/licenses/](http://www.apache.org/licenses/)
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
// analysis.ts
|
|
21
|
+
var analysis_exports = {};
|
|
22
|
+
__export(analysis_exports, {
|
|
23
|
+
CombiningCoverageAnalyser: () => CombiningCoverageAnalyser,
|
|
24
|
+
SourcesCoverageAnalyser: () => SourcesCoverageAnalyser,
|
|
25
|
+
createAnalyser: () => createAnalyser
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(analysis_exports);
|
|
28
|
+
var import_node_url = require("node:url");
|
|
29
|
+
var import_asserts = require("@plugjs/plug/asserts");
|
|
30
|
+
var import_fs = require("@plugjs/plug/fs");
|
|
31
|
+
var import_logging = require("@plugjs/plug/logging");
|
|
32
|
+
var import_source_map = require("source-map");
|
|
33
|
+
var CoverageAnalyserImpl = class {
|
|
34
|
+
constructor(_log) {
|
|
35
|
+
this._log = _log;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var CoverageResultAnalyser = class extends CoverageAnalyserImpl {
|
|
39
|
+
constructor(log, _result) {
|
|
40
|
+
super(log);
|
|
41
|
+
this._result = _result;
|
|
42
|
+
const _coverage = [];
|
|
43
|
+
for (const coveredFunction of _result.functions) {
|
|
44
|
+
for (const range of coveredFunction.ranges) {
|
|
45
|
+
for (let i = range.startOffset; i < range.endOffset; i++) {
|
|
46
|
+
_coverage[i] = range.count;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this._coverage = _coverage;
|
|
51
|
+
}
|
|
52
|
+
_coverage;
|
|
53
|
+
_lineLengths;
|
|
54
|
+
async init() {
|
|
55
|
+
const filename = (0, import_node_url.fileURLToPath)(this._result.url);
|
|
56
|
+
const source = await (0, import_fs.readFile)(filename, "utf-8");
|
|
57
|
+
this._lineLengths = source.split("\n").map((line) => line.length);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
destroy() {
|
|
61
|
+
}
|
|
62
|
+
coverage(source, line, column) {
|
|
63
|
+
(0, import_asserts.assert)(this._lineLengths, "Analyser not initialized");
|
|
64
|
+
(0, import_asserts.assert)(source === this._result.url, `Wrong source ${source} (should be ${this._result.url})`);
|
|
65
|
+
const { _lineLengths, _coverage } = this;
|
|
66
|
+
let offset = 0;
|
|
67
|
+
for (let l = line - 2; l >= 0; l--)
|
|
68
|
+
offset += _lineLengths[l] + 1;
|
|
69
|
+
return _coverage[offset + column] || 0;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var CoverageSitemapAnalyser = class extends CoverageResultAnalyser {
|
|
73
|
+
constructor(log, result, _sourceMapCache, _sourceMapBias) {
|
|
74
|
+
super(log, result);
|
|
75
|
+
this._sourceMapCache = _sourceMapCache;
|
|
76
|
+
this._sourceMapBias = _sourceMapBias;
|
|
77
|
+
this._lineLengths = _sourceMapCache.lineLengths;
|
|
78
|
+
}
|
|
79
|
+
_preciseMappings = /* @__PURE__ */ new Map();
|
|
80
|
+
_sourceMap;
|
|
81
|
+
_key(source, line, column) {
|
|
82
|
+
return `${line}:${column}:${source}`;
|
|
83
|
+
}
|
|
84
|
+
async init() {
|
|
85
|
+
const sourceMap = this._sourceMapCache.data;
|
|
86
|
+
(0, import_asserts.assert)(sourceMap, "Missing source map data from cache");
|
|
87
|
+
this._sourceMap = await new import_source_map.SourceMapConsumer(sourceMap);
|
|
88
|
+
if (this._sourceMapBias === "none") {
|
|
89
|
+
this._sourceMap.eachMapping((m) => {
|
|
90
|
+
const location = { line: m.generatedLine, column: m.generatedColumn };
|
|
91
|
+
const key = this._key(m.source, m.originalLine, m.originalColumn);
|
|
92
|
+
this._preciseMappings.set(key, location);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
destroy() {
|
|
98
|
+
var _a;
|
|
99
|
+
(_a = this._sourceMap) == null ? void 0 : _a.destroy();
|
|
100
|
+
}
|
|
101
|
+
coverage(source, line, column) {
|
|
102
|
+
(0, import_asserts.assert)(this._sourceMap, "Analyser not initialized");
|
|
103
|
+
if (this._sourceMapBias === "none") {
|
|
104
|
+
const key = this._key(source, line, column);
|
|
105
|
+
const location = this._preciseMappings.get(key);
|
|
106
|
+
if (!location) {
|
|
107
|
+
this._log.debug(`No precise mapping for ${source}:${line}:${column}`);
|
|
108
|
+
return 0;
|
|
109
|
+
} else {
|
|
110
|
+
return super.coverage(this._result.url, location.line, location.column);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const bias = this._sourceMapBias === "greatest_lower_bound" ? import_source_map.SourceMapConsumer.GREATEST_LOWER_BOUND : this._sourceMapBias === "least_upper_bound" ? import_source_map.SourceMapConsumer.LEAST_UPPER_BOUND : void 0;
|
|
114
|
+
const generated = this._sourceMap.generatedPositionFor({ source, line, column, bias });
|
|
115
|
+
if (!generated) {
|
|
116
|
+
this._log.debug(`No position generated for ${source}:${line}:${column}`);
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
if (generated.line == null) {
|
|
120
|
+
this._log.debug(`No line generated for ${source}:${line}:${column}`);
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
if (generated.column == null) {
|
|
124
|
+
this._log.debug(`No column generated for ${source}:${line}:${column}`);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
return super.coverage(this._result.url, generated.line, generated.column);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function combineCoverage(analysers, source, line, column) {
|
|
131
|
+
let coverage = 0;
|
|
132
|
+
if (!analysers)
|
|
133
|
+
return coverage;
|
|
134
|
+
for (const analyser of analysers) {
|
|
135
|
+
coverage += analyser.coverage(source, line, column);
|
|
136
|
+
}
|
|
137
|
+
return coverage;
|
|
138
|
+
}
|
|
139
|
+
var SourcesCoverageAnalyser = class extends CoverageAnalyserImpl {
|
|
140
|
+
constructor(log, _filename) {
|
|
141
|
+
super(log);
|
|
142
|
+
this._filename = _filename;
|
|
143
|
+
}
|
|
144
|
+
_mappings = /* @__PURE__ */ new Map();
|
|
145
|
+
hasMappings() {
|
|
146
|
+
return this._mappings.size > 0;
|
|
147
|
+
}
|
|
148
|
+
add(source, analyser) {
|
|
149
|
+
const analysers = this._mappings.get(source) || /* @__PURE__ */ new Set();
|
|
150
|
+
analysers.add(analyser);
|
|
151
|
+
this._mappings.set(source, analysers);
|
|
152
|
+
}
|
|
153
|
+
async init() {
|
|
154
|
+
this._log.debug("SourcesCoverageAnalyser", (0, import_logging.$p)(this._filename), (0, import_logging.$gry)(`(${this._mappings.size} mappings)`));
|
|
155
|
+
for (const analysers of this._mappings.values()) {
|
|
156
|
+
for (const analyser of analysers) {
|
|
157
|
+
await analyser.init();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
destroy() {
|
|
163
|
+
for (const analysers of this._mappings.values()) {
|
|
164
|
+
for (const analyser of analysers) {
|
|
165
|
+
analyser.destroy();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
coverage(source, line, column) {
|
|
170
|
+
const analysers = this._mappings.get(source);
|
|
171
|
+
return combineCoverage(analysers, source, line, column);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
var CombiningCoverageAnalyser = class extends CoverageAnalyserImpl {
|
|
175
|
+
_analysers = /* @__PURE__ */ new Set();
|
|
176
|
+
add(analyser) {
|
|
177
|
+
this._analysers.add(analyser);
|
|
178
|
+
}
|
|
179
|
+
async init() {
|
|
180
|
+
this._log.debug("CombiningCoverageAnalyser", (0, import_logging.$gry)(`(${this._analysers.size} analysers)`));
|
|
181
|
+
this._log.enter();
|
|
182
|
+
try {
|
|
183
|
+
for (const analyser of this._analysers)
|
|
184
|
+
await analyser.init();
|
|
185
|
+
return this;
|
|
186
|
+
} finally {
|
|
187
|
+
this._log.leave();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
destroy() {
|
|
191
|
+
for (const analyser of this._analysers)
|
|
192
|
+
analyser.destroy();
|
|
193
|
+
}
|
|
194
|
+
coverage(source, line, column) {
|
|
195
|
+
return combineCoverage(this._analysers, source, line, column);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
async function createAnalyser(sourceFiles, coverageFiles, sourceMapBias, log) {
|
|
199
|
+
var _a;
|
|
200
|
+
const urls = sourceFiles.map((path) => (0, import_node_url.pathToFileURL)(path).toString());
|
|
201
|
+
const analyser = new CombiningCoverageAnalyser(log);
|
|
202
|
+
for await (const coverageFile of coverageFiles) {
|
|
203
|
+
const coverageFileAnalyser = new SourcesCoverageAnalyser(log, coverageFile);
|
|
204
|
+
log.info("Parsing coverage file", (0, import_logging.$p)(coverageFile));
|
|
205
|
+
const contents = await (0, import_fs.readFile)(coverageFile, "utf-8");
|
|
206
|
+
const coverage = JSON.parse(contents);
|
|
207
|
+
for (const result of coverage.result) {
|
|
208
|
+
if (!result.url.startsWith("node:")) {
|
|
209
|
+
log.debug("Found coverage data for", result.url);
|
|
210
|
+
}
|
|
211
|
+
const mapping = (_a = coverage["source-map-cache"]) == null ? void 0 : _a[result.url];
|
|
212
|
+
if (mapping) {
|
|
213
|
+
log.debug("Found source mapping for", result.url, mapping.data);
|
|
214
|
+
const matches = urls.filter((url) => {
|
|
215
|
+
var _a2;
|
|
216
|
+
return (_a2 = mapping.data) == null ? void 0 : _a2.sources.includes(url);
|
|
217
|
+
});
|
|
218
|
+
if (matches.length) {
|
|
219
|
+
log.debug("Found source mapping matches", matches);
|
|
220
|
+
const sourceAnalyser = new CoverageSitemapAnalyser(log, result, mapping, sourceMapBias);
|
|
221
|
+
for (const match of matches)
|
|
222
|
+
coverageFileAnalyser.add(match, sourceAnalyser);
|
|
223
|
+
}
|
|
224
|
+
} else if (urls.includes(result.url)) {
|
|
225
|
+
coverageFileAnalyser.add(result.url, new CoverageResultAnalyser(log, result));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (coverageFileAnalyser.hasMappings())
|
|
229
|
+
analyser.add(coverageFileAnalyser);
|
|
230
|
+
}
|
|
231
|
+
return await analyser.init();
|
|
232
|
+
}
|
|
233
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
234
|
+
0 && (module.exports = {
|
|
235
|
+
CombiningCoverageAnalyser,
|
|
236
|
+
SourcesCoverageAnalyser,
|
|
237
|
+
createAnalyser
|
|
238
|
+
});
|
|
239
|
+
//# sourceMappingURL=analysis.cjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/analysis.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6C;AAE7C,qBAAuB;AACvB,gBAAyB;AACzB,qBAAyB;AACzB,wBAAkC;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,mBAAmB,QAAQ,WAAW;AAC/C,iBAAW,SAAS,gBAAgB,QAAQ;AAC1C,iBAAS,IAAI,MAAM,aAAa,IAAI,MAAM,WAAW,KAAM;AACzD,oBAAU,KAAK,MAAM;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAEA,SAAK,YAAY;AAAA,EACnB;AAAA,EArBmB;AAAA,EAET;AAAA,EAqBV,MAAM,OAAsB;AAC1B,UAAM,eAAW,+BAAc,KAAK,QAAQ,GAAG;AAC/C,UAAM,SAAS,UAAM,oBAAS,UAAU,OAAO;AAC/C,SAAK,eAAe,OAAO,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,MAAM;AAChE,WAAO;AAAA,EACT;AAAA,EAEA,UAAgB;AAAA,EAEhB;AAAA,EAGA,SAAS,QAAgB,MAAc,QAAwB;AAC7D,+BAAO,KAAK,cAAc,0BAA0B;AACpD,+BAAO,WAAW,KAAK,QAAQ,KAAK,gBAAgB,qBAAqB,KAAK,QAAQ,MAAM;AAE5F,UA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import type { RawSourceMap } from 'source-map';
|
|
4
|
+
/** Coverage range */
|
|
5
|
+
export interface V8CoveredRange {
|
|
6
|
+
/** The offset in the script of the first character covered */
|
|
7
|
+
startOffset: number;
|
|
8
|
+
/** The offset (exclusive) in the script of the last character covered */
|
|
9
|
+
endOffset: number;
|
|
10
|
+
/** The number of times the specified offset was covered */
|
|
11
|
+
count: number;
|
|
12
|
+
}
|
|
13
|
+
/** Coverage report per function as invoked by Node */
|
|
14
|
+
export interface V8CoveredFunction {
|
|
15
|
+
/** The name of the function being covered */
|
|
16
|
+
functionName: string;
|
|
17
|
+
/** A flag indicating whether fine-grained (precise) coverage is available */
|
|
18
|
+
isBlockCoverage: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The ranges covered.
|
|
21
|
+
*
|
|
22
|
+
* The first range indicates the whole function.
|
|
23
|
+
*/
|
|
24
|
+
ranges: V8CoveredRange[];
|
|
25
|
+
}
|
|
26
|
+
/** Coverage result for a particlar script as seen by Node */
|
|
27
|
+
export interface V8CoverageResult {
|
|
28
|
+
/** The script ID, uniquely identifying the script within the Node process */
|
|
29
|
+
scriptId: string;
|
|
30
|
+
/** The URL of the script (might not be unique, if the script is loaded multiple times) */
|
|
31
|
+
url: string;
|
|
32
|
+
/** Per-function report of coverage */
|
|
33
|
+
functions: V8CoveredFunction[];
|
|
34
|
+
}
|
|
35
|
+
/** Cached source map for a coverage result */
|
|
36
|
+
export interface V8SourceMapCache {
|
|
37
|
+
/** The line lengths (sans EOL) in the transpiled code */
|
|
38
|
+
lineLengths: number[];
|
|
39
|
+
/** The source map associated with the transpiled code */
|
|
40
|
+
data: RawSourceMap | null;
|
|
41
|
+
/** The url (if any) of the sourcemap, for resolving relative paths */
|
|
42
|
+
url: string | null;
|
|
43
|
+
}
|
|
44
|
+
/** The RAW coverage data as emitted by Node, parsed from JSON */
|
|
45
|
+
export interface V8CoverageData {
|
|
46
|
+
/**
|
|
47
|
+
* Coverage results, per script.
|
|
48
|
+
*
|
|
49
|
+
* The first element in the array describes the coverage for the whole script.
|
|
50
|
+
*/
|
|
51
|
+
'result': V8CoverageResult[];
|
|
52
|
+
/** Timestamp when coverage was taken */
|
|
53
|
+
'timestamp'?: number;
|
|
54
|
+
/** Source maps caches keyed by `result[?].url` */
|
|
55
|
+
'source-map-cache'?: Record<string, V8SourceMapCache>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The bias for source map analisys (defaults to `least_upper_bound`).
|
|
59
|
+
*
|
|
60
|
+
* We use `least_upper_bound` here, as it's the _opposite_ of the default
|
|
61
|
+
* `greatest_lower_bound`, and we _reverse_ the lookup of the sourcemaps (from
|
|
62
|
+
* source code to generated code).
|
|
63
|
+
*/
|
|
64
|
+
export declare type SourceMapBias = 'greatest_lower_bound' | 'least_upper_bound' | 'none' | undefined;
|
|
65
|
+
/** Interface providing coverage data */
|
|
66
|
+
export interface CoverageAnalyser {
|
|
67
|
+
/** Return the number of coverage passes for the given location */
|
|
68
|
+
coverage(source: string, line: number, column: number): number;
|
|
69
|
+
/** Destroy this instance */
|
|
70
|
+
destroy(): void;
|
|
71
|
+
}
|
|
72
|
+
/** Basic abstract class implementing the {@link CoverageAnalyser} class */
|
|
73
|
+
declare abstract class CoverageAnalyserImpl implements CoverageAnalyser {
|
|
74
|
+
protected readonly _log: Logger;
|
|
75
|
+
constructor(_log: Logger);
|
|
76
|
+
abstract init(): Promise<this>;
|
|
77
|
+
abstract destroy(): void;
|
|
78
|
+
abstract coverage(source: string, line: number, column: number): number;
|
|
79
|
+
}
|
|
80
|
+
/** Associate one or more {@link CoverageAnalyser} with different sources */
|
|
81
|
+
export declare class SourcesCoverageAnalyser extends CoverageAnalyserImpl {
|
|
82
|
+
private readonly _filename;
|
|
83
|
+
private readonly _mappings;
|
|
84
|
+
constructor(log: Logger, _filename: AbsolutePath);
|
|
85
|
+
hasMappings(): boolean;
|
|
86
|
+
add(source: string, analyser: CoverageAnalyserImpl): void;
|
|
87
|
+
init(): Promise<this>;
|
|
88
|
+
destroy(): void;
|
|
89
|
+
coverage(source: string, line: number, column: number): number;
|
|
90
|
+
}
|
|
91
|
+
/** Combine multiple {@link CoverageAnalyser} instances together */
|
|
92
|
+
export declare class CombiningCoverageAnalyser extends CoverageAnalyserImpl {
|
|
93
|
+
private readonly _analysers;
|
|
94
|
+
add(analyser: CoverageAnalyserImpl): void;
|
|
95
|
+
init(): Promise<this>;
|
|
96
|
+
destroy(): void;
|
|
97
|
+
coverage(source: string, line: number, column: number): number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Analyse coverage for the specified source files, using the data from the
|
|
101
|
+
* specified coverage files and produce a {@link CoverageReport}.
|
|
102
|
+
*/
|
|
103
|
+
export declare function createAnalyser(sourceFiles: AbsolutePath[], coverageFiles: AbsolutePath[], sourceMapBias: SourceMapBias, log: Logger): Promise<CoverageAnalyser>;
|
|
104
|
+
export {};
|