monocart-coverage-reports 2.0.6 → 2.0.8
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 +45 -22
- package/lib/converter/ast.js +2 -3
- package/lib/converter/branches.js +1 -37
- package/lib/converter/converter.js +398 -394
- package/lib/converter/find-in-ranges.js +39 -0
- package/lib/converter/ignore.js +130 -0
- package/lib/default/options.js +3 -0
- package/lib/generate.js +75 -67
- package/lib/index.d.ts +8 -2
- package/lib/index.js +1 -5
- package/lib/istanbul/istanbul-summary.js +1 -2
- package/lib/istanbul/istanbul.js +2 -2
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +28 -28
- package/lib/utils/dedupe.js +0 -5
- package/lib/v8/v8-summary.js +85 -34
- package/lib/v8/v8.js +27 -83
- package/package.json +1 -1
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// https://github.com/demurgos/v8-coverage
|
|
2
|
+
/**
|
|
3
|
+
* @ranges is always non-empty. The first range is called the "root range".
|
|
4
|
+
* @isBlockCoverage indicates if the function has block coverage information
|
|
5
|
+
* @false means that there is a single range and its count is the number of times the function was called.
|
|
6
|
+
* @true means that the ranges form a tree of blocks representing how many times each statement or expression inside was executed.
|
|
7
|
+
* It detects skipped or repeated statements. The root range counts the number of function calls.
|
|
8
|
+
*
|
|
9
|
+
* @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
|
|
10
|
+
*/
|
|
11
|
+
// if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.
|
|
12
|
+
|
|
1
13
|
const path = require('path');
|
|
2
14
|
|
|
3
15
|
const Util = require('../utils/util.js');
|
|
@@ -7,6 +19,7 @@ const decodeMappings = require('../utils/decode-mappings.js');
|
|
|
7
19
|
const { Locator } = require('monocart-formatter/node');
|
|
8
20
|
const findOriginalRange = require('./find-original-range.js');
|
|
9
21
|
const { getJsAstInfo, getCssAstInfo } = require('./ast.js');
|
|
22
|
+
const { getIgnoredRanges } = require('./ignore.js');
|
|
10
23
|
|
|
11
24
|
const { dedupeCountRanges } = require('../utils/dedupe.js');
|
|
12
25
|
const { getSourceType, initSourceMapSourcePath } = require('../utils/source-path.js');
|
|
@@ -14,6 +27,121 @@ const { getSourceType, initSourceMapSourcePath } = require('../utils/source-path
|
|
|
14
27
|
const InfoLine = require('./info-line.js');
|
|
15
28
|
const InfoBranch = require('./info-branch.js');
|
|
16
29
|
const InfoFunction = require('./info-function.js');
|
|
30
|
+
const findInRanges = require('./find-in-ranges.js');
|
|
31
|
+
|
|
32
|
+
// ========================================================================================================
|
|
33
|
+
|
|
34
|
+
const handleIgnoredRanges = (list, ignoredRanges) => {
|
|
35
|
+
list.forEach((item) => {
|
|
36
|
+
if (item.count > 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const range = findInRanges(item.start, item.end, ignoredRanges);
|
|
40
|
+
if (range) {
|
|
41
|
+
// console.log(item, range);
|
|
42
|
+
item.ignored = true;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// ========================================================================================================
|
|
48
|
+
|
|
49
|
+
const updateLinesCount = (bytes, locator, lineMap) => {
|
|
50
|
+
bytes.forEach((range) => {
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
start, end, count, ignored
|
|
54
|
+
} = range;
|
|
55
|
+
|
|
56
|
+
const sLoc = locator.offsetToLocation(start);
|
|
57
|
+
const eLoc = locator.offsetToLocation(end);
|
|
58
|
+
|
|
59
|
+
// update lines coverage
|
|
60
|
+
const lines = Util.getRangeLines(sLoc, eLoc);
|
|
61
|
+
|
|
62
|
+
lines.forEach((it) => {
|
|
63
|
+
const line = lineMap.get(it.line);
|
|
64
|
+
if (!line) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// from outside into inside, uncovered is certain
|
|
69
|
+
// default is covered
|
|
70
|
+
if (it.entire) {
|
|
71
|
+
line.covered = count > 0;
|
|
72
|
+
line.count = count;
|
|
73
|
+
|
|
74
|
+
if (ignored) {
|
|
75
|
+
if (!line.covered) {
|
|
76
|
+
line.ignored = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
} else {
|
|
81
|
+
|
|
82
|
+
if (!ignored) {
|
|
83
|
+
if (count > 0) {
|
|
84
|
+
line.count = count;
|
|
85
|
+
} else {
|
|
86
|
+
// not covered if any count = 0
|
|
87
|
+
line.covered = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// if (!line.history) {
|
|
94
|
+
// line.history = [];
|
|
95
|
+
// }
|
|
96
|
+
// line.history.push(`${it.entire}-${count}`);
|
|
97
|
+
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// if (state.sourcePath.endsWith('component.js')) {
|
|
103
|
+
// console.log('===========================================', state.sourcePath);
|
|
104
|
+
// console.log(coverageInfo.lines);
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const handleLinesCoverage = (bytes, locator) => {
|
|
110
|
+
|
|
111
|
+
const lines = [];
|
|
112
|
+
// line 1 based
|
|
113
|
+
const lineMap = new Map();
|
|
114
|
+
|
|
115
|
+
// init lines
|
|
116
|
+
let blankCount = 0;
|
|
117
|
+
let commentCount = 0;
|
|
118
|
+
|
|
119
|
+
locator.lines.forEach((it) => {
|
|
120
|
+
// exclude blank and comment
|
|
121
|
+
if (it.blank) {
|
|
122
|
+
blankCount += 1;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (it.comment) {
|
|
126
|
+
commentCount += 1;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// line 1-base
|
|
130
|
+
const line = it.line + 1;
|
|
131
|
+
// default count to 1, both js and css
|
|
132
|
+
const lineInfo = new InfoLine(line, it.length, 1);
|
|
133
|
+
lineMap.set(line, lineInfo);
|
|
134
|
+
lines.push(lineInfo);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
updateLinesCount(bytes, locator, lineMap);
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
lines,
|
|
141
|
+
blankCount,
|
|
142
|
+
commentCount
|
|
143
|
+
};
|
|
144
|
+
};
|
|
17
145
|
|
|
18
146
|
// ========================================================================================================
|
|
19
147
|
|
|
@@ -25,6 +153,10 @@ const calculateV8Functions = (functions) => {
|
|
|
25
153
|
};
|
|
26
154
|
|
|
27
155
|
functions.forEach((fn) => {
|
|
156
|
+
if (fn.ignored) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
28
160
|
v8Functions.total += 1;
|
|
29
161
|
if (fn.count > 0) {
|
|
30
162
|
v8Functions.covered += 1;
|
|
@@ -41,12 +173,13 @@ const calculateV8Branches = (branches) => {
|
|
|
41
173
|
};
|
|
42
174
|
|
|
43
175
|
branches.forEach((branch) => {
|
|
44
|
-
branch.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
176
|
+
if (branch.ignored) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
v8Branches.total += 1;
|
|
180
|
+
if (branch.count > 0) {
|
|
181
|
+
v8Branches.covered += 1;
|
|
182
|
+
}
|
|
50
183
|
});
|
|
51
184
|
|
|
52
185
|
return v8Branches;
|
|
@@ -61,6 +194,10 @@ const calculateV8Lines = (lines, blankCount, commentCount) => {
|
|
|
61
194
|
};
|
|
62
195
|
|
|
63
196
|
lines.forEach((ln) => {
|
|
197
|
+
if (ln.ignored) {
|
|
198
|
+
// console.log(ln);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
64
201
|
v8Lines.total += 1;
|
|
65
202
|
// full line covered
|
|
66
203
|
if (ln.covered) {
|
|
@@ -71,41 +208,19 @@ const calculateV8Lines = (lines, blankCount, commentCount) => {
|
|
|
71
208
|
return v8Lines;
|
|
72
209
|
};
|
|
73
210
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// data for v8 UI
|
|
77
|
-
const data = {
|
|
78
|
-
bytes: [],
|
|
79
|
-
functions: [],
|
|
80
|
-
branches: []
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const branches = [];
|
|
84
|
-
|
|
85
|
-
const functions = [];
|
|
86
|
-
|
|
87
|
-
const lines = [];
|
|
88
|
-
// line 1 based
|
|
89
|
-
const lineMap = new Map();
|
|
90
|
-
|
|
91
|
-
const blankCount = 0;
|
|
92
|
-
const commentCount = 0;
|
|
93
|
-
|
|
211
|
+
// ========================================================================================================
|
|
94
212
|
|
|
213
|
+
const createEmptyCoverageInfo = () => {
|
|
95
214
|
return {
|
|
96
|
-
// v8
|
|
97
|
-
data
|
|
98
|
-
|
|
215
|
+
// v8 UI
|
|
216
|
+
data: {
|
|
217
|
+
bytes: [],
|
|
218
|
+
functions: [],
|
|
219
|
+
branches: []
|
|
220
|
+
},
|
|
99
221
|
// istanbul
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
functions,
|
|
103
|
-
|
|
104
|
-
lines,
|
|
105
|
-
lineMap,
|
|
106
|
-
blankCount,
|
|
107
|
-
commentCount
|
|
108
|
-
|
|
222
|
+
functions: [],
|
|
223
|
+
branches: []
|
|
109
224
|
};
|
|
110
225
|
};
|
|
111
226
|
|
|
@@ -119,32 +234,41 @@ const createEmptyCoverageInfo = () => {
|
|
|
119
234
|
* * `f` - hit count for functions
|
|
120
235
|
* * `b` - hit count for branches
|
|
121
236
|
*/
|
|
122
|
-
const collectFileCoverage = (item,
|
|
237
|
+
const collectFileCoverage = (item, state, coverageData, options) => {
|
|
123
238
|
|
|
124
239
|
const { sourcePath } = item;
|
|
240
|
+
const { coverageInfo, locator } = state;
|
|
125
241
|
|
|
126
242
|
const {
|
|
127
|
-
// v8
|
|
128
243
|
data,
|
|
129
|
-
|
|
130
|
-
// istanbul
|
|
131
|
-
branches,
|
|
132
|
-
|
|
133
244
|
functions,
|
|
134
|
-
|
|
135
|
-
lines,
|
|
136
|
-
blankCount,
|
|
137
|
-
commentCount
|
|
138
|
-
|
|
245
|
+
branches
|
|
139
246
|
} = coverageInfo;
|
|
140
247
|
|
|
141
248
|
// ==========================================
|
|
142
249
|
// v8
|
|
143
250
|
data.bytes = dedupeCountRanges(data.bytes);
|
|
251
|
+
|
|
252
|
+
const ignoredRanges = getIgnoredRanges(locator, options);
|
|
253
|
+
if (ignoredRanges) {
|
|
254
|
+
|
|
255
|
+
handleIgnoredRanges(data.bytes, ignoredRanges);
|
|
256
|
+
handleIgnoredRanges(data.functions, ignoredRanges);
|
|
257
|
+
handleIgnoredRanges(data.branches, ignoredRanges);
|
|
258
|
+
|
|
259
|
+
// console.log(ignoredRanges);
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// after bytes with ignored, before calculateV8Lines
|
|
264
|
+
const {
|
|
265
|
+
lines, blankCount, commentCount
|
|
266
|
+
} = handleLinesCoverage(data.bytes, locator);
|
|
267
|
+
|
|
144
268
|
item.data = data;
|
|
145
269
|
item.summary = {
|
|
146
|
-
functions: calculateV8Functions(functions),
|
|
147
|
-
branches: calculateV8Branches(branches),
|
|
270
|
+
functions: calculateV8Functions(data.functions),
|
|
271
|
+
branches: calculateV8Branches(data.branches),
|
|
148
272
|
lines: calculateV8Lines(lines, blankCount, commentCount)
|
|
149
273
|
};
|
|
150
274
|
|
|
@@ -178,118 +302,40 @@ const collectFileCoverage = (item, coverageInfo, state) => {
|
|
|
178
302
|
});
|
|
179
303
|
|
|
180
304
|
// append to dist file state
|
|
181
|
-
|
|
305
|
+
coverageData[sourcePath] = istanbulCoverage;
|
|
182
306
|
|
|
183
307
|
};
|
|
184
308
|
|
|
185
309
|
// ========================================================================================================
|
|
186
310
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* @isBlockCoverage indicates if the function has block coverage information
|
|
191
|
-
* @false means that there is a single range and its count is the number of times the function was called.
|
|
192
|
-
* @true means that the ranges form a tree of blocks representing how many times each statement or expression inside was executed.
|
|
193
|
-
* It detects skipped or repeated statements. The root range counts the number of function calls.
|
|
194
|
-
*
|
|
195
|
-
* @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
|
|
196
|
-
*/
|
|
197
|
-
// if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.
|
|
198
|
-
|
|
199
|
-
const addJsLineCoverage = (state, range) => {
|
|
200
|
-
|
|
201
|
-
const { locator, coverageInfo } = state;
|
|
202
|
-
|
|
203
|
-
const { data, lineMap } = coverageInfo;
|
|
204
|
-
|
|
311
|
+
const addJsBytesCoverage = (state, range) => {
|
|
312
|
+
const { coverageInfo } = state;
|
|
313
|
+
const { data } = coverageInfo;
|
|
205
314
|
const {
|
|
206
315
|
startOffset, endOffset, count
|
|
207
316
|
} = range;
|
|
208
|
-
|
|
209
317
|
// add bytes range
|
|
210
318
|
data.bytes.push({
|
|
211
|
-
// index,
|
|
212
319
|
start: startOffset,
|
|
213
320
|
end: endOffset,
|
|
214
321
|
count
|
|
215
322
|
});
|
|
216
|
-
|
|
217
|
-
const sLoc = locator.offsetToLocation(startOffset);
|
|
218
|
-
const eLoc = locator.offsetToLocation(endOffset);
|
|
219
|
-
|
|
220
|
-
// update lines coverage
|
|
221
|
-
const lines = Util.getRangeLines(sLoc, eLoc);
|
|
222
|
-
|
|
223
|
-
lines.forEach((it) => {
|
|
224
|
-
const line = lineMap.get(it.line);
|
|
225
|
-
if (!line) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// from outside into inside, uncovered is certain
|
|
230
|
-
// default is covered
|
|
231
|
-
if (it.entire) {
|
|
232
|
-
line.covered = count > 0;
|
|
233
|
-
line.count = count;
|
|
234
|
-
} else {
|
|
235
|
-
if (count > 0) {
|
|
236
|
-
line.count = count;
|
|
237
|
-
} else {
|
|
238
|
-
// not covered if any count = 0
|
|
239
|
-
line.covered = false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// if (!line.history) {
|
|
244
|
-
// line.history = [];
|
|
245
|
-
// }
|
|
246
|
-
// line.history.push(`${it.entire}-${count}`);
|
|
247
|
-
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
// if (state.sourcePath.endsWith('component.js')) {
|
|
251
|
-
// console.log('===========================================', state.sourcePath);
|
|
252
|
-
// console.log(coverageInfo.lines);
|
|
253
|
-
// }
|
|
254
|
-
|
|
255
323
|
};
|
|
256
324
|
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
const {
|
|
260
|
-
|
|
261
|
-
const { lineMap, data } = coverageInfo;
|
|
262
|
-
|
|
325
|
+
const addCssBytesCoverage = (state, range) => {
|
|
326
|
+
const { coverageInfo } = state;
|
|
327
|
+
const { data } = coverageInfo;
|
|
263
328
|
const {
|
|
264
329
|
start, end, count
|
|
265
330
|
} = range;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const lines = Util.getRangeLines(sLoc, eLoc);
|
|
273
|
-
lines.forEach((it) => {
|
|
274
|
-
if (!it.entire) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const line = lineMap.get(it.line);
|
|
278
|
-
if (line) {
|
|
279
|
-
// default is uncovered
|
|
280
|
-
// count always 1, covered is certain
|
|
281
|
-
line.covered = true;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// add bytes range
|
|
287
|
-
data.bytes.push(range);
|
|
288
|
-
|
|
331
|
+
// add css bytes range, already start, end
|
|
332
|
+
data.bytes.push({
|
|
333
|
+
start,
|
|
334
|
+
end,
|
|
335
|
+
count
|
|
336
|
+
});
|
|
289
337
|
};
|
|
290
338
|
|
|
291
|
-
// ========================================================================================================
|
|
292
|
-
|
|
293
339
|
const updateOffsetToLocation = (locator, loc) => {
|
|
294
340
|
const sLoc = locator.offsetToLocation(loc.start);
|
|
295
341
|
loc.start = {
|
|
@@ -303,6 +349,8 @@ const updateOffsetToLocation = (locator, loc) => {
|
|
|
303
349
|
};
|
|
304
350
|
};
|
|
305
351
|
|
|
352
|
+
// ========================================================================================================
|
|
353
|
+
|
|
306
354
|
const handleFunctionsCoverage = (state) => {
|
|
307
355
|
|
|
308
356
|
// functions only for js
|
|
@@ -401,90 +449,219 @@ const handleBranchesCoverage = (state) => {
|
|
|
401
449
|
isTanbulBranches.push(branchInfo);
|
|
402
450
|
});
|
|
403
451
|
|
|
404
|
-
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
const handleLinesCoverage = (state) => {
|
|
408
|
-
|
|
409
|
-
const {
|
|
410
|
-
js, locator, coverageInfo
|
|
411
|
-
} = state;
|
|
412
|
-
|
|
413
|
-
const lines = coverageInfo.lines;
|
|
414
|
-
const lineMap = coverageInfo.lineMap;
|
|
415
|
-
|
|
416
|
-
// init lines
|
|
417
|
-
let blankCount = 0;
|
|
418
|
-
let commentCount = 0;
|
|
419
|
-
|
|
420
|
-
// js: 1 (functions include all uncovered)
|
|
421
|
-
// css: 0 (ranges include all covered)
|
|
422
|
-
const baseLineCount = js ? 1 : 0;
|
|
423
|
-
|
|
424
|
-
locator.lines.forEach((it) => {
|
|
425
|
-
// exclude blank and comment
|
|
426
|
-
if (it.blank) {
|
|
427
|
-
blankCount += 1;
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
if (it.comment) {
|
|
431
|
-
commentCount += 1;
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
// line 1-base
|
|
435
|
-
const line = it.line + 1;
|
|
436
|
-
const lineInfo = new InfoLine(line, it.length, baseLineCount);
|
|
437
|
-
lineMap.set(line, lineInfo);
|
|
438
|
-
lines.push(lineInfo);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
coverageInfo.blankCount = blankCount;
|
|
442
|
-
coverageInfo.commentCount = commentCount;
|
|
443
452
|
};
|
|
444
453
|
|
|
445
|
-
const
|
|
454
|
+
const handleBytesCoverage = (state) => {
|
|
446
455
|
|
|
447
456
|
const { js, coverageList } = state;
|
|
448
457
|
|
|
449
458
|
if (js) {
|
|
450
459
|
coverageList.forEach((block) => {
|
|
451
460
|
block.ranges.forEach((range) => {
|
|
452
|
-
|
|
461
|
+
addJsBytesCoverage(state, range);
|
|
453
462
|
});
|
|
454
463
|
});
|
|
455
|
-
|
|
456
464
|
} else {
|
|
457
465
|
coverageList.forEach((range) => {
|
|
458
|
-
|
|
466
|
+
addCssBytesCoverage(state, range);
|
|
459
467
|
});
|
|
460
468
|
}
|
|
461
469
|
|
|
462
470
|
};
|
|
463
471
|
|
|
464
|
-
const generateCoverageForDist = (item, state) => {
|
|
465
|
-
|
|
466
|
-
// handle coverage
|
|
467
|
-
handleFunctionsCoverage(state);
|
|
468
|
-
handleBranchesCoverage(state);
|
|
469
|
-
handleLinesCoverage(state);
|
|
470
|
-
handleRangesCoverage(state);
|
|
471
|
-
|
|
472
|
-
collectFileCoverage(item, state.coverageInfo, state);
|
|
473
|
-
|
|
474
|
-
};
|
|
475
|
-
|
|
476
472
|
// ========================================================================================================
|
|
477
473
|
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
const generatedLocator = state.locator;
|
|
474
|
+
const handleOriginalFunctionsCoverage = (state, originalMap) => {
|
|
481
475
|
|
|
482
|
-
|
|
476
|
+
// functions only for js
|
|
477
|
+
if (!state.js) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
483
480
|
|
|
484
|
-
|
|
481
|
+
// console.log(state.astInfo.functions);
|
|
482
|
+
|
|
483
|
+
// function count
|
|
484
|
+
state.astInfo.functions.forEach((it) => {
|
|
485
|
+
const {
|
|
486
|
+
start, end, wrap
|
|
487
|
+
} = it;
|
|
488
|
+
|
|
489
|
+
// remove webpack wrap functions for functions count, not for ranges here
|
|
490
|
+
if (wrap) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// rename to startOffset and endOffset
|
|
495
|
+
const range = {
|
|
496
|
+
startOffset: start,
|
|
497
|
+
endOffset: end
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const result = findOriginalRange(range, state, originalMap);
|
|
501
|
+
if (result.error) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const { originalRange, originalState } = result;
|
|
505
|
+
|
|
506
|
+
// add back to original ast
|
|
507
|
+
originalState.astInfo.functions.push({
|
|
508
|
+
... it,
|
|
509
|
+
generatedStart: start,
|
|
510
|
+
generatedEnd: end,
|
|
511
|
+
start: originalRange.startOffset,
|
|
512
|
+
end: originalRange.endOffset
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
// if (originalState.sourcePath.endsWith('store.js')) {
|
|
516
|
+
// console.log('==========================================================');
|
|
517
|
+
// console.log(it, result.startMapping, result.endMapping);
|
|
518
|
+
// }
|
|
485
519
|
|
|
486
|
-
|
|
487
|
-
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
const handleOriginalBranchesCoverage = (state, originalMap) => {
|
|
525
|
+
|
|
526
|
+
// branches only for js
|
|
527
|
+
if (!state.js) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// console.log(state.astInfo.branches);
|
|
532
|
+
|
|
533
|
+
// function count
|
|
534
|
+
state.astInfo.branches.forEach((it) => {
|
|
535
|
+
|
|
536
|
+
const {
|
|
537
|
+
type, loc, locations
|
|
538
|
+
} = it;
|
|
539
|
+
|
|
540
|
+
// rename to startOffset and endOffset
|
|
541
|
+
const bRange = {
|
|
542
|
+
startOffset: loc.start,
|
|
543
|
+
endOffset: loc.end
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// start
|
|
547
|
+
const result = findOriginalRange(bRange, state, originalMap);
|
|
548
|
+
if (result.error) {
|
|
549
|
+
// not in the original files
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const { originalRange, originalState } = result;
|
|
553
|
+
|
|
554
|
+
const newBranchLoc = {
|
|
555
|
+
start: originalRange.startOffset,
|
|
556
|
+
end: originalRange.endOffset
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
let hasError;
|
|
560
|
+
const newLocations = locations.map((oLoc) => {
|
|
561
|
+
|
|
562
|
+
const newLoc = {
|
|
563
|
+
... oLoc
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
if (newLoc.none) {
|
|
567
|
+
return newLoc;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const { start, end } = newLoc;
|
|
571
|
+
|
|
572
|
+
const lRange = {
|
|
573
|
+
startOffset: start,
|
|
574
|
+
endOffset: end
|
|
575
|
+
};
|
|
576
|
+
const res = findOriginalRange(lRange, state, originalMap);
|
|
577
|
+
if (res.error) {
|
|
578
|
+
// It should not happen unless it is minify files, the SourceMap has some order problems
|
|
579
|
+
|
|
580
|
+
hasError = true;
|
|
581
|
+
|
|
582
|
+
// console.log('====================================', state.sourcePath, loc);
|
|
583
|
+
// console.log(res.errors);
|
|
584
|
+
// Util.logError(`Not found original branch. start: ${start}, end: ${end}`);
|
|
585
|
+
|
|
586
|
+
return newLoc;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const oRage = res.originalRange;
|
|
590
|
+
newLoc.start = oRage.startOffset;
|
|
591
|
+
newLoc.end = oRage.endOffset;
|
|
592
|
+
|
|
593
|
+
return newLoc;
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
if (hasError) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// add back to original ast
|
|
601
|
+
originalState.astInfo.branches.push({
|
|
602
|
+
type,
|
|
603
|
+
loc: newBranchLoc,
|
|
604
|
+
locations: newLocations
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const handleOriginalBytesCoverage = (state, originalMap) => {
|
|
612
|
+
|
|
613
|
+
const { js, coverageList } = state;
|
|
614
|
+
|
|
615
|
+
// const time_start_mapping = Date.now();
|
|
616
|
+
if (js) {
|
|
617
|
+
// v8 coverage
|
|
618
|
+
coverageList.forEach((block) => {
|
|
619
|
+
block.ranges.forEach((range, index) => {
|
|
620
|
+
|
|
621
|
+
// remove wrap functions for original files
|
|
622
|
+
if (range.wrap) {
|
|
623
|
+
// console.log(range);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const result = findOriginalRange(range, state, originalMap);
|
|
628
|
+
if (result.error) {
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const { originalRange, originalState } = result;
|
|
633
|
+
addJsBytesCoverage(originalState, originalRange);
|
|
634
|
+
|
|
635
|
+
// if (originalRange.startOffset === 110 && originalRange.endOffset === 271) {
|
|
636
|
+
// console.log('===============================', originalState.sourcePath);
|
|
637
|
+
// console.log(result.startMapping, result.endMapping);
|
|
638
|
+
// }
|
|
639
|
+
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
} else {
|
|
644
|
+
// support css later
|
|
645
|
+
// current css no sourceMap, so never come in
|
|
646
|
+
// coverageList.forEach((range) => {
|
|
647
|
+
|
|
648
|
+
// });
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// ========================================================================================================
|
|
654
|
+
|
|
655
|
+
const decodeSourceMappings = async (state, originalDecodedMap) => {
|
|
656
|
+
|
|
657
|
+
const generatedLocator = state.locator;
|
|
658
|
+
|
|
659
|
+
const { sources, mappings } = state.sourceMap;
|
|
660
|
+
|
|
661
|
+
const decodedList = await decodeMappings(mappings);
|
|
662
|
+
|
|
663
|
+
sources.forEach((source, i) => {
|
|
664
|
+
originalDecodedMap.set(i, []);
|
|
488
665
|
});
|
|
489
666
|
|
|
490
667
|
const allDecodedMappings = [];
|
|
@@ -566,6 +743,8 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
|
|
|
566
743
|
return decodedMappings;
|
|
567
744
|
};
|
|
568
745
|
|
|
746
|
+
// ========================================================================================================
|
|
747
|
+
|
|
569
748
|
const initOriginalList = (state, originalDecodedMap, options) => {
|
|
570
749
|
|
|
571
750
|
// source filter
|
|
@@ -628,7 +807,7 @@ const initOriginalList = (state, originalDecodedMap, options) => {
|
|
|
628
807
|
return originalMap;
|
|
629
808
|
};
|
|
630
809
|
|
|
631
|
-
const collectOriginalList = (item, state, originalMap) => {
|
|
810
|
+
const collectOriginalList = (item, state, originalMap, options) => {
|
|
632
811
|
|
|
633
812
|
const { fileUrls, sourceMap } = state;
|
|
634
813
|
const distFile = sourceMap.file || path.basename(item.sourcePath);
|
|
@@ -638,7 +817,7 @@ const collectOriginalList = (item, state, originalMap) => {
|
|
|
638
817
|
originalMap.forEach((originalState) => {
|
|
639
818
|
|
|
640
819
|
const {
|
|
641
|
-
js, type, sourcePath, source
|
|
820
|
+
js, type, sourcePath, source
|
|
642
821
|
} = originalState;
|
|
643
822
|
|
|
644
823
|
// add file item
|
|
@@ -656,7 +835,7 @@ const collectOriginalList = (item, state, originalMap) => {
|
|
|
656
835
|
};
|
|
657
836
|
|
|
658
837
|
// generate coverage, coverageInfo for current file, state for dist file
|
|
659
|
-
collectFileCoverage(sourceItem,
|
|
838
|
+
collectFileCoverage(sourceItem, originalState, state.coverageData, options);
|
|
660
839
|
|
|
661
840
|
sourceList.push(sourceItem);
|
|
662
841
|
});
|
|
@@ -664,184 +843,15 @@ const collectOriginalList = (item, state, originalMap) => {
|
|
|
664
843
|
return sourceList;
|
|
665
844
|
};
|
|
666
845
|
|
|
667
|
-
//
|
|
668
|
-
|
|
669
|
-
const handleOriginalFunctionsCoverage = (state, originalMap) => {
|
|
670
|
-
|
|
671
|
-
// functions only for js
|
|
672
|
-
if (!state.js) {
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// console.log(state.astInfo.functions);
|
|
677
|
-
|
|
678
|
-
// function count
|
|
679
|
-
state.astInfo.functions.forEach((it) => {
|
|
680
|
-
const {
|
|
681
|
-
start, end, wrap
|
|
682
|
-
} = it;
|
|
683
|
-
|
|
684
|
-
// remove webpack wrap functions for functions count, not for ranges here
|
|
685
|
-
if (wrap) {
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// rename to startOffset and endOffset
|
|
690
|
-
const range = {
|
|
691
|
-
startOffset: start,
|
|
692
|
-
endOffset: end
|
|
693
|
-
};
|
|
694
|
-
|
|
695
|
-
const result = findOriginalRange(range, state, originalMap);
|
|
696
|
-
if (result.error) {
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
const { originalRange, originalState } = result;
|
|
700
|
-
|
|
701
|
-
// add back to original ast
|
|
702
|
-
originalState.astInfo.functions.push({
|
|
703
|
-
... it,
|
|
704
|
-
generatedStart: start,
|
|
705
|
-
generatedEnd: end,
|
|
706
|
-
start: originalRange.startOffset,
|
|
707
|
-
end: originalRange.endOffset
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
// if (originalState.sourcePath.endsWith('store.js')) {
|
|
711
|
-
// console.log('==========================================================');
|
|
712
|
-
// console.log(it, result.startMapping, result.endMapping);
|
|
713
|
-
// }
|
|
714
|
-
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
const handleOriginalBranchesCoverage = (state, originalMap) => {
|
|
720
|
-
|
|
721
|
-
// branches only for js
|
|
722
|
-
if (!state.js) {
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// console.log(state.astInfo.branches);
|
|
727
|
-
|
|
728
|
-
// function count
|
|
729
|
-
state.astInfo.branches.forEach((it) => {
|
|
730
|
-
|
|
731
|
-
const {
|
|
732
|
-
type, loc, locations
|
|
733
|
-
} = it;
|
|
734
|
-
|
|
735
|
-
// rename to startOffset and endOffset
|
|
736
|
-
const bRange = {
|
|
737
|
-
startOffset: loc.start,
|
|
738
|
-
endOffset: loc.end
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
// start
|
|
742
|
-
const result = findOriginalRange(bRange, state, originalMap);
|
|
743
|
-
if (result.error) {
|
|
744
|
-
// not in the original files
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
const { originalRange, originalState } = result;
|
|
748
|
-
|
|
749
|
-
const newBranchLoc = {
|
|
750
|
-
start: originalRange.startOffset,
|
|
751
|
-
end: originalRange.endOffset
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
let hasError;
|
|
755
|
-
const newLocations = locations.map((oLoc) => {
|
|
756
|
-
|
|
757
|
-
const newLoc = {
|
|
758
|
-
... oLoc
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
if (newLoc.none) {
|
|
762
|
-
return newLoc;
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
const { start, end } = newLoc;
|
|
766
|
-
|
|
767
|
-
const lRange = {
|
|
768
|
-
startOffset: start,
|
|
769
|
-
endOffset: end
|
|
770
|
-
};
|
|
771
|
-
const res = findOriginalRange(lRange, state, originalMap);
|
|
772
|
-
if (res.error) {
|
|
773
|
-
// It should not happen unless it is minify files, the SourceMap has some order problems
|
|
774
|
-
|
|
775
|
-
hasError = true;
|
|
776
|
-
|
|
777
|
-
// console.log('====================================', state.sourcePath, loc);
|
|
778
|
-
// console.log(res.errors);
|
|
779
|
-
// Util.logError(`Not found original branch. start: ${start}, end: ${end}`);
|
|
780
|
-
|
|
781
|
-
return newLoc;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
const oRage = res.originalRange;
|
|
785
|
-
newLoc.start = oRage.startOffset;
|
|
786
|
-
newLoc.end = oRage.endOffset;
|
|
787
|
-
|
|
788
|
-
return newLoc;
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
if (hasError) {
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
// add back to original ast
|
|
796
|
-
originalState.astInfo.branches.push({
|
|
797
|
-
type,
|
|
798
|
-
loc: newBranchLoc,
|
|
799
|
-
locations: newLocations
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
const handleOriginalRangesCoverage = (state, originalMap) => {
|
|
807
|
-
|
|
808
|
-
const { js, coverageList } = state;
|
|
809
|
-
|
|
810
|
-
// const time_start_mapping = Date.now();
|
|
811
|
-
if (js) {
|
|
812
|
-
// v8 coverage
|
|
813
|
-
coverageList.forEach((block) => {
|
|
814
|
-
block.ranges.forEach((range, index) => {
|
|
815
|
-
|
|
816
|
-
// remove wrap functions for original files
|
|
817
|
-
if (range.wrap) {
|
|
818
|
-
// console.log(range);
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
const result = findOriginalRange(range, state, originalMap);
|
|
823
|
-
if (result.error) {
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
const { originalRange, originalState } = result;
|
|
828
|
-
addJsLineCoverage(originalState, originalRange);
|
|
829
|
-
|
|
830
|
-
// if (originalRange.startOffset === 110 && originalRange.endOffset === 271) {
|
|
831
|
-
// console.log('===============================', originalState.sourcePath);
|
|
832
|
-
// console.log(result.startMapping, result.endMapping);
|
|
833
|
-
// }
|
|
846
|
+
// ========================================================================================================
|
|
834
847
|
|
|
835
|
-
|
|
836
|
-
});
|
|
848
|
+
const generateCoverageForDist = (item, state, options) => {
|
|
837
849
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
// coverageList.forEach((range) => {
|
|
850
|
+
handleFunctionsCoverage(state);
|
|
851
|
+
handleBranchesCoverage(state);
|
|
852
|
+
handleBytesCoverage(state);
|
|
842
853
|
|
|
843
|
-
|
|
844
|
-
}
|
|
854
|
+
collectFileCoverage(item, state, state.coverageData, options);
|
|
845
855
|
|
|
846
856
|
};
|
|
847
857
|
|
|
@@ -878,14 +888,9 @@ const unpackSourceMap = async (item, state, options) => {
|
|
|
878
888
|
|
|
879
889
|
// handle lines info before handle ranges to update line count
|
|
880
890
|
originalMap.forEach((originalState) => {
|
|
891
|
+
|
|
881
892
|
handleFunctionsCoverage(originalState);
|
|
882
893
|
handleBranchesCoverage(originalState);
|
|
883
|
-
handleLinesCoverage(originalState);
|
|
884
|
-
|
|
885
|
-
// console.log(originalState.sourcePath, '================================');
|
|
886
|
-
// console.log(originalState.astInfo.functions);
|
|
887
|
-
// console.log(originalState.source.length);
|
|
888
|
-
// console.log(originalState.coverageInfo.functions);
|
|
889
894
|
|
|
890
895
|
// if (originalState.sourcePath.endsWith('demo.js')) {
|
|
891
896
|
// console.log('=================================', originalState.sourcePath);
|
|
@@ -895,21 +900,20 @@ const unpackSourceMap = async (item, state, options) => {
|
|
|
895
900
|
});
|
|
896
901
|
|
|
897
902
|
// handle ranges after lines ready
|
|
898
|
-
|
|
903
|
+
handleOriginalBytesCoverage(state, originalMap);
|
|
899
904
|
|
|
900
905
|
// collect coverage for original list
|
|
901
|
-
state.sourceList = collectOriginalList(item, state, originalMap);
|
|
906
|
+
state.sourceList = collectOriginalList(item, state, originalMap, options);
|
|
902
907
|
|
|
903
908
|
};
|
|
904
909
|
|
|
905
|
-
// ========================================================================================================
|
|
906
|
-
|
|
907
910
|
const unpackDistFile = async (item, state, options) => {
|
|
908
911
|
|
|
909
912
|
if (state.sourceMap) {
|
|
910
913
|
if (Util.loggingType === 'debug') {
|
|
911
914
|
// js self
|
|
912
|
-
|
|
915
|
+
item.debug = true;
|
|
916
|
+
generateCoverageForDist(item, state, options);
|
|
913
917
|
} else {
|
|
914
918
|
item.dedupe = true;
|
|
915
919
|
}
|
|
@@ -920,7 +924,7 @@ const unpackDistFile = async (item, state, options) => {
|
|
|
920
924
|
} else {
|
|
921
925
|
|
|
922
926
|
// css/js self
|
|
923
|
-
generateCoverageForDist(item, state);
|
|
927
|
+
generateCoverageForDist(item, state, options);
|
|
924
928
|
|
|
925
929
|
}
|
|
926
930
|
|