monocart-coverage-reports 2.3.3 → 2.4.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 +50 -20
- package/lib/converter/ast-visitor.js +646 -0
- package/lib/converter/ast.js +116 -137
- package/lib/converter/collect-source-maps.js +1 -1
- package/lib/converter/converter.js +337 -226
- package/lib/converter/find-original-range.js +471 -411
- package/lib/converter/ignore.js +33 -22
- package/lib/converter/info-branch.js +13 -2
- package/lib/converter/info-function.js +29 -6
- package/lib/converter/info-statement.js +43 -0
- package/lib/default/options.js +1 -1
- package/lib/generate.js +2 -2
- package/lib/index.d.ts +24 -13
- package/lib/istanbul/istanbul.js +1 -1
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +38 -37
- package/lib/platform/share.js +39 -4
- package/lib/utils/util.js +8 -2
- package/lib/v8/v8-summary.js +5 -1
- package/lib/v8/v8.js +4 -1
- package/package.json +3 -3
- package/lib/converter/branches.js +0 -429
- package/lib/converter/find-in-ranges.js +0 -39
- package/lib/converter/info-line.js +0 -23
package/lib/converter/ignore.js
CHANGED
|
@@ -2,7 +2,7 @@ const Util = require('../utils/util.js');
|
|
|
2
2
|
|
|
3
3
|
const getNextN = (content, currentLine, item, locator) => {
|
|
4
4
|
|
|
5
|
-
//
|
|
5
|
+
// v-8 ignore next N
|
|
6
6
|
if (content) {
|
|
7
7
|
const n = parseInt(content);
|
|
8
8
|
if (n && n > 0) {
|
|
@@ -20,19 +20,32 @@ const getNextN = (content, currentLine, item, locator) => {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
// v-8 ignore next
|
|
24
24
|
return 1;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
const extendStart = (start, source) => {
|
|
28
|
+
// extend left, include
|
|
29
|
+
while (start > 0 && Util.isBlank(source[start - 1])) {
|
|
30
|
+
start -= 1;
|
|
31
|
+
}
|
|
32
|
+
return start;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const extendEnd = (end, source, maxLength) => {
|
|
36
|
+
// extend right, exclude
|
|
37
|
+
while (end < maxLength && Util.isBlank(source[end])) {
|
|
38
|
+
end += 1;
|
|
39
|
+
}
|
|
40
|
+
return end;
|
|
41
|
+
};
|
|
42
|
+
|
|
27
43
|
const addNextIgnore = (list, content, item, locator) => {
|
|
28
44
|
|
|
29
45
|
const { lineParser, source } = locator;
|
|
30
46
|
const maxLength = source.length;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
while (startOffset > 0 && Util.isBlank(source[startOffset - 1])) {
|
|
34
|
-
startOffset -= 1;
|
|
35
|
-
}
|
|
47
|
+
|
|
48
|
+
const start = extendStart(item.start, source);
|
|
36
49
|
|
|
37
50
|
// findLine 0-base
|
|
38
51
|
const currentLine = lineParser.findLine(item.end);
|
|
@@ -43,17 +56,13 @@ const addNextIgnore = (list, content, item, locator) => {
|
|
|
43
56
|
// getLine 1-base
|
|
44
57
|
const line = currentLine.line + 1;
|
|
45
58
|
const endLine = locator.getLine(line + n);
|
|
46
|
-
|
|
47
|
-
// extend right
|
|
48
|
-
while (endOffset < maxLength && Util.isBlank(source[endOffset + 1])) {
|
|
49
|
-
endOffset += 1;
|
|
50
|
-
}
|
|
59
|
+
const end = extendEnd(endLine ? endLine.end : maxLength, source, maxLength);
|
|
51
60
|
|
|
52
61
|
const nextItem = {
|
|
53
62
|
type: 'next',
|
|
54
63
|
n,
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
start,
|
|
65
|
+
end
|
|
57
66
|
};
|
|
58
67
|
|
|
59
68
|
list.push(nextItem);
|
|
@@ -69,6 +78,7 @@ const hasIgnoreKey = (content) => {
|
|
|
69
78
|
if (content.startsWith(c8Key)) {
|
|
70
79
|
return c8Key.length;
|
|
71
80
|
}
|
|
81
|
+
// istanbul ignore has different rules, can not support it
|
|
72
82
|
};
|
|
73
83
|
|
|
74
84
|
const getIgnoredRanges = (locator, options) => {
|
|
@@ -76,7 +86,8 @@ const getIgnoredRanges = (locator, options) => {
|
|
|
76
86
|
return;
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
const { lineParser } = locator;
|
|
89
|
+
const { lineParser, source } = locator;
|
|
90
|
+
const maxLength = source.length;
|
|
80
91
|
|
|
81
92
|
const comments = lineParser.comments;
|
|
82
93
|
if (!Util.isList(comments)) {
|
|
@@ -101,27 +112,27 @@ const getIgnoredRanges = (locator, options) => {
|
|
|
101
112
|
content = content.slice(ignoreKey).trim();
|
|
102
113
|
|
|
103
114
|
if (ignoreStart) {
|
|
104
|
-
//
|
|
115
|
+
// v-8 ignore stop
|
|
105
116
|
if (content === 'stop') {
|
|
106
|
-
ignoreStart.
|
|
117
|
+
ignoreStart.end = extendEnd(end, source, maxLength);
|
|
107
118
|
ignoreStart = null;
|
|
108
119
|
}
|
|
109
120
|
return;
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
//
|
|
123
|
+
// v-8 ignore start
|
|
113
124
|
if (content === 'start') {
|
|
114
125
|
// add first for sort by start
|
|
115
126
|
ignoreStart = {
|
|
116
127
|
type: 'start-stop',
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
start: extendStart(start, source),
|
|
129
|
+
end: start
|
|
119
130
|
};
|
|
120
131
|
list.push(ignoreStart);
|
|
121
132
|
return;
|
|
122
133
|
}
|
|
123
134
|
|
|
124
|
-
//
|
|
135
|
+
// v-8 ignore next N
|
|
125
136
|
const nextKey = 'next';
|
|
126
137
|
if (content.startsWith(nextKey)) {
|
|
127
138
|
content = content.slice(nextKey.length).trim();
|
|
@@ -132,7 +143,7 @@ const getIgnoredRanges = (locator, options) => {
|
|
|
132
143
|
|
|
133
144
|
// ignore not stop
|
|
134
145
|
if (ignoreStart) {
|
|
135
|
-
ignoreStart.
|
|
146
|
+
ignoreStart.end = locator.source.length;
|
|
136
147
|
ignoreStart = null;
|
|
137
148
|
}
|
|
138
149
|
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
const Util = require('../utils/util.js');
|
|
2
2
|
module.exports = class InfoBranch {
|
|
3
|
-
constructor(
|
|
3
|
+
constructor(data, original) {
|
|
4
|
+
const {
|
|
5
|
+
start, end, locations, type
|
|
6
|
+
} = data;
|
|
7
|
+
|
|
4
8
|
this.start = start;
|
|
5
9
|
this.end = end;
|
|
6
10
|
this.locations = locations;
|
|
7
|
-
this.type = type
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.data = data;
|
|
13
|
+
this.original = original;
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
getRanges() {
|
|
@@ -20,6 +26,11 @@ module.exports = class InfoBranch {
|
|
|
20
26
|
if (item.ignored) {
|
|
21
27
|
range.ignored = true;
|
|
22
28
|
}
|
|
29
|
+
// for debug
|
|
30
|
+
if (Util.isDebug() && this.original) {
|
|
31
|
+
range.generatedStart = item.generatedStart;
|
|
32
|
+
range.generatedEnd = item.generatedEnd;
|
|
33
|
+
}
|
|
23
34
|
return range;
|
|
24
35
|
});
|
|
25
36
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
const Util = require('../utils/util.js');
|
|
2
2
|
module.exports = class InfoFunction {
|
|
3
|
-
constructor(
|
|
3
|
+
constructor(data, original) {
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
start, end, bodyStart, bodyEnd, functionName, count
|
|
7
|
+
} = data;
|
|
8
|
+
|
|
4
9
|
this.start = start;
|
|
5
10
|
this.end = end;
|
|
11
|
+
this.bodyStart = bodyStart;
|
|
12
|
+
this.bodyEnd = bodyEnd;
|
|
6
13
|
this.count = count;
|
|
7
|
-
this.
|
|
14
|
+
this.functionName = functionName;
|
|
15
|
+
this.data = data;
|
|
16
|
+
this.original = original;
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
getRange() {
|
|
@@ -16,13 +25,25 @@ module.exports = class InfoFunction {
|
|
|
16
25
|
if (this.ignored) {
|
|
17
26
|
range.ignored = true;
|
|
18
27
|
}
|
|
28
|
+
// for debug
|
|
29
|
+
if (Util.isDebug() && this.original) {
|
|
30
|
+
range.generatedStart = this.data.generatedStart;
|
|
31
|
+
range.generatedEnd = this.data.generatedEnd;
|
|
32
|
+
}
|
|
19
33
|
return range;
|
|
20
34
|
}
|
|
21
35
|
|
|
22
|
-
generate(locator) {
|
|
36
|
+
generate(locator, index) {
|
|
23
37
|
|
|
24
|
-
const
|
|
38
|
+
const decl = {
|
|
25
39
|
start: this.start,
|
|
40
|
+
end: this.bodyStart
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Util.updateOffsetToLocation(locator, decl);
|
|
44
|
+
|
|
45
|
+
const loc = {
|
|
46
|
+
start: this.bodyStart,
|
|
26
47
|
end: this.end
|
|
27
48
|
};
|
|
28
49
|
|
|
@@ -30,9 +51,11 @@ module.exports = class InfoFunction {
|
|
|
30
51
|
|
|
31
52
|
const line = loc.start.line;
|
|
32
53
|
|
|
54
|
+
const functionName = this.functionName || `(anonymous_${index})`;
|
|
55
|
+
|
|
33
56
|
return {
|
|
34
|
-
name:
|
|
35
|
-
decl:
|
|
57
|
+
name: functionName,
|
|
58
|
+
decl: decl,
|
|
36
59
|
loc: loc,
|
|
37
60
|
line: line
|
|
38
61
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const Util = require('../utils/util.js');
|
|
2
|
+
module.exports = class InfoStatement {
|
|
3
|
+
constructor(data, original) {
|
|
4
|
+
const {
|
|
5
|
+
start, end, count
|
|
6
|
+
} = data;
|
|
7
|
+
|
|
8
|
+
this.start = start;
|
|
9
|
+
this.end = end;
|
|
10
|
+
this.count = count;
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.original = original;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getRange() {
|
|
16
|
+
const range = {
|
|
17
|
+
start: this.start,
|
|
18
|
+
end: this.end,
|
|
19
|
+
count: this.count
|
|
20
|
+
};
|
|
21
|
+
if (this.ignored) {
|
|
22
|
+
range.ignored = true;
|
|
23
|
+
}
|
|
24
|
+
// for debug
|
|
25
|
+
if (Util.isDebug() && this.original) {
|
|
26
|
+
range.generatedStart = this.data.generatedStart;
|
|
27
|
+
range.generatedEnd = this.data.generatedEnd;
|
|
28
|
+
}
|
|
29
|
+
return range;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
generate(locator) {
|
|
33
|
+
|
|
34
|
+
const loc = {
|
|
35
|
+
start: this.start,
|
|
36
|
+
end: this.end
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Util.updateOffsetToLocation(locator, loc);
|
|
40
|
+
|
|
41
|
+
return loc;
|
|
42
|
+
}
|
|
43
|
+
};
|
package/lib/default/options.js
CHANGED
|
@@ -62,7 +62,7 @@ module.exports = {
|
|
|
62
62
|
reportPath: null,
|
|
63
63
|
|
|
64
64
|
// {array} watermarks for low/medium/high. Defaults to [50, 80]
|
|
65
|
-
// {object}
|
|
65
|
+
// {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] }
|
|
66
66
|
watermarks: [50, 80],
|
|
67
67
|
|
|
68
68
|
// {function} onEnd hook
|
package/lib/generate.js
CHANGED
|
@@ -166,8 +166,8 @@ const showConsoleSummary = (reportData, reportOptions, options) => {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
const allMetrics = {
|
|
169
|
-
v8: ['bytes', '
|
|
170
|
-
istanbul: ['statements', '
|
|
169
|
+
v8: ['bytes', 'statements', 'branches', 'functions', 'lines'],
|
|
170
|
+
istanbul: ['statements', 'branches', 'functions', 'lines']
|
|
171
171
|
};
|
|
172
172
|
|
|
173
173
|
let list = allMetrics[type];
|
package/lib/index.d.ts
CHANGED
|
@@ -15,13 +15,12 @@ declare namespace MCR {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export type Watermarks = [number, number] | {
|
|
18
|
-
functions?: [number, number];
|
|
19
|
-
branches?: [number, number];
|
|
20
|
-
lines?: [number, number];
|
|
21
18
|
/** V8 only */
|
|
22
19
|
bytes?: [number, number];
|
|
23
|
-
/** Istanbul only */
|
|
24
20
|
statements?: [number, number];
|
|
21
|
+
branches?: [number, number];
|
|
22
|
+
functions?: [number, number];
|
|
23
|
+
lines?: [number, number];
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export type ReportDescription =
|
|
@@ -29,7 +28,7 @@ declare namespace MCR {
|
|
|
29
28
|
outputFile?: string;
|
|
30
29
|
inline?: boolean;
|
|
31
30
|
assetsPath?: string;
|
|
32
|
-
metrics?: Array<"bytes" | "
|
|
31
|
+
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">;
|
|
33
32
|
}] |
|
|
34
33
|
['v8-json'] | ["v8-json", {
|
|
35
34
|
outputFile?: string;
|
|
@@ -56,7 +55,7 @@ declare namespace MCR {
|
|
|
56
55
|
verbose?: boolean;
|
|
57
56
|
linkMapper?: any;
|
|
58
57
|
skipEmpty?: boolean;
|
|
59
|
-
metricsToShow?: Array<"
|
|
58
|
+
metricsToShow?: Array<"statements" | "branches" | "functions" | "lines">;
|
|
60
59
|
}] |
|
|
61
60
|
['json'] | ['json', {
|
|
62
61
|
file?: string;
|
|
@@ -90,7 +89,7 @@ declare namespace MCR {
|
|
|
90
89
|
file?: string;
|
|
91
90
|
}] |
|
|
92
91
|
['console-summary'] | ['console-summary', {
|
|
93
|
-
metrics?: Array<"bytes" | "
|
|
92
|
+
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">;
|
|
94
93
|
}] |
|
|
95
94
|
['raw'] | ['raw', {
|
|
96
95
|
outputDir?: string;
|
|
@@ -121,13 +120,12 @@ declare namespace MCR {
|
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
export interface CoverageSummary {
|
|
124
|
-
functions: MetricsSummary;
|
|
125
|
-
branches: MetricsSummary;
|
|
126
|
-
lines: MetricsSummary;
|
|
127
123
|
/** V8 only */
|
|
128
124
|
bytes?: MetricsSummary;
|
|
129
|
-
/** Istanbul only */
|
|
130
125
|
statements?: MetricsSummary;
|
|
126
|
+
branches: MetricsSummary;
|
|
127
|
+
functions: MetricsSummary;
|
|
128
|
+
lines: MetricsSummary;
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
/** V8 only */
|
|
@@ -139,6 +137,13 @@ declare namespace MCR {
|
|
|
139
137
|
none?: boolean;
|
|
140
138
|
}
|
|
141
139
|
|
|
140
|
+
export interface IgnoredRange {
|
|
141
|
+
start: number;
|
|
142
|
+
end: number;
|
|
143
|
+
type: string;
|
|
144
|
+
n?: number;
|
|
145
|
+
}
|
|
146
|
+
|
|
142
147
|
export interface CoverageFile {
|
|
143
148
|
sourcePath: string;
|
|
144
149
|
summary: CoverageSummary;
|
|
@@ -157,8 +162,14 @@ declare namespace MCR {
|
|
|
157
162
|
/** V8 only */
|
|
158
163
|
data?: {
|
|
159
164
|
bytes: CoverageRange[];
|
|
160
|
-
|
|
165
|
+
statements: CoverageRange[];
|
|
161
166
|
branches: CoverageRange[];
|
|
167
|
+
functions: CoverageRange[];
|
|
168
|
+
ignores?: IgnoredRange[];
|
|
169
|
+
/** codecov json format */
|
|
170
|
+
lines: {
|
|
171
|
+
[key: string]: number | string
|
|
172
|
+
};
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
175
|
|
|
@@ -218,7 +229,7 @@ declare namespace MCR {
|
|
|
218
229
|
reportPath?: string | (() => string);
|
|
219
230
|
|
|
220
231
|
/** {array} watermarks for low/medium/high. Defaults to [50, 80]
|
|
221
|
-
* {object} {
|
|
232
|
+
* {object} { bytes:[50,80], statements:[50,80], branches:[50,80], functions:[50,80], lines:[50,80] } */
|
|
222
233
|
watermarks?: Watermarks;
|
|
223
234
|
|
|
224
235
|
/** {function} onEnd hook */
|
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -39,8 +39,8 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
|
|
|
39
39
|
|
|
40
40
|
const defaultWatermarks = {
|
|
41
41
|
statements: [50, 80],
|
|
42
|
-
functions: [50, 80],
|
|
43
42
|
branches: [50, 80],
|
|
43
|
+
functions: [50, 80],
|
|
44
44
|
lines: [50, 80]
|
|
45
45
|
};
|
|
46
46
|
const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);
|