monocart-coverage-reports 2.0.10 → 2.2.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/lib/index.d.ts CHANGED
@@ -1,167 +1,242 @@
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
+ /** V8 lines only */
108
+ blank?: number;
109
+ /** V8 lines only */
110
+ comment?: number;
111
+ }
112
+
113
+ export interface CoverageSummary {
114
+ functions: MetricsSummary;
115
+ branches: MetricsSummary;
116
+ lines: MetricsSummary;
117
+ /** V8 only */
118
+ bytes?: MetricsSummary;
119
+ /** Istanbul only */
120
+ statements?: MetricsSummary;
121
+ }
122
+
123
+ /** V8 only */
124
+ export interface CoverageRange {
125
+ start: number;
126
+ end: number;
127
+ count: number;
128
+ ignored?: boolean;
129
+ none?: boolean;
130
+ }
131
+
132
+ export interface CoverageFile {
133
+ sourcePath: string;
134
+ summary: CoverageSummary;
135
+ /** V8 only */
136
+ url?: string;
137
+ /** V8 only */
138
+ id?: string;
139
+ /** V8 only */
140
+ type?: string;
141
+ /** V8 only */
142
+ source?: string;
143
+ /** V8 only */
144
+ distFile?: string;
145
+ /** V8 only */
146
+ js?: boolean;
147
+ /** V8 only */
148
+ data?: {
149
+ bytes: CoverageRange[];
150
+ functions: CoverageRange[];
151
+ branches: CoverageRange[];
152
+ }
153
+ }
154
+
155
+ export type CoverageResults = {
156
+ type: "v8" | "istanbul";
157
+ reportPath: string;
158
+ name: string;
159
+ watermarks: Watermarks;
160
+ summary: CoverageSummary;
161
+ files: CoverageFile[];
162
+ } | undefined;
163
+
164
+ export interface CoverageReportOptions {
165
+
166
+ /** {string} logging levels: off, error, info, debug */
167
+ logging?: string;
168
+
169
+ /** {string} output dir */
170
+ outputDir?: string;
171
+
172
+ /** {string} v8 or html for istanbul by default
173
+ * {array} multiple reports with options
174
+ * v8 report or istanbul supported reports */
175
+ reports?: string | ReportDescription[];
176
+
177
+ /** {string} Report name. Defaults to "Coverage Report". */
178
+ name?: string;
179
+
180
+ /** (V8 only) {string} Output [sub dir/]filename. Defaults to "index.html" */
181
+ outputFile?: string;
182
+ /** (V8 only) {boolean} Inline all scripts to the single HTML file. Defaults to false. */
183
+ inline?: boolean;
184
+ /** (V8 only) {string} Assets path if not inline. Defaults to "./assets" */
185
+ assetsPath?: string;
186
+
187
+ /** (V8 only) {function} A filter function to execute for each element in the V8 list. */
188
+ entryFilter?: (entry: V8CoverageEntry) => boolean;
189
+
190
+ /** (V8 only) {function} A filter function to execute for each element in the sources which unpacked from the source map. */
191
+ sourceFilter?: (sourcePath: string) => boolean;
192
+
193
+ /** (V8 only) {boolean} Enable/Disable ignoring uncovered codes with the special comments: v8 ignore next/next N/start/stop */
194
+ v8Ignore?: boolean;
195
+
196
+ /** (Istanbul only) defaultSummarizer, sourceFinder */
197
+
198
+ /** {boolean} Generate lcov.info file, same as lcovonly report. Defaults to false. */
199
+ lcov?: boolean;
200
+
201
+ /** {function} Source path handler. */
202
+ sourcePath?: (filePath: string) => string;
203
+
204
+ /** {string|function} Specify the report path, especially when there are multiple reports. Defaults to outputDir/index.html. */
205
+ reportPath?: string | (() => string);
206
+
207
+ /** {array} watermarks for low/medium/high. Defaults to [50, 80]
208
+ * {object} { statements:[50,80], functions:[50,80], branches:[50,80], lines:[50,80] }, V8: { bytes:[50,80] } */
209
+ watermarks?: Watermarks;
210
+
211
+ /** {function} onEnd hook */
212
+ onEnd?: (reportData: CoverageResults) => Promise<void>;
213
+ }
214
+
215
+ export class CoverageReport {
216
+
217
+ constructor(options?: CoverageReportOptions);
218
+
219
+ /** add coverage data: {array} V8 format, {object} Istanbul format */
220
+ add: (coverageData: any[] | any) => Promise<AddedResults>;
221
+
222
+ /** generate report */
223
+ generate: () => Promise<CoverageResults>;
224
+
225
+ /** check if cache exists */
226
+ hasCache: () => boolean;
227
+
228
+ /** clean previous cache, return `false` if no cache */
229
+ cleanCache: () => boolean;
230
+ }
231
+
232
+ export interface McrCliOptions extends CoverageReportOptions {
233
+ /** {function} onStart hook */
234
+ onStart?: (coverageReport: CoverageReport) => Promise<void>;
235
+ }
1
236
 
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
237
  }
13
238
 
14
- export type Watermarks = [number, number] | {
15
- statements?: [number, number],
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;
239
+ /** create coverage report */
240
+ declare function MCR(options?: MCR.CoverageReportOptions): MCR.CoverageReport;
166
241
 
167
- export function createCoverageReport(options?: CoverageReportOptions): CoverageReport;
242
+ 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: (Array) V8 format, (Object) Istanbul format
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
- module.exports = CoverageReport;
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 CoverageReport from './index.js';
2
-
3
- export default CoverageReport;
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
- fileSummary.name = node.getRelativeName();
32
- this.files.push(fileSummary);
31
+ const sourcePath = node.getQualifiedName();
32
+ this.files.push({
33
+ sourcePath,
34
+ summary: fileSummary
35
+ });
33
36
  }
34
37
 
35
38
  onEnd() {