monocart-coverage-reports 2.0.9 → 2.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/README.md +14 -15
- package/lib/converter/converter.js +1 -1
- package/lib/default/options.js +18 -18
- package/lib/index.d.ts +236 -163
- package/lib/index.js +8 -6
- package/lib/index.mjs +3 -6
- package/lib/istanbul/istanbul-summary.js +5 -2
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +15 -15
- package/lib/v8/v8.js +1 -3
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/monocart-coverage-reports)
|
|
4
4
|
[](https://www.npmjs.com/package/monocart-coverage-reports)
|
|
5
5
|

|
|
6
|
+

|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
> Code coverage tool to generate native [V8](https://v8.dev/blog/javascript-code-coverage) reports or [Istanbul](https://istanbul.js.org/) reports.
|
|
8
10
|
|
|
@@ -28,12 +30,12 @@
|
|
|
28
30
|
|
|
29
31
|
## Usage
|
|
30
32
|
```js
|
|
31
|
-
const
|
|
33
|
+
const MCR = require('monocart-coverage-reports');
|
|
32
34
|
const options = {
|
|
33
35
|
outputDir: './coverage-reports',
|
|
34
36
|
reports: "v8"
|
|
35
37
|
}
|
|
36
|
-
const coverageReport =
|
|
38
|
+
const coverageReport = MCR(options);
|
|
37
39
|
await coverageReport.add(coverageData1);
|
|
38
40
|
await coverageReport.add(coverageData2);
|
|
39
41
|
const coverageResults = await coverageReport.generate();
|
|
@@ -80,7 +82,7 @@ console.log(coverageResults.summary);
|
|
|
80
82
|
- `text-summary`
|
|
81
83
|
|
|
82
84
|
```js
|
|
83
|
-
const
|
|
85
|
+
const MCR = require('monocart-coverage-reports');
|
|
84
86
|
const options = {
|
|
85
87
|
outputDir: './coverage-reports',
|
|
86
88
|
reports: [
|
|
@@ -95,7 +97,7 @@ const options = {
|
|
|
95
97
|
'lcovonly'
|
|
96
98
|
]
|
|
97
99
|
}
|
|
98
|
-
const coverageReport =
|
|
100
|
+
const coverageReport = MCR(options);
|
|
99
101
|
```
|
|
100
102
|
|
|
101
103
|
## Integration
|
|
@@ -107,26 +109,26 @@ const coverageReport = new CoverageReport(options);
|
|
|
107
109
|
The data will be added to `[outputDir]/.cache`, and the cache will be removed after reports generated.
|
|
108
110
|
- sub process 1
|
|
109
111
|
```js
|
|
110
|
-
const
|
|
112
|
+
const MCR = require('monocart-coverage-reports');
|
|
111
113
|
const options = require('path-to/same-options.js');
|
|
112
|
-
const coverageReport =
|
|
114
|
+
const coverageReport = MCR(options);
|
|
113
115
|
await coverageReport.add(coverageData1);
|
|
114
116
|
```
|
|
115
117
|
|
|
116
118
|
- sub process 2
|
|
117
119
|
```js
|
|
118
|
-
const
|
|
120
|
+
const MCR = require('monocart-coverage-reports');
|
|
119
121
|
const options = require('path-to/same-options.js');
|
|
120
|
-
const coverageReport =
|
|
122
|
+
const coverageReport = MCR(options);
|
|
121
123
|
await coverageReport.add(coverageData2);
|
|
122
124
|
```
|
|
123
125
|
|
|
124
126
|
- main process
|
|
125
127
|
```js
|
|
126
128
|
// after all sub processes finished
|
|
127
|
-
const
|
|
129
|
+
const MCR = require('monocart-coverage-reports');
|
|
128
130
|
const options = require('path-to/same-options.js');
|
|
129
|
-
const coverageReport =
|
|
131
|
+
const coverageReport = MCR(options);
|
|
130
132
|
const coverageResults = await coverageReport.generate();
|
|
131
133
|
console.log(coverageResults.summary);
|
|
132
134
|
```
|
|
@@ -221,9 +223,6 @@ const coverageOptions = {
|
|
|
221
223
|
- example:
|
|
222
224
|
> cross-env NODE_V8_COVERAGE=`.temp/v8-coverage-api` node [./test/test-node-api.js](./test/test-node-api.js)
|
|
223
225
|
|
|
224
|
-
- Using [foreground-child](https://github.com/tapjs/foreground-child) + NODE_V8_COVERAGE
|
|
225
|
-
- example: [./test/test-node-fgc.js](./test/test-node-fgc.js)
|
|
226
|
-
|
|
227
226
|
- Using [Inspector](https://nodejs.org/docs/latest/api/inspector.html) API (or module [collect-v8-coverage](https://github.com/SimenB/collect-v8-coverage))
|
|
228
227
|
- Connecting to the V8 inspector and enable V8 coverage.
|
|
229
228
|
- Taking coverage data and adding to the report after your application runs.
|
|
@@ -326,7 +325,7 @@ const os = platform === 'wind32' ? 'Windows' : 'Other';
|
|
|
326
325
|
|
|
327
326
|
const os = platform === 'wind32' ? 'Windows' /* v8 ignore next */ : 'Other';
|
|
328
327
|
|
|
329
|
-
|
|
328
|
+
// v8 ignore next 3
|
|
330
329
|
if (platform === 'linux') {
|
|
331
330
|
console.info('hello linux');
|
|
332
331
|
}
|
|
@@ -379,7 +378,7 @@ export interface ScriptCoverage {
|
|
|
379
378
|
|
|
380
379
|
export type V8CoverageData = ScriptCoverage[];
|
|
381
380
|
```
|
|
382
|
-
see devtools-protocol [ScriptCoverage](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-ScriptCoverage)
|
|
381
|
+
see devtools-protocol [ScriptCoverage](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-ScriptCoverage) and [v8-coverage](https://github.com/bcoe/v8-coverage)
|
|
383
382
|
|
|
384
383
|
|
|
385
384
|
## Istanbul Introduction
|
|
@@ -24,7 +24,7 @@ const Util = require('../utils/util.js');
|
|
|
24
24
|
const decodeMappings = require('../utils/decode-mappings.js');
|
|
25
25
|
|
|
26
26
|
// position mapping for conversion between offset and line/column
|
|
27
|
-
const { Locator } = require('monocart-formatter
|
|
27
|
+
const { Locator } = require('monocart-formatter');
|
|
28
28
|
const findOriginalRange = require('./find-original-range.js');
|
|
29
29
|
const { getJsAstInfo, getCssAstInfo } = require('./ast.js');
|
|
30
30
|
const { getIgnoredRanges } = require('./ignore.js');
|
package/lib/default/options.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// {string} logging levels: off, error, info, debug
|
|
4
4
|
logging: 'info',
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// {string} output dir
|
|
7
7
|
outputDir: './coverage-reports',
|
|
8
8
|
|
|
9
|
-
//
|
|
10
|
-
//
|
|
9
|
+
// {string} v8 or html for istanbul by default
|
|
10
|
+
// {array} multiple reports with options
|
|
11
11
|
// v8 report or istanbul supported reports
|
|
12
12
|
// reports: [
|
|
13
13
|
// ['v8'],
|
|
@@ -18,19 +18,19 @@ module.exports = {
|
|
|
18
18
|
// ],
|
|
19
19
|
reports: '',
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// {string} Report name. Defaults to "Coverage Report".
|
|
22
22
|
name: 'Coverage Report',
|
|
23
23
|
|
|
24
|
-
//
|
|
24
|
+
// (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html"
|
|
25
25
|
outputFile: 'index.html',
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false.
|
|
28
28
|
inline: false,
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// (V8 only) {string} Assets path if not inline. Defaults to "./assets"
|
|
31
31
|
assetsPath: './assets',
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// (V8 only) {function} A filter function to execute for each element in the V8 list.
|
|
34
34
|
// entryFilter: (entry) => {
|
|
35
35
|
// if (entry.url.indexOf('googleapis.com') !== -1) {
|
|
36
36
|
// return false;
|
|
@@ -39,30 +39,30 @@ module.exports = {
|
|
|
39
39
|
// },
|
|
40
40
|
entryFilter: null,
|
|
41
41
|
|
|
42
|
-
//
|
|
42
|
+
// (V8 only) {function} A filter function to execute for each element in the sources which unpacked from the source map.
|
|
43
43
|
// sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
|
|
44
44
|
sourceFilter: null,
|
|
45
45
|
|
|
46
|
-
//
|
|
46
|
+
// (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop
|
|
47
47
|
v8Ignore: true,
|
|
48
48
|
|
|
49
|
-
//
|
|
49
|
+
// (Istanbul only) defaultSummarizer, sourceFinder
|
|
50
50
|
|
|
51
|
-
//
|
|
51
|
+
// {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false.
|
|
52
52
|
lcov: false,
|
|
53
53
|
|
|
54
|
-
//
|
|
54
|
+
// {function} Source path handler.
|
|
55
55
|
// sourcePath: (filePath) => `wwwroot/${filePath}`,
|
|
56
56
|
sourcePath: null,
|
|
57
57
|
|
|
58
|
-
//
|
|
58
|
+
// {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html.
|
|
59
59
|
reportPath: null,
|
|
60
60
|
|
|
61
|
-
//
|
|
62
|
-
//
|
|
61
|
+
// {array} watermarks for low/medium/high. Defaults to [50, 80]
|
|
62
|
+
// {object} Istanbul: { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] }.
|
|
63
63
|
watermarks: [50, 80],
|
|
64
64
|
|
|
65
|
-
//
|
|
65
|
+
// {function} onEnd hook
|
|
66
66
|
// onEnd: async (reportData) => {}
|
|
67
67
|
onEnd: null
|
|
68
68
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,167 +1,240 @@
|
|
|
1
|
+
declare namespace MCR {
|
|
2
|
+
|
|
3
|
+
export interface V8CoverageEntry {
|
|
4
|
+
url: string;
|
|
5
|
+
/** css only */
|
|
6
|
+
text?: string;
|
|
7
|
+
/** css only */
|
|
8
|
+
ranges?: any[];
|
|
9
|
+
/** js only */
|
|
10
|
+
scriptId?: string;
|
|
11
|
+
/** js only */
|
|
12
|
+
source?: string;
|
|
13
|
+
/** js only */
|
|
14
|
+
functions?: any[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Watermarks = [number, number] | {
|
|
18
|
+
functions?: [number, number];
|
|
19
|
+
branches?: [number, number];
|
|
20
|
+
lines?: [number, number];
|
|
21
|
+
/** V8 only */
|
|
22
|
+
bytes?: [number, number];
|
|
23
|
+
/** Istanbul only */
|
|
24
|
+
statements?: [number, number];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ReportDescription =
|
|
28
|
+
['v8'] | ["v8", {
|
|
29
|
+
outputFile?: string;
|
|
30
|
+
inline?: boolean;
|
|
31
|
+
assetsPath?: string;
|
|
32
|
+
metrics?: Array<"bytes" | "functions" | "branches" | "lines">;
|
|
33
|
+
}] |
|
|
34
|
+
['v8-json'] | ["v8-json", {
|
|
35
|
+
outputFile?: string;
|
|
36
|
+
}] |
|
|
37
|
+
['console-summary'] | ['console-summary', {
|
|
38
|
+
metrics?: Array<"bytes" | "functions" | "branches" | "lines" | "statements">;
|
|
39
|
+
}] |
|
|
40
|
+
['clover'] | ['clover', {
|
|
41
|
+
file?: string;
|
|
42
|
+
}] |
|
|
43
|
+
['cobertura'] | ['cobertura', {
|
|
44
|
+
file?: string;
|
|
45
|
+
timestamp?: string;
|
|
46
|
+
projectRoot?: string;
|
|
47
|
+
}] |
|
|
48
|
+
['html'] | ['html', {
|
|
49
|
+
subdir?: string;
|
|
50
|
+
verbose?: boolean;
|
|
51
|
+
linkMapper?: any;
|
|
52
|
+
skipEmpty?: boolean;
|
|
53
|
+
}] |
|
|
54
|
+
['html-spa'] | ['html-spa', {
|
|
55
|
+
subdir?: string;
|
|
56
|
+
verbose?: boolean;
|
|
57
|
+
linkMapper?: any;
|
|
58
|
+
skipEmpty?: boolean;
|
|
59
|
+
metricsToShow?: Array<"lines" | "branches" | "functions" | "statements">;
|
|
60
|
+
}] |
|
|
61
|
+
['json'] | ['json', {
|
|
62
|
+
file?: string;
|
|
63
|
+
}] |
|
|
64
|
+
['json-summary'] | ['json-summary', {
|
|
65
|
+
file?: string;
|
|
66
|
+
}] |
|
|
67
|
+
['lcov'] | ['lcov', {
|
|
68
|
+
file?: string;
|
|
69
|
+
projectRoot?: string;
|
|
70
|
+
}] |
|
|
71
|
+
['lcovonly'] | ['lcovonly', {
|
|
72
|
+
file?: string;
|
|
73
|
+
projectRoot?: string;
|
|
74
|
+
}] |
|
|
75
|
+
['none'] |
|
|
76
|
+
['teamcity'] | ['teamcity', {
|
|
77
|
+
file?: string;
|
|
78
|
+
blockName?: string;
|
|
79
|
+
}] |
|
|
80
|
+
['text'] | ['text', {
|
|
81
|
+
file?: string;
|
|
82
|
+
maxCols?: number;
|
|
83
|
+
skipEmpty?: boolean;
|
|
84
|
+
skipFull?: boolean;
|
|
85
|
+
}] |
|
|
86
|
+
['text-lcov'] | ['text-lcov', {
|
|
87
|
+
projectRoot?: string;
|
|
88
|
+
}] |
|
|
89
|
+
['text-summary'] | ['text-summary', {
|
|
90
|
+
file?: string;
|
|
91
|
+
}];
|
|
92
|
+
|
|
93
|
+
export type AddedResults = {
|
|
94
|
+
id: string;
|
|
95
|
+
path: string;
|
|
96
|
+
type: "v8" | "istanbul";
|
|
97
|
+
data: any;
|
|
98
|
+
} | undefined;
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
export interface MetricsSummary {
|
|
102
|
+
covered: number;
|
|
103
|
+
uncovered?: number;
|
|
104
|
+
total: number;
|
|
105
|
+
pct: number | "";
|
|
106
|
+
status: "low" | "medium" | "high" | "unknown";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface LinesSummary extends MetricsSummary {
|
|
110
|
+
/** V8 only */
|
|
111
|
+
blank?: number;
|
|
112
|
+
/** V8 only */
|
|
113
|
+
comment?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CoverageSummary {
|
|
117
|
+
functions: MetricsSummary;
|
|
118
|
+
branches: MetricsSummary;
|
|
119
|
+
lines: LinesSummary;
|
|
120
|
+
/** V8 only */
|
|
121
|
+
bytes?: MetricsSummary;
|
|
122
|
+
/** Istanbul only */
|
|
123
|
+
statements?: MetricsSummary;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** V8 only */
|
|
127
|
+
export interface CoverageRange {
|
|
128
|
+
start: number;
|
|
129
|
+
end: number;
|
|
130
|
+
count: number;
|
|
131
|
+
ignored?: boolean;
|
|
132
|
+
none?: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface CoverageFile {
|
|
136
|
+
sourcePath: string;
|
|
137
|
+
summary: CoverageSummary;
|
|
138
|
+
/** V8 only */
|
|
139
|
+
url?: string;
|
|
140
|
+
/** V8 only */
|
|
141
|
+
id?: string;
|
|
142
|
+
/** V8 only */
|
|
143
|
+
type?: string;
|
|
144
|
+
/** V8 only */
|
|
145
|
+
source?: string;
|
|
146
|
+
/** V8 only */
|
|
147
|
+
distFile?: string;
|
|
148
|
+
/** V8 only */
|
|
149
|
+
js?: boolean;
|
|
150
|
+
/** V8 only */
|
|
151
|
+
data?: {
|
|
152
|
+
bytes: CoverageRange[];
|
|
153
|
+
functions: CoverageRange[];
|
|
154
|
+
branches: CoverageRange[];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type CoverageResults = {
|
|
159
|
+
type: "v8" | "istanbul";
|
|
160
|
+
reportPath: string;
|
|
161
|
+
name: string;
|
|
162
|
+
watermarks: Watermarks;
|
|
163
|
+
summary: CoverageSummary;
|
|
164
|
+
files: CoverageFile[];
|
|
165
|
+
} | undefined;
|
|
166
|
+
|
|
167
|
+
export interface CoverageReportOptions {
|
|
168
|
+
|
|
169
|
+
/** {string} logging levels: off, error, info, debug */
|
|
170
|
+
logging?: string;
|
|
171
|
+
|
|
172
|
+
/** {string} output dir */
|
|
173
|
+
outputDir?: string;
|
|
174
|
+
|
|
175
|
+
/** {string} v8 or html for istanbul by default
|
|
176
|
+
* {array} multiple reports with options
|
|
177
|
+
* v8 report or istanbul supported reports */
|
|
178
|
+
reports?: string | ReportDescription[];
|
|
179
|
+
|
|
180
|
+
/** {string} Report name. Defaults to "Coverage Report". */
|
|
181
|
+
name?: string;
|
|
182
|
+
|
|
183
|
+
/** (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html" */
|
|
184
|
+
outputFile?: string;
|
|
185
|
+
/** (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false. */
|
|
186
|
+
inline?: boolean;
|
|
187
|
+
/** (V8 only) {string} Assets path if not inline. Defaults to "./assets" */
|
|
188
|
+
assetsPath?: string;
|
|
189
|
+
|
|
190
|
+
/** (V8 only) {function} A filter function to execute for each element in the V8 list. */
|
|
191
|
+
entryFilter?: (entry: V8CoverageEntry) => boolean;
|
|
192
|
+
|
|
193
|
+
/** (V8 only) {function} A filter function to execute for each element in the sources which unpacked from the source map. */
|
|
194
|
+
sourceFilter?: (sourcePath: string) => boolean;
|
|
195
|
+
|
|
196
|
+
/** (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop */
|
|
197
|
+
v8Ignore?: boolean;
|
|
198
|
+
|
|
199
|
+
/** (Istanbul only) defaultSummarizer, sourceFinder */
|
|
200
|
+
|
|
201
|
+
/** {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false. */
|
|
202
|
+
lcov?: boolean;
|
|
203
|
+
|
|
204
|
+
/** {function} Source path handler. */
|
|
205
|
+
sourcePath?: (filePath: string) => string;
|
|
206
|
+
|
|
207
|
+
/** {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html. */
|
|
208
|
+
reportPath?: string | (() => string);
|
|
209
|
+
|
|
210
|
+
/** {array} watermarks for low/medium/high. Defaults to [50, 80]
|
|
211
|
+
* {object} { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] } */
|
|
212
|
+
watermarks?: Watermarks;
|
|
213
|
+
|
|
214
|
+
/** {function} onEnd hook */
|
|
215
|
+
onEnd?: (reportData: CoverageResults) => Promise<void>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class CoverageReport {
|
|
219
|
+
|
|
220
|
+
constructor(options?: CoverageReportOptions);
|
|
221
|
+
|
|
222
|
+
/** add coverage data: {array} V8 format, {object} Istanbul format */
|
|
223
|
+
add: (coverageData: any[] | any) => Promise<AddedResults>;
|
|
224
|
+
|
|
225
|
+
/** generate report */
|
|
226
|
+
generate: () => Promise<CoverageResults>;
|
|
227
|
+
|
|
228
|
+
/** check if cache exists */
|
|
229
|
+
hasCache: () => boolean;
|
|
230
|
+
|
|
231
|
+
/** clean previous cache, return `false` if no cache */
|
|
232
|
+
cleanCache: () => boolean;
|
|
233
|
+
}
|
|
1
234
|
|
|
2
|
-
// https://playwright.dev/docs/api/class-coverage
|
|
3
|
-
export type V8CoverageEntry = {
|
|
4
|
-
url: string,
|
|
5
|
-
// css
|
|
6
|
-
text?: string,
|
|
7
|
-
ranges?: any[]
|
|
8
|
-
// js
|
|
9
|
-
scriptId?: string,
|
|
10
|
-
source?: string,
|
|
11
|
-
functions?: any[]
|
|
12
235
|
}
|
|
13
236
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
functions?: [number, number],
|
|
17
|
-
branches?: [number, number],
|
|
18
|
-
lines?: [number, number],
|
|
19
|
-
bytes?: [number, number]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type ReportDescription =
|
|
23
|
-
['v8'] | ["v8", {
|
|
24
|
-
outputFile?: string,
|
|
25
|
-
inline?: boolean,
|
|
26
|
-
assetsPath?: string,
|
|
27
|
-
metrics?: Array<"bytes" | "functions" | "branches" | "lines">
|
|
28
|
-
}] |
|
|
29
|
-
['v8-json'] | ["v8-json", {
|
|
30
|
-
outputFile?: string
|
|
31
|
-
}] |
|
|
32
|
-
['console-summary'] | ['console-summary', {
|
|
33
|
-
metrics?: Array<"bytes" | "functions" | "branches" | "lines" | "statements">
|
|
34
|
-
}] |
|
|
35
|
-
['clover'] | ['clover', {
|
|
36
|
-
file?: string
|
|
37
|
-
}] |
|
|
38
|
-
['cobertura'] | ['cobertura', {
|
|
39
|
-
file?: string,
|
|
40
|
-
timestamp?: string,
|
|
41
|
-
projectRoot?: string
|
|
42
|
-
}] |
|
|
43
|
-
['html'] | ['html', {
|
|
44
|
-
subdir?: string,
|
|
45
|
-
verbose?: boolean,
|
|
46
|
-
linkMapper?: any,
|
|
47
|
-
skipEmpty?: boolean
|
|
48
|
-
}] |
|
|
49
|
-
['html-spa'] | ['html-spa', {
|
|
50
|
-
subdir?: string,
|
|
51
|
-
verbose?: boolean,
|
|
52
|
-
linkMapper?: any,
|
|
53
|
-
skipEmpty?: boolean,
|
|
54
|
-
metricsToShow?: Array<"lines" | "branches" | "functions" | "statements">
|
|
55
|
-
}] |
|
|
56
|
-
['json'] | ['json', {
|
|
57
|
-
file?: string
|
|
58
|
-
}] |
|
|
59
|
-
['json-summary'] | ['json-summary', {
|
|
60
|
-
file?: string
|
|
61
|
-
}] |
|
|
62
|
-
['lcov'] | ['lcov', {
|
|
63
|
-
file?: string,
|
|
64
|
-
projectRoot?: string
|
|
65
|
-
}] |
|
|
66
|
-
['lcovonly'] | ['lcovonly', {
|
|
67
|
-
file?: string,
|
|
68
|
-
projectRoot?: string
|
|
69
|
-
}] |
|
|
70
|
-
['none'] |
|
|
71
|
-
['teamcity'] | ['teamcity', {
|
|
72
|
-
file?: string,
|
|
73
|
-
blockName?: string
|
|
74
|
-
}] |
|
|
75
|
-
['text'] | ['text', {
|
|
76
|
-
file?: string,
|
|
77
|
-
maxCols?: number,
|
|
78
|
-
skipEmpty?: boolean,
|
|
79
|
-
skipFull?: boolean
|
|
80
|
-
}] |
|
|
81
|
-
['text-lcov'] | ['text-lcov', {
|
|
82
|
-
projectRoot?: string
|
|
83
|
-
}] |
|
|
84
|
-
['text-summary'] | ['text-summary', {
|
|
85
|
-
file?: string
|
|
86
|
-
}];
|
|
87
|
-
|
|
88
|
-
export type CoverageResults = {
|
|
89
|
-
type: "v8" | "istanbul",
|
|
90
|
-
reportPath: string,
|
|
91
|
-
name: string,
|
|
92
|
-
watermarks: Watermarks,
|
|
93
|
-
summary: any,
|
|
94
|
-
files: any
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type CoverageReportOptions = {
|
|
98
|
-
|
|
99
|
-
// (String) logging levels: off, error, info, debug
|
|
100
|
-
logging?: string,
|
|
101
|
-
|
|
102
|
-
// (String) output dir
|
|
103
|
-
outputDir?: string,
|
|
104
|
-
|
|
105
|
-
// (String) v8 or html for istanbul by default
|
|
106
|
-
// (Array) multiple reports with options
|
|
107
|
-
// v8 report or istanbul supported reports
|
|
108
|
-
reports?: string | ReportDescription[],
|
|
109
|
-
|
|
110
|
-
// (String) Report name. Defaults to "Coverage Report".
|
|
111
|
-
name?: string,
|
|
112
|
-
|
|
113
|
-
// [V8 only](String) Output [sub dir/]filename. Defaults to "index.html"
|
|
114
|
-
outputFile?: string,
|
|
115
|
-
// [V8 only](Boolean) Inline all scripts to the single HTML file. Defaults to false.
|
|
116
|
-
inline?: boolean,
|
|
117
|
-
// [V8 only](String) Assets path if not inline. Defaults to "./assets"
|
|
118
|
-
assetsPath?: string
|
|
119
|
-
|
|
120
|
-
// [V8 only](Function) A filter function to execute for each element in the V8 list.
|
|
121
|
-
entryFilter?: (entry: V8CoverageEntry) => boolean,
|
|
122
|
-
|
|
123
|
-
// [V8 only](Function) A filter function to execute for each element in the sources which unpacked from the source map.
|
|
124
|
-
sourceFilter?: (sourcePath: string) => boolean,
|
|
125
|
-
|
|
126
|
-
// [V8 only](Boolean) Enable/Disable ignoring uncovered codes with the special comments: /* v8 ignore next/next N/start/stop */
|
|
127
|
-
v8Ignore?: boolean,
|
|
128
|
-
|
|
129
|
-
// [Istanbul only] defaultSummarizer, sourceFinder
|
|
130
|
-
|
|
131
|
-
// (Boolean) Generate lcov.info file, same as lcovonly report. Defaults to false.
|
|
132
|
-
lcov?: boolean,
|
|
133
|
-
|
|
134
|
-
// (Function) Source path handler.
|
|
135
|
-
sourcePath?: (filePath: string) => string,
|
|
136
|
-
|
|
137
|
-
// (String|Function) Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html.
|
|
138
|
-
reportPath?: string | (() => string),
|
|
139
|
-
|
|
140
|
-
// (Array) watermarks for low/medium/high. Defaults to [50, 80]
|
|
141
|
-
// (Object) Istanbul: { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] }.
|
|
142
|
-
watermarks?: Watermarks,
|
|
143
|
-
|
|
144
|
-
// (Function) onEnd hook
|
|
145
|
-
onEnd?: (reportData: CoverageResults) => Promise<void>
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export class CoverageReport {
|
|
149
|
-
constructor(options?: CoverageReportOptions);
|
|
150
|
-
|
|
151
|
-
// add coverage data: (Array) V8 format, (Object) Istanbul format
|
|
152
|
-
add: (coverageData: any[] | any) => Promise<any>;
|
|
153
|
-
|
|
154
|
-
// generate report
|
|
155
|
-
generate: () => Promise<CoverageResults>;
|
|
156
|
-
|
|
157
|
-
// check if cache exists
|
|
158
|
-
hasCache: () => boolean;
|
|
159
|
-
|
|
160
|
-
// clean cache
|
|
161
|
-
cleanCache: () => boolean;
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export default CoverageReport;
|
|
237
|
+
/** create coverage report */
|
|
238
|
+
declare function MCR(options?: MCR.CoverageReportOptions): MCR.CoverageReport;
|
|
166
239
|
|
|
167
|
-
export
|
|
240
|
+
export = MCR;
|
package/lib/index.js
CHANGED
|
@@ -8,10 +8,6 @@ const { getCoverageDataList, generateCoverageReports } = require('./generate.js'
|
|
|
8
8
|
|
|
9
9
|
class CoverageReport {
|
|
10
10
|
|
|
11
|
-
static createCoverageReport = (options) => {
|
|
12
|
-
return new CoverageReport(options);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
11
|
constructor(options = {}) {
|
|
16
12
|
this.cacheDirName = '.cache';
|
|
17
13
|
this.options = {
|
|
@@ -42,7 +38,7 @@ class CoverageReport {
|
|
|
42
38
|
this.fixedOptions = true;
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
// add coverage data:
|
|
41
|
+
// add coverage data: {array} V8 format, {object} Istanbul format
|
|
46
42
|
async add(data) {
|
|
47
43
|
|
|
48
44
|
this.initOptions();
|
|
@@ -133,4 +129,10 @@ class CoverageReport {
|
|
|
133
129
|
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
|
|
132
|
+
/** create coverage report */
|
|
133
|
+
const MCR = function(options) {
|
|
134
|
+
return new CoverageReport(options);
|
|
135
|
+
};
|
|
136
|
+
MCR.CoverageReport = CoverageReport;
|
|
137
|
+
|
|
138
|
+
module.exports = MCR;
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export { CoverageReport };
|
|
5
|
-
|
|
6
|
-
export const createCoverageReport = CoverageReport.createCoverageReport;
|
|
1
|
+
import MCR from './index.js';
|
|
2
|
+
export default MCR;
|
|
3
|
+
export const CoverageReport = MCR.CoverageReport;
|
|
@@ -28,8 +28,11 @@ class IstanbulSummary extends ReportBase {
|
|
|
28
28
|
onDetail(node) {
|
|
29
29
|
const fileSummary = node.getCoverageSummary().data;
|
|
30
30
|
this.addStatus(fileSummary);
|
|
31
|
-
|
|
32
|
-
this.files.push(
|
|
31
|
+
const sourcePath = node.getQualifiedName();
|
|
32
|
+
this.files.push({
|
|
33
|
+
sourcePath,
|
|
34
|
+
summary: fileSummary
|
|
35
|
+
});
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
onEnd() {
|