monocart-reporter 1.7.13 → 2.0.1
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 +10 -26
- package/lib/generate-data.js +7 -19
- package/lib/generate-report.js +13 -6
- package/lib/index.d.ts +82 -53
- package/lib/index.js +1 -4
- package/lib/index.mjs +0 -1
- package/lib/packages/monocart-common.js +1 -0
- package/lib/packages/monocart-network.js +1 -0
- package/lib/packages/monocart-reporter.js +1 -0
- package/lib/packages/monocart-vendor.js +22 -0
- package/lib/platform/share.js +0 -5
- package/lib/plugins/audit/audit.js +2 -2
- package/lib/plugins/coverage/coverage.js +77 -256
- package/lib/plugins/network/network.js +17 -13
- package/lib/plugins/state/client.js +1 -1
- package/lib/plugins/state/state.js +1 -1
- package/lib/utils/parse-source.js +1 -1
- package/lib/utils/util.js +25 -38
- package/lib/visitor.js +6 -26
- package/package.json +10 -8
- package/lib/plugins/coverage/converter/collect-source-maps.js +0 -194
- package/lib/plugins/coverage/converter/converter.js +0 -565
- package/lib/plugins/coverage/converter/dedupe.js +0 -110
- package/lib/plugins/coverage/converter/find-original-range.js +0 -581
- package/lib/plugins/coverage/converter/info-branch.js +0 -30
- package/lib/plugins/coverage/converter/info-function.js +0 -29
- package/lib/plugins/coverage/converter/info-line.js +0 -20
- package/lib/plugins/coverage/converter/position-mapping.js +0 -183
- package/lib/plugins/coverage/converter/source-path.js +0 -140
- package/lib/plugins/coverage/istanbul/istanbul-summary.js +0 -49
- package/lib/plugins/coverage/istanbul/istanbul.js +0 -171
- package/lib/plugins/coverage/v8/v8-summary.js +0 -80
- package/lib/plugins/coverage/v8/v8.js +0 -260
- package/lib/runtime/monocart-code-viewer.js +0 -1
- package/lib/runtime/monocart-common.js +0 -1
- package/lib/runtime/monocart-coverage.js +0 -14
- package/lib/runtime/monocart-formatter.js +0 -1
- package/lib/runtime/monocart-network.js +0 -1
- package/lib/runtime/monocart-reporter.js +0 -1
- package/lib/runtime/monocart-v8.js +0 -1
- package/lib/runtime/monocart-vendor.js +0 -22
- package/lib/utils/decode-mappings.js +0 -49
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const findLine = function(list, position) {
|
|
3
|
-
let start = 0;
|
|
4
|
-
let end = list.length - 1;
|
|
5
|
-
while (end - start > 1) {
|
|
6
|
-
const i = Math.floor((start + end) * 0.5);
|
|
7
|
-
const item = list[i];
|
|
8
|
-
if (position < item.start) {
|
|
9
|
-
end = i;
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
if (position > item.end) {
|
|
13
|
-
start = i;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
return list[i];
|
|
17
|
-
}
|
|
18
|
-
// last two items, less is start
|
|
19
|
-
const endItem = list[end];
|
|
20
|
-
if (position < endItem.start) {
|
|
21
|
-
return list[start];
|
|
22
|
-
}
|
|
23
|
-
return list[end];
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// =======================================================================================
|
|
27
|
-
|
|
28
|
-
const isLineSingleCommented = (codeStr) => {
|
|
29
|
-
const singleBlock = /^\s*\/\//g;
|
|
30
|
-
return singleBlock.test(codeStr);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const isLineStartCommented = (codeStr) => {
|
|
34
|
-
const multiStartBlock = /^\s*\/\*/g;
|
|
35
|
-
return multiStartBlock.test(codeStr);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// multi-comment end but not at end
|
|
39
|
-
const isLineEndCommented = (codeStr) => {
|
|
40
|
-
const multiEndBlock = /.*\*\//g;
|
|
41
|
-
return multiEndBlock.test(codeStr);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const isLineEndCommentedToEnd = (codeStr) => {
|
|
45
|
-
const multiEndBlock = /.*\*\/\s*$/g;
|
|
46
|
-
return multiEndBlock.test(codeStr);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const isLineBlank = (codeStr) => {
|
|
50
|
-
const blankBlock = /\S/;
|
|
51
|
-
return !blankBlock.test(codeStr);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
class PositionMapping {
|
|
55
|
-
constructor(source) {
|
|
56
|
-
this.source = source;
|
|
57
|
-
this.lines = this.buildLines(source);
|
|
58
|
-
this.commentedLines = [];
|
|
59
|
-
this.blankLines = [];
|
|
60
|
-
this.parseLines(this.lines);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// =============================================================================
|
|
64
|
-
|
|
65
|
-
getSlice(s, e) {
|
|
66
|
-
return this.source.slice(s, e);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 1-base
|
|
70
|
-
locationToOffset(location) {
|
|
71
|
-
const { line, column } = location;
|
|
72
|
-
// 1-based
|
|
73
|
-
const lineInfo = this.lines[line - 1];
|
|
74
|
-
if (lineInfo) {
|
|
75
|
-
if (column === Infinity) {
|
|
76
|
-
return lineInfo.start + lineInfo.length;
|
|
77
|
-
}
|
|
78
|
-
return lineInfo.start + column;
|
|
79
|
-
}
|
|
80
|
-
return 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 1-base
|
|
84
|
-
offsetToLocation(offset) {
|
|
85
|
-
const lineInfo = findLine(this.lines, offset);
|
|
86
|
-
|
|
87
|
-
let indent = lineInfo.text.search(/\S/);
|
|
88
|
-
if (indent === -1) {
|
|
89
|
-
indent = lineInfo.length;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 1-base
|
|
93
|
-
const line = lineInfo.line + 1;
|
|
94
|
-
const column = Math.min(Math.max(offset - lineInfo.start, 0), lineInfo.length);
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
... lineInfo,
|
|
98
|
-
line,
|
|
99
|
-
column,
|
|
100
|
-
indent
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 1-base
|
|
105
|
-
getLine(line) {
|
|
106
|
-
return this.lines[line - 1];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// =============================================================================
|
|
110
|
-
|
|
111
|
-
buildLines(content) {
|
|
112
|
-
let pos = 0;
|
|
113
|
-
const lines = content.split(/\n/).map((text, line) => {
|
|
114
|
-
|
|
115
|
-
let n = 1;
|
|
116
|
-
// may ends with \r (don't consider double \r\r for now)
|
|
117
|
-
const reg = /\r$/;
|
|
118
|
-
if (reg.test(text)) {
|
|
119
|
-
text = text.slice(0, -1);
|
|
120
|
-
n += 1;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const length = text.length;
|
|
124
|
-
const start = pos;
|
|
125
|
-
const end = start + length;
|
|
126
|
-
|
|
127
|
-
pos += length + n;
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
line,
|
|
131
|
-
start,
|
|
132
|
-
end,
|
|
133
|
-
length,
|
|
134
|
-
text
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
return lines;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
parseLines(lines) {
|
|
142
|
-
const commentedLines = [];
|
|
143
|
-
const blankLines = [];
|
|
144
|
-
|
|
145
|
-
let startCommented = false;
|
|
146
|
-
|
|
147
|
-
const multiEndHandler = (text, i) => {
|
|
148
|
-
if (isLineEndCommented(text)) {
|
|
149
|
-
startCommented = false;
|
|
150
|
-
if (isLineEndCommentedToEnd(text)) {
|
|
151
|
-
commentedLines.push(i);
|
|
152
|
-
}
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
commentedLines.push(i);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
lines.forEach((line, i) => {
|
|
159
|
-
const text = line.text;
|
|
160
|
-
if (startCommented) {
|
|
161
|
-
return multiEndHandler(text, i);
|
|
162
|
-
}
|
|
163
|
-
if (isLineStartCommented(text)) {
|
|
164
|
-
startCommented = true;
|
|
165
|
-
return multiEndHandler(text, i);
|
|
166
|
-
}
|
|
167
|
-
if (isLineSingleCommented(text)) {
|
|
168
|
-
commentedLines.push(i);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (isLineBlank(text)) {
|
|
172
|
-
blankLines.push(i);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
this.commentedLines = commentedLines;
|
|
177
|
-
this.blankLines = blankLines;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
module.exports = PositionMapping;
|
|
183
|
-
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Util = require('../../../utils/util.js');
|
|
3
|
-
|
|
4
|
-
const resolveUrl = (input) => {
|
|
5
|
-
let url;
|
|
6
|
-
try {
|
|
7
|
-
url = new URL(input);
|
|
8
|
-
} catch (e) {
|
|
9
|
-
// console.error('error url', input);
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
return url;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const filterPath = (str) => {
|
|
16
|
-
str = decodeURI(str);
|
|
17
|
-
// remove / of start, end or double, ./ ../
|
|
18
|
-
const ls = str.split('/').map((it) => {
|
|
19
|
-
it = it.trim();
|
|
20
|
-
// remove illegal characters except /
|
|
21
|
-
it = it.replace(/[\\:*?"<>|]/g, '');
|
|
22
|
-
// space
|
|
23
|
-
it = it.replace(/\s+/g, '-');
|
|
24
|
-
return it;
|
|
25
|
-
}).filter((item) => {
|
|
26
|
-
if (!item || item === '.' || item === '..') {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
});
|
|
31
|
-
return ls.join('/');
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const getSourcePath = (url, index = '', type = '') => {
|
|
35
|
-
|
|
36
|
-
if (!url) {
|
|
37
|
-
// anonymous scripts will have __playwright_evaluation_script__ as their URL.
|
|
38
|
-
url = ['file://anonymous', index ? `-${index}` : '', type ? `.${type}` : ''].join('');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const u = resolveUrl(url);
|
|
42
|
-
if (u) {
|
|
43
|
-
const host = [u.hostname, u.port].filter((it) => it).join('-');
|
|
44
|
-
// always start with '/'
|
|
45
|
-
const pathname = u.pathname;
|
|
46
|
-
|
|
47
|
-
let p = host + pathname;
|
|
48
|
-
// webpack://monocart-v8/packages/v8/src/app.vue?5cc4
|
|
49
|
-
if (u.search) {
|
|
50
|
-
p += `/${u.search}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return filterPath(p);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const relPath = Util.relativePath(url);
|
|
57
|
-
return filterPath(relPath);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const getSourceType = (sourcePath) => {
|
|
61
|
-
let ext = path.extname(sourcePath);
|
|
62
|
-
let type = '';
|
|
63
|
-
if (ext) {
|
|
64
|
-
ext = ext.slice(1);
|
|
65
|
-
const reg = /^[a-z0-9]+$/;
|
|
66
|
-
if (reg.test(ext)) {
|
|
67
|
-
type = ext;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return type;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// ========================================================================================================
|
|
74
|
-
|
|
75
|
-
const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) => {
|
|
76
|
-
if (typeof sourcePathHandler !== 'function') {
|
|
77
|
-
return coverageData;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const newCoverage = {};
|
|
81
|
-
Object.keys(coverageData).forEach((sourcePath) => {
|
|
82
|
-
// previous coverage and source
|
|
83
|
-
const item = coverageData[sourcePath];
|
|
84
|
-
const source = fileSources[sourcePath];
|
|
85
|
-
|
|
86
|
-
// new source path, second is source url
|
|
87
|
-
const newSourcePath = sourcePathHandler(sourcePath, '');
|
|
88
|
-
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
89
|
-
sourcePath = newSourcePath;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// update source path
|
|
93
|
-
item.path = sourcePath;
|
|
94
|
-
newCoverage[sourcePath] = item;
|
|
95
|
-
// update source for the new path
|
|
96
|
-
if (source) {
|
|
97
|
-
fileSources[sourcePath] = source;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return newCoverage;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// ========================================================================================================
|
|
105
|
-
|
|
106
|
-
const mergeSourceRoot = (sourceRoot, sourceName) => {
|
|
107
|
-
if (sourceName.startsWith(sourceRoot)) {
|
|
108
|
-
return sourceName;
|
|
109
|
-
}
|
|
110
|
-
return sourceRoot + sourceName;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
|
|
114
|
-
// reset sourceRoot
|
|
115
|
-
const sourceRoot = sourceMap.sourceRoot || '';
|
|
116
|
-
sourceMap.sourceRoot = '';
|
|
117
|
-
|
|
118
|
-
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
119
|
-
const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
|
|
120
|
-
|
|
121
|
-
let sourcePath = getSourcePath(sourceUrl, i + 1);
|
|
122
|
-
if (typeof sourcePathHandler === 'function') {
|
|
123
|
-
const newSourcePath = sourcePathHandler(sourcePath, sourceUrl);
|
|
124
|
-
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
125
|
-
sourcePath = newSourcePath;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
fileUrls[sourcePath] = sourceUrl;
|
|
130
|
-
return sourcePath;
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
module.exports = {
|
|
136
|
-
getSourcePath,
|
|
137
|
-
getSourceType,
|
|
138
|
-
initIstanbulSourcePath,
|
|
139
|
-
initSourceMapSourcePath
|
|
140
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const { istanbulLibReport } = require('../../../runtime/monocart-coverage.js');
|
|
2
|
-
|
|
3
|
-
const ReportBase = istanbulLibReport.ReportBase;
|
|
4
|
-
class IstanbulSummary extends ReportBase {
|
|
5
|
-
|
|
6
|
-
onStart(root, context) {
|
|
7
|
-
this.context = context;
|
|
8
|
-
this.summary = {};
|
|
9
|
-
this.files = [];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
addStatus(data) {
|
|
13
|
-
Object.keys(data).forEach((k) => {
|
|
14
|
-
const item = data[k];
|
|
15
|
-
// low, medium, high, unknown
|
|
16
|
-
item.status = this.context.classForPercent(k, item.pct);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
onSummary(node) {
|
|
21
|
-
if (!node.isRoot()) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
this.summary = node.getCoverageSummary().data;
|
|
25
|
-
this.addStatus(this.summary);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
onDetail(node) {
|
|
29
|
-
const fileSummary = node.getCoverageSummary().data;
|
|
30
|
-
this.addStatus(fileSummary);
|
|
31
|
-
fileSummary.name = node.getRelativeName();
|
|
32
|
-
this.files.push(fileSummary);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onEnd() {
|
|
36
|
-
// console.log('onEnd');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getReport() {
|
|
40
|
-
return {
|
|
41
|
-
type: 'istanbul',
|
|
42
|
-
summary: this.summary,
|
|
43
|
-
files: this.files
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
module.exports = IstanbulSummary;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const istanbulReports = require('istanbul-reports');
|
|
5
|
-
|
|
6
|
-
const Util = require('../../../utils/util.js');
|
|
7
|
-
const IstanbulSummary = require('./istanbul-summary.js');
|
|
8
|
-
|
|
9
|
-
const { istanbulLibReport, istanbulLibCoverage } = require('../../../runtime/monocart-coverage.js');
|
|
10
|
-
|
|
11
|
-
const { initIstanbulSourcePath } = require('../converter/source-path.js');
|
|
12
|
-
|
|
13
|
-
const getIstanbulReportList = (toIstanbul) => {
|
|
14
|
-
if (typeof toIstanbul === 'boolean') {
|
|
15
|
-
return [{
|
|
16
|
-
name: 'html-spa',
|
|
17
|
-
options: {}
|
|
18
|
-
}];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof toIstanbul === 'string') {
|
|
22
|
-
return [{
|
|
23
|
-
name: toIstanbul,
|
|
24
|
-
options: {}
|
|
25
|
-
}];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (Array.isArray(toIstanbul)) {
|
|
29
|
-
return toIstanbul.map((item) => {
|
|
30
|
-
if (typeof item === 'string') {
|
|
31
|
-
return {
|
|
32
|
-
name: item,
|
|
33
|
-
options: {}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (item && item.name) {
|
|
37
|
-
return item;
|
|
38
|
-
}
|
|
39
|
-
}).filter((it) => it);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return [{
|
|
43
|
-
name: 'html-spa',
|
|
44
|
-
options: {}
|
|
45
|
-
}];
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
49
|
-
|
|
50
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap(coverageData);
|
|
51
|
-
|
|
52
|
-
const { watermarks, defaultSummarizer } = options;
|
|
53
|
-
const istanbulOptions = {
|
|
54
|
-
watermarks,
|
|
55
|
-
defaultSummarizer
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report
|
|
59
|
-
const contextOptions = {
|
|
60
|
-
watermarks: {
|
|
61
|
-
statements: [50, 80],
|
|
62
|
-
functions: [50, 80],
|
|
63
|
-
branches: [50, 80],
|
|
64
|
-
lines: [50, 80]
|
|
65
|
-
},
|
|
66
|
-
// The summarizer to default to (may be overridden by some reports)
|
|
67
|
-
// values can be nested/flat/pkg. Defaults to 'pkg'
|
|
68
|
-
defaultSummarizer: 'nested',
|
|
69
|
-
|
|
70
|
-
... istanbulOptions,
|
|
71
|
-
|
|
72
|
-
dir: options.htmlDir,
|
|
73
|
-
sourceFinder: (filePath) => {
|
|
74
|
-
|
|
75
|
-
// console.log(`find file source: ${filePath}`);
|
|
76
|
-
|
|
77
|
-
if (fileSources) {
|
|
78
|
-
const source = fileSources[filePath];
|
|
79
|
-
if (source) {
|
|
80
|
-
return source;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (typeof options.sourceFinder === 'function') {
|
|
85
|
-
const source = options.sourceFinder(filePath);
|
|
86
|
-
if (source) {
|
|
87
|
-
return source;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (fs.existsSync(filePath)) {
|
|
92
|
-
return fs.readFileSync(filePath, 'utf8');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// console.log('Not found source file:', filePath);
|
|
96
|
-
|
|
97
|
-
return `Not found source file: ${filePath}`;
|
|
98
|
-
},
|
|
99
|
-
coverageMap
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// create a context for report generation
|
|
103
|
-
const context = istanbulLibReport.createContext(contextOptions);
|
|
104
|
-
|
|
105
|
-
// istanbul reports
|
|
106
|
-
let lcovCreated = false;
|
|
107
|
-
if (options.toIstanbul) {
|
|
108
|
-
const reportList = getIstanbulReportList(options.toIstanbul);
|
|
109
|
-
reportList.forEach((item) => {
|
|
110
|
-
if (item.name === 'lcovonly') {
|
|
111
|
-
lcovCreated = true;
|
|
112
|
-
}
|
|
113
|
-
const report = istanbulReports.create(item.name, item.options || {});
|
|
114
|
-
report.execute(context);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// lcov
|
|
119
|
-
if (!lcovCreated && options.lcov) {
|
|
120
|
-
const lcovReport = istanbulReports.create('lcovonly', {});
|
|
121
|
-
lcovReport.execute(context);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const htmlPath = Util.relativePath(path.resolve(options.htmlDir, 'index.html'));
|
|
125
|
-
|
|
126
|
-
// add watermarks and color
|
|
127
|
-
const coverageReport = new IstanbulSummary();
|
|
128
|
-
coverageReport.execute(context);
|
|
129
|
-
const report = {
|
|
130
|
-
title: options.title,
|
|
131
|
-
htmlPath,
|
|
132
|
-
watermarks: contextOptions.watermarks,
|
|
133
|
-
... coverageReport.getReport()
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
return report;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const mergeIstanbulCoverage = (dataList, options) => {
|
|
140
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
141
|
-
dataList.forEach((item) => {
|
|
142
|
-
coverageMap.merge(item.data);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const istanbulData = coverageMap.toJSON();
|
|
146
|
-
|
|
147
|
-
return istanbulData;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const initIstanbulData = (istanbulData, options) => {
|
|
151
|
-
|
|
152
|
-
// force to istanbul, true is defaults to html-spa
|
|
153
|
-
if (!options.toIstanbul) {
|
|
154
|
-
options.toIstanbul = true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const fileSources = options.fileSources || {};
|
|
158
|
-
|
|
159
|
-
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, options.sourcePath);
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
fileSources,
|
|
163
|
-
coverageData
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
module.exports = {
|
|
168
|
-
saveIstanbulReport,
|
|
169
|
-
mergeIstanbulCoverage,
|
|
170
|
-
initIstanbulData
|
|
171
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// https://playwright.dev/docs/api/class-coverage
|
|
2
|
-
|
|
3
|
-
// url, text, ranges: [ {start, end} ]
|
|
4
|
-
const getCssSummary = (item) => {
|
|
5
|
-
|
|
6
|
-
const source = item.source;
|
|
7
|
-
const total = source.length;
|
|
8
|
-
|
|
9
|
-
let covered = 0;
|
|
10
|
-
const ranges = item.ranges;
|
|
11
|
-
if (ranges) {
|
|
12
|
-
ranges.forEach((range) => {
|
|
13
|
-
covered += range.end - range.start;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const uncovered = total - covered;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
name: item.sourcePath,
|
|
21
|
-
type: item.type,
|
|
22
|
-
url: item.url,
|
|
23
|
-
total,
|
|
24
|
-
covered,
|
|
25
|
-
uncovered
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// url, source, ranges:[{start,end, count}]
|
|
31
|
-
const getJsSummary = (item) => {
|
|
32
|
-
|
|
33
|
-
const source = item.source;
|
|
34
|
-
const total = source.length;
|
|
35
|
-
|
|
36
|
-
const uncoveredRanges = item.ranges.filter((range) => range.count === 0);
|
|
37
|
-
|
|
38
|
-
let uncovered = 0;
|
|
39
|
-
|
|
40
|
-
let endPos = 0;
|
|
41
|
-
uncoveredRanges.forEach((range) => {
|
|
42
|
-
const { start, end } = range;
|
|
43
|
-
|
|
44
|
-
if (start > endPos) {
|
|
45
|
-
uncovered += end - start;
|
|
46
|
-
endPos = end;
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (end <= endPos) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
uncovered += end - endPos;
|
|
55
|
-
endPos = end;
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const covered = total - uncovered;
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
name: item.sourcePath,
|
|
63
|
-
type: item.type,
|
|
64
|
-
url: item.url,
|
|
65
|
-
total,
|
|
66
|
-
covered,
|
|
67
|
-
uncovered
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const getV8Summary = (item) => {
|
|
72
|
-
if (item.type === 'css') {
|
|
73
|
-
return getCssSummary(item);
|
|
74
|
-
}
|
|
75
|
-
return getJsSummary(item);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
module.exports = {
|
|
79
|
-
getV8Summary
|
|
80
|
-
};
|