monocart-coverage-reports 2.5.8 → 2.6.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 +21 -21
- package/README.md +787 -763
- package/lib/cli.js +215 -215
- package/lib/converter/ast-visitor.js +675 -666
- package/lib/converter/ast.js +353 -353
- package/lib/converter/collect-source-maps.js +201 -201
- package/lib/converter/converter.js +1487 -1400
- package/lib/converter/find-original-range.js +737 -737
- package/lib/converter/ignore.js +163 -163
- package/lib/converter/info-branch.js +93 -93
- package/lib/converter/info-function.js +63 -63
- package/lib/converter/info-statement.js +43 -43
- package/lib/default/options.js +84 -81
- package/lib/default/template.html +47 -47
- package/lib/generate.js +720 -532
- package/lib/index.d.ts +360 -317
- package/lib/index.js +183 -173
- package/lib/index.mjs +5 -3
- package/lib/istanbul/istanbul-summary.js +70 -63
- package/lib/istanbul/istanbul.js +146 -146
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/platform/concurrency.js +74 -74
- package/lib/platform/share.js +484 -484
- package/lib/utils/dedupe.js +118 -118
- package/lib/utils/request.js +62 -62
- package/lib/utils/snapshot.js +381 -0
- package/lib/utils/source-path.js +179 -165
- package/lib/utils/util.js +526 -526
- package/lib/v8/v8-summary.js +138 -138
- package/lib/v8/v8.js +399 -630
- package/package.json +81 -79
package/lib/utils/source-path.js
CHANGED
|
@@ -1,165 +1,179 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const { fileURLToPath, pathToFileURL } = require('url');
|
|
3
|
-
const Util = require('./util.js');
|
|
4
|
-
|
|
5
|
-
const filterPath = (str) => {
|
|
6
|
-
str = decodeURI(str);
|
|
7
|
-
// remove / of start, end or double, ./ ../
|
|
8
|
-
const ls = str.split('/').map((it) => {
|
|
9
|
-
it = it.trim();
|
|
10
|
-
// remove illegal characters except /
|
|
11
|
-
it = it.replace(/[\\:*?"<>|]/g, '');
|
|
12
|
-
// space
|
|
13
|
-
it = it.replace(/\s+/g, '-');
|
|
14
|
-
return it;
|
|
15
|
-
}).filter((item) => {
|
|
16
|
-
if (!item || item === '.' || item === '..') {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
return ls.join('/');
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getSourcePath = (url, index = '', type = '') => {
|
|
25
|
-
|
|
26
|
-
// no url for anonymous
|
|
27
|
-
if (!url) {
|
|
28
|
-
// anonymous scripts will have __playwright_evaluation_script__ as their URL.
|
|
29
|
-
url = ['anonymous', index ? `-${index}` : '', type ? `.${type}` : ''].join('');
|
|
30
|
-
return filterPath(url);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// already is file url
|
|
34
|
-
if (url.startsWith('file:')) {
|
|
35
|
-
const relPath = Util.relativePath(fileURLToPath(url));
|
|
36
|
-
return filterPath(relPath);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// http/https url, other url
|
|
40
|
-
const urlObj = Util.resolveUrl(url);
|
|
41
|
-
if (urlObj) {
|
|
42
|
-
const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
|
|
43
|
-
// always start with '/'
|
|
44
|
-
const pathname = urlObj.pathname;
|
|
45
|
-
|
|
46
|
-
let p = host + pathname;
|
|
47
|
-
// webpack://monocart-v8/packages/v8/src/app.vue?5cc4
|
|
48
|
-
if (urlObj.search) {
|
|
49
|
-
p += `/${urlObj.search}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return filterPath(p);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// could be path
|
|
56
|
-
const fileUrl = pathToFileURL(url).toString();
|
|
57
|
-
const relPath = Util.relativePath(fileURLToPath(fileUrl));
|
|
58
|
-
return filterPath(relPath);
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const getSourceType = (sourcePath) => {
|
|
63
|
-
let ext = path.extname(sourcePath);
|
|
64
|
-
let type = 'js';
|
|
65
|
-
if (ext) {
|
|
66
|
-
ext = ext.slice(1);
|
|
67
|
-
const reg = /^[a-z0-9]+$/;
|
|
68
|
-
if (reg.test(ext)) {
|
|
69
|
-
type = ext;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return type;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// ========================================================================================================
|
|
77
|
-
|
|
78
|
-
const getSourcePathHandler = (options) => {
|
|
79
|
-
const input = options.sourcePath;
|
|
80
|
-
if (typeof input === 'function') {
|
|
81
|
-
return input;
|
|
82
|
-
}
|
|
83
|
-
// object replace key with value
|
|
84
|
-
if (input && typeof input === 'object') {
|
|
85
|
-
const keys = Object.keys(input).filter((k) => typeof input[k] === 'string');
|
|
86
|
-
if (keys.length) {
|
|
87
|
-
return (filePath) => {
|
|
88
|
-
keys.forEach((k) => {
|
|
89
|
-
filePath = filePath.replace(k, input[k]);
|
|
90
|
-
});
|
|
91
|
-
return filePath;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// ========================================================================================================
|
|
98
|
-
|
|
99
|
-
const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) => {
|
|
100
|
-
if (!sourcePathHandler) {
|
|
101
|
-
return coverageData;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { fileURLToPath, pathToFileURL } = require('url');
|
|
3
|
+
const Util = require('./util.js');
|
|
4
|
+
|
|
5
|
+
const filterPath = (str) => {
|
|
6
|
+
str = decodeURI(str);
|
|
7
|
+
// remove / of start, end or double, ./ ../
|
|
8
|
+
const ls = str.split('/').map((it) => {
|
|
9
|
+
it = it.trim();
|
|
10
|
+
// remove illegal characters except /
|
|
11
|
+
it = it.replace(/[\\:*?"<>|]/g, '');
|
|
12
|
+
// space
|
|
13
|
+
it = it.replace(/\s+/g, '-');
|
|
14
|
+
return it;
|
|
15
|
+
}).filter((item) => {
|
|
16
|
+
if (!item || item === '.' || item === '..') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
});
|
|
21
|
+
return ls.join('/');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getSourcePath = (url, index = '', type = '') => {
|
|
25
|
+
|
|
26
|
+
// no url for anonymous
|
|
27
|
+
if (!url) {
|
|
28
|
+
// anonymous scripts will have __playwright_evaluation_script__ as their URL.
|
|
29
|
+
url = ['anonymous', index ? `-${index}` : '', type ? `.${type}` : ''].join('');
|
|
30
|
+
return filterPath(url);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// already is file url
|
|
34
|
+
if (url.startsWith('file:')) {
|
|
35
|
+
const relPath = Util.relativePath(fileURLToPath(url));
|
|
36
|
+
return filterPath(relPath);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// http/https url, other url
|
|
40
|
+
const urlObj = Util.resolveUrl(url);
|
|
41
|
+
if (urlObj) {
|
|
42
|
+
const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
|
|
43
|
+
// always start with '/'
|
|
44
|
+
const pathname = urlObj.pathname;
|
|
45
|
+
|
|
46
|
+
let p = host + pathname;
|
|
47
|
+
// webpack://monocart-v8/packages/v8/src/app.vue?5cc4
|
|
48
|
+
if (urlObj.search) {
|
|
49
|
+
p += `/${urlObj.search}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return filterPath(p);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// could be path
|
|
56
|
+
const fileUrl = pathToFileURL(url).toString();
|
|
57
|
+
const relPath = Util.relativePath(fileURLToPath(fileUrl));
|
|
58
|
+
return filterPath(relPath);
|
|
59
|
+
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getSourceType = (sourcePath) => {
|
|
63
|
+
let ext = path.extname(sourcePath);
|
|
64
|
+
let type = 'js';
|
|
65
|
+
if (ext) {
|
|
66
|
+
ext = ext.slice(1);
|
|
67
|
+
const reg = /^[a-z0-9]+$/;
|
|
68
|
+
if (reg.test(ext)) {
|
|
69
|
+
type = ext;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return type;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// ========================================================================================================
|
|
77
|
+
|
|
78
|
+
const getSourcePathHandler = (options) => {
|
|
79
|
+
const input = options.sourcePath;
|
|
80
|
+
if (typeof input === 'function') {
|
|
81
|
+
return input;
|
|
82
|
+
}
|
|
83
|
+
// object replace key with value
|
|
84
|
+
if (input && typeof input === 'object') {
|
|
85
|
+
const keys = Object.keys(input).filter((k) => typeof input[k] === 'string');
|
|
86
|
+
if (keys.length) {
|
|
87
|
+
return (filePath) => {
|
|
88
|
+
keys.forEach((k) => {
|
|
89
|
+
filePath = filePath.replace(k, input[k]);
|
|
90
|
+
});
|
|
91
|
+
return filePath;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// ========================================================================================================
|
|
98
|
+
|
|
99
|
+
const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) => {
|
|
100
|
+
if (!sourcePathHandler) {
|
|
101
|
+
return coverageData;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// console.log(fileSources);
|
|
105
|
+
|
|
106
|
+
const newCoverage = {};
|
|
107
|
+
Object.keys(coverageData).forEach((sourcePath) => {
|
|
108
|
+
// previous coverage and source
|
|
109
|
+
const item = coverageData[sourcePath];
|
|
110
|
+
let source = fileSources[sourcePath];
|
|
111
|
+
|
|
112
|
+
// source could be empty string ''
|
|
113
|
+
if (typeof source !== 'string') {
|
|
114
|
+
// read source with original source path first
|
|
115
|
+
source = Util.readFileSync(sourcePath);
|
|
116
|
+
if (typeof source === 'string') {
|
|
117
|
+
fileSources[sourcePath] = source;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// new source path, second is source url
|
|
122
|
+
const newSourcePath = sourcePathHandler(sourcePath, '');
|
|
123
|
+
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
124
|
+
sourcePath = newSourcePath;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// update source path
|
|
128
|
+
item.data.path = sourcePath;
|
|
129
|
+
newCoverage[sourcePath] = item;
|
|
130
|
+
// update source for the new path
|
|
131
|
+
if (typeof source === 'string') {
|
|
132
|
+
fileSources[sourcePath] = source;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// console.log(Object.keys(fileSources));
|
|
137
|
+
// console.log(newCoverage);
|
|
138
|
+
|
|
139
|
+
return newCoverage;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// ========================================================================================================
|
|
143
|
+
|
|
144
|
+
const mergeSourceRoot = (sourceRoot, sourceName) => {
|
|
145
|
+
if (sourceName.startsWith(sourceRoot)) {
|
|
146
|
+
return sourceName;
|
|
147
|
+
}
|
|
148
|
+
return sourceRoot + sourceName;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
|
|
152
|
+
// reset sourceRoot
|
|
153
|
+
const sourceRoot = sourceMap.sourceRoot || '';
|
|
154
|
+
sourceMap.sourceRoot = '';
|
|
155
|
+
|
|
156
|
+
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
157
|
+
const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
|
|
158
|
+
|
|
159
|
+
let sourcePath = getSourcePath(sourceUrl, i + 1);
|
|
160
|
+
if (sourcePathHandler) {
|
|
161
|
+
const newSourcePath = sourcePathHandler(sourcePath, sourceUrl);
|
|
162
|
+
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
163
|
+
sourcePath = newSourcePath;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fileUrls[sourcePath] = sourceUrl;
|
|
168
|
+
return sourcePath;
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
module.exports = {
|
|
174
|
+
getSourcePath,
|
|
175
|
+
getSourceType,
|
|
176
|
+
getSourcePathHandler,
|
|
177
|
+
initIstanbulSourcePath,
|
|
178
|
+
initSourceMapSourcePath
|
|
179
|
+
};
|