monocart-coverage-reports 2.0.7 → 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 +26 -4
- package/lib/converter/ast.js +2 -3
- package/lib/converter/branches.js +1 -37
- package/lib/converter/converter.js +391 -369
- 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 +64 -65
- package/lib/index.d.ts +3 -0
- 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 +7 -68
- 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,105 +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
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
// update lines coverage
|
|
192
|
-
const lines = Util.getRangeLines(sLoc, eLoc);
|
|
193
|
-
|
|
194
|
-
lines.forEach((it) => {
|
|
195
|
-
const line = lineMap.get(it.line);
|
|
196
|
-
if (!line) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// from outside into inside, uncovered is certain
|
|
201
|
-
// default is covered
|
|
202
|
-
if (it.entire) {
|
|
203
|
-
line.covered = count > 0;
|
|
204
|
-
line.count = count;
|
|
205
|
-
} else {
|
|
206
|
-
if (count > 0) {
|
|
207
|
-
line.count = count;
|
|
208
|
-
} else {
|
|
209
|
-
// not covered if any count = 0
|
|
210
|
-
line.covered = false;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// if (!line.history) {
|
|
215
|
-
// line.history = [];
|
|
216
|
-
// }
|
|
217
|
-
// line.history.push(`${it.entire}-${count}`);
|
|
218
|
-
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// if (state.sourcePath.endsWith('component.js')) {
|
|
222
|
-
// console.log('===========================================', state.sourcePath);
|
|
223
|
-
// console.log(coverageInfo.lines);
|
|
224
|
-
// }
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
// https://github.com/demurgos/v8-coverage
|
|
228
|
-
/**
|
|
229
|
-
* @ranges is always non-empty. The first range is called the "root range".
|
|
230
|
-
* @isBlockCoverage indicates if the function has block coverage information
|
|
231
|
-
* @false means that there is a single range and its count is the number of times the function was called.
|
|
232
|
-
* @true means that the ranges form a tree of blocks representing how many times each statement or expression inside was executed.
|
|
233
|
-
* It detects skipped or repeated statements. The root range counts the number of function calls.
|
|
234
|
-
*
|
|
235
|
-
* @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
|
|
236
|
-
*/
|
|
237
|
-
// if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.
|
|
238
|
-
|
|
239
|
-
const addJsLineCoverage = (state, range) => {
|
|
240
|
-
|
|
241
|
-
const { locator, coverageInfo } = state;
|
|
242
|
-
|
|
243
|
-
const { data, lineMap } = coverageInfo;
|
|
244
|
-
|
|
311
|
+
const addJsBytesCoverage = (state, range) => {
|
|
312
|
+
const { coverageInfo } = state;
|
|
313
|
+
const { data } = coverageInfo;
|
|
245
314
|
const {
|
|
246
315
|
startOffset, endOffset, count
|
|
247
316
|
} = range;
|
|
248
|
-
|
|
249
317
|
// add bytes range
|
|
250
318
|
data.bytes.push({
|
|
251
|
-
// index,
|
|
252
319
|
start: startOffset,
|
|
253
320
|
end: endOffset,
|
|
254
321
|
count
|
|
255
322
|
});
|
|
256
|
-
|
|
257
|
-
updateLineCoverage(startOffset, endOffset, count, lineMap, locator);
|
|
258
|
-
|
|
259
323
|
};
|
|
260
324
|
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
const {
|
|
264
|
-
|
|
265
|
-
const { lineMap, data } = coverageInfo;
|
|
266
|
-
|
|
325
|
+
const addCssBytesCoverage = (state, range) => {
|
|
326
|
+
const { coverageInfo } = state;
|
|
327
|
+
const { data } = coverageInfo;
|
|
267
328
|
const {
|
|
268
329
|
start, end, count
|
|
269
330
|
} = range;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
331
|
+
// add css bytes range, already start, end
|
|
332
|
+
data.bytes.push({
|
|
333
|
+
start,
|
|
334
|
+
end,
|
|
335
|
+
count
|
|
336
|
+
});
|
|
276
337
|
};
|
|
277
338
|
|
|
278
|
-
// ========================================================================================================
|
|
279
|
-
|
|
280
339
|
const updateOffsetToLocation = (locator, loc) => {
|
|
281
340
|
const sLoc = locator.offsetToLocation(loc.start);
|
|
282
341
|
loc.start = {
|
|
@@ -290,6 +349,8 @@ const updateOffsetToLocation = (locator, loc) => {
|
|
|
290
349
|
};
|
|
291
350
|
};
|
|
292
351
|
|
|
352
|
+
// ========================================================================================================
|
|
353
|
+
|
|
293
354
|
const handleFunctionsCoverage = (state) => {
|
|
294
355
|
|
|
295
356
|
// functions only for js
|
|
@@ -388,80 +449,214 @@ const handleBranchesCoverage = (state) => {
|
|
|
388
449
|
isTanbulBranches.push(branchInfo);
|
|
389
450
|
});
|
|
390
451
|
|
|
391
|
-
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const handleLinesCoverage = (state) => {
|
|
395
|
-
|
|
396
|
-
const { locator, coverageInfo } = state;
|
|
397
|
-
|
|
398
|
-
const lines = coverageInfo.lines;
|
|
399
|
-
const lineMap = coverageInfo.lineMap;
|
|
400
|
-
|
|
401
|
-
// init lines
|
|
402
|
-
let blankCount = 0;
|
|
403
|
-
let commentCount = 0;
|
|
404
|
-
|
|
405
|
-
locator.lines.forEach((it) => {
|
|
406
|
-
// exclude blank and comment
|
|
407
|
-
if (it.blank) {
|
|
408
|
-
blankCount += 1;
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
if (it.comment) {
|
|
412
|
-
commentCount += 1;
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
// line 1-base
|
|
416
|
-
const line = it.line + 1;
|
|
417
|
-
// default count to 1, both js and css
|
|
418
|
-
const lineInfo = new InfoLine(line, it.length, 1);
|
|
419
|
-
lineMap.set(line, lineInfo);
|
|
420
|
-
lines.push(lineInfo);
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
coverageInfo.blankCount = blankCount;
|
|
424
|
-
coverageInfo.commentCount = commentCount;
|
|
425
452
|
};
|
|
426
453
|
|
|
427
|
-
const
|
|
454
|
+
const handleBytesCoverage = (state) => {
|
|
428
455
|
|
|
429
456
|
const { js, coverageList } = state;
|
|
430
457
|
|
|
431
458
|
if (js) {
|
|
432
459
|
coverageList.forEach((block) => {
|
|
433
460
|
block.ranges.forEach((range) => {
|
|
434
|
-
|
|
461
|
+
addJsBytesCoverage(state, range);
|
|
435
462
|
});
|
|
436
463
|
});
|
|
437
|
-
|
|
438
464
|
} else {
|
|
439
465
|
coverageList.forEach((range) => {
|
|
440
|
-
|
|
466
|
+
addCssBytesCoverage(state, range);
|
|
441
467
|
});
|
|
442
468
|
}
|
|
443
469
|
|
|
444
470
|
};
|
|
445
471
|
|
|
446
|
-
|
|
472
|
+
// ========================================================================================================
|
|
447
473
|
|
|
448
|
-
|
|
449
|
-
handleFunctionsCoverage(state);
|
|
450
|
-
handleBranchesCoverage(state);
|
|
451
|
-
handleLinesCoverage(state);
|
|
452
|
-
handleRangesCoverage(state);
|
|
474
|
+
const handleOriginalFunctionsCoverage = (state, originalMap) => {
|
|
453
475
|
|
|
454
|
-
|
|
476
|
+
// functions only for js
|
|
477
|
+
if (!state.js) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
455
480
|
|
|
456
|
-
|
|
481
|
+
// console.log(state.astInfo.functions);
|
|
457
482
|
|
|
458
|
-
//
|
|
483
|
+
// function count
|
|
484
|
+
state.astInfo.functions.forEach((it) => {
|
|
485
|
+
const {
|
|
486
|
+
start, end, wrap
|
|
487
|
+
} = it;
|
|
459
488
|
|
|
460
|
-
|
|
489
|
+
// remove webpack wrap functions for functions count, not for ranges here
|
|
490
|
+
if (wrap) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
461
493
|
|
|
462
|
-
|
|
494
|
+
// rename to startOffset and endOffset
|
|
495
|
+
const range = {
|
|
496
|
+
startOffset: start,
|
|
497
|
+
endOffset: end
|
|
498
|
+
};
|
|
463
499
|
|
|
464
|
-
|
|
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
|
+
// }
|
|
519
|
+
|
|
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;
|
|
465
660
|
|
|
466
661
|
const decodedList = await decodeMappings(mappings);
|
|
467
662
|
|
|
@@ -548,6 +743,8 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
|
|
|
548
743
|
return decodedMappings;
|
|
549
744
|
};
|
|
550
745
|
|
|
746
|
+
// ========================================================================================================
|
|
747
|
+
|
|
551
748
|
const initOriginalList = (state, originalDecodedMap, options) => {
|
|
552
749
|
|
|
553
750
|
// source filter
|
|
@@ -610,7 +807,7 @@ const initOriginalList = (state, originalDecodedMap, options) => {
|
|
|
610
807
|
return originalMap;
|
|
611
808
|
};
|
|
612
809
|
|
|
613
|
-
const collectOriginalList = (item, state, originalMap) => {
|
|
810
|
+
const collectOriginalList = (item, state, originalMap, options) => {
|
|
614
811
|
|
|
615
812
|
const { fileUrls, sourceMap } = state;
|
|
616
813
|
const distFile = sourceMap.file || path.basename(item.sourcePath);
|
|
@@ -620,7 +817,7 @@ const collectOriginalList = (item, state, originalMap) => {
|
|
|
620
817
|
originalMap.forEach((originalState) => {
|
|
621
818
|
|
|
622
819
|
const {
|
|
623
|
-
js, type, sourcePath, source
|
|
820
|
+
js, type, sourcePath, source
|
|
624
821
|
} = originalState;
|
|
625
822
|
|
|
626
823
|
// add file item
|
|
@@ -638,7 +835,7 @@ const collectOriginalList = (item, state, originalMap) => {
|
|
|
638
835
|
};
|
|
639
836
|
|
|
640
837
|
// generate coverage, coverageInfo for current file, state for dist file
|
|
641
|
-
collectFileCoverage(sourceItem,
|
|
838
|
+
collectFileCoverage(sourceItem, originalState, state.coverageData, options);
|
|
642
839
|
|
|
643
840
|
sourceList.push(sourceItem);
|
|
644
841
|
});
|
|
@@ -646,184 +843,15 @@ const collectOriginalList = (item, state, originalMap) => {
|
|
|
646
843
|
return sourceList;
|
|
647
844
|
};
|
|
648
845
|
|
|
649
|
-
//
|
|
650
|
-
|
|
651
|
-
const handleOriginalFunctionsCoverage = (state, originalMap) => {
|
|
652
|
-
|
|
653
|
-
// functions only for js
|
|
654
|
-
if (!state.js) {
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
// console.log(state.astInfo.functions);
|
|
659
|
-
|
|
660
|
-
// function count
|
|
661
|
-
state.astInfo.functions.forEach((it) => {
|
|
662
|
-
const {
|
|
663
|
-
start, end, wrap
|
|
664
|
-
} = it;
|
|
665
|
-
|
|
666
|
-
// remove webpack wrap functions for functions count, not for ranges here
|
|
667
|
-
if (wrap) {
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// rename to startOffset and endOffset
|
|
672
|
-
const range = {
|
|
673
|
-
startOffset: start,
|
|
674
|
-
endOffset: end
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
const result = findOriginalRange(range, state, originalMap);
|
|
678
|
-
if (result.error) {
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
const { originalRange, originalState } = result;
|
|
682
|
-
|
|
683
|
-
// add back to original ast
|
|
684
|
-
originalState.astInfo.functions.push({
|
|
685
|
-
... it,
|
|
686
|
-
generatedStart: start,
|
|
687
|
-
generatedEnd: end,
|
|
688
|
-
start: originalRange.startOffset,
|
|
689
|
-
end: originalRange.endOffset
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
// if (originalState.sourcePath.endsWith('store.js')) {
|
|
693
|
-
// console.log('==========================================================');
|
|
694
|
-
// console.log(it, result.startMapping, result.endMapping);
|
|
695
|
-
// }
|
|
696
|
-
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
const handleOriginalBranchesCoverage = (state, originalMap) => {
|
|
702
|
-
|
|
703
|
-
// branches only for js
|
|
704
|
-
if (!state.js) {
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
// console.log(state.astInfo.branches);
|
|
709
|
-
|
|
710
|
-
// function count
|
|
711
|
-
state.astInfo.branches.forEach((it) => {
|
|
712
|
-
|
|
713
|
-
const {
|
|
714
|
-
type, loc, locations
|
|
715
|
-
} = it;
|
|
716
|
-
|
|
717
|
-
// rename to startOffset and endOffset
|
|
718
|
-
const bRange = {
|
|
719
|
-
startOffset: loc.start,
|
|
720
|
-
endOffset: loc.end
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
// start
|
|
724
|
-
const result = findOriginalRange(bRange, state, originalMap);
|
|
725
|
-
if (result.error) {
|
|
726
|
-
// not in the original files
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
const { originalRange, originalState } = result;
|
|
730
|
-
|
|
731
|
-
const newBranchLoc = {
|
|
732
|
-
start: originalRange.startOffset,
|
|
733
|
-
end: originalRange.endOffset
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
let hasError;
|
|
737
|
-
const newLocations = locations.map((oLoc) => {
|
|
738
|
-
|
|
739
|
-
const newLoc = {
|
|
740
|
-
... oLoc
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
if (newLoc.none) {
|
|
744
|
-
return newLoc;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
const { start, end } = newLoc;
|
|
748
|
-
|
|
749
|
-
const lRange = {
|
|
750
|
-
startOffset: start,
|
|
751
|
-
endOffset: end
|
|
752
|
-
};
|
|
753
|
-
const res = findOriginalRange(lRange, state, originalMap);
|
|
754
|
-
if (res.error) {
|
|
755
|
-
// It should not happen unless it is minify files, the SourceMap has some order problems
|
|
756
|
-
|
|
757
|
-
hasError = true;
|
|
758
|
-
|
|
759
|
-
// console.log('====================================', state.sourcePath, loc);
|
|
760
|
-
// console.log(res.errors);
|
|
761
|
-
// Util.logError(`Not found original branch. start: ${start}, end: ${end}`);
|
|
762
|
-
|
|
763
|
-
return newLoc;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
const oRage = res.originalRange;
|
|
767
|
-
newLoc.start = oRage.startOffset;
|
|
768
|
-
newLoc.end = oRage.endOffset;
|
|
769
|
-
|
|
770
|
-
return newLoc;
|
|
771
|
-
});
|
|
772
|
-
|
|
773
|
-
if (hasError) {
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
// add back to original ast
|
|
778
|
-
originalState.astInfo.branches.push({
|
|
779
|
-
type,
|
|
780
|
-
loc: newBranchLoc,
|
|
781
|
-
locations: newLocations
|
|
782
|
-
});
|
|
783
|
-
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
const handleOriginalRangesCoverage = (state, originalMap) => {
|
|
789
|
-
|
|
790
|
-
const { js, coverageList } = state;
|
|
791
|
-
|
|
792
|
-
// const time_start_mapping = Date.now();
|
|
793
|
-
if (js) {
|
|
794
|
-
// v8 coverage
|
|
795
|
-
coverageList.forEach((block) => {
|
|
796
|
-
block.ranges.forEach((range, index) => {
|
|
797
|
-
|
|
798
|
-
// remove wrap functions for original files
|
|
799
|
-
if (range.wrap) {
|
|
800
|
-
// console.log(range);
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
const result = findOriginalRange(range, state, originalMap);
|
|
805
|
-
if (result.error) {
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
const { originalRange, originalState } = result;
|
|
810
|
-
addJsLineCoverage(originalState, originalRange);
|
|
811
|
-
|
|
812
|
-
// if (originalRange.startOffset === 110 && originalRange.endOffset === 271) {
|
|
813
|
-
// console.log('===============================', originalState.sourcePath);
|
|
814
|
-
// console.log(result.startMapping, result.endMapping);
|
|
815
|
-
// }
|
|
846
|
+
// ========================================================================================================
|
|
816
847
|
|
|
817
|
-
|
|
818
|
-
});
|
|
848
|
+
const generateCoverageForDist = (item, state, options) => {
|
|
819
849
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
// coverageList.forEach((range) => {
|
|
850
|
+
handleFunctionsCoverage(state);
|
|
851
|
+
handleBranchesCoverage(state);
|
|
852
|
+
handleBytesCoverage(state);
|
|
824
853
|
|
|
825
|
-
|
|
826
|
-
}
|
|
854
|
+
collectFileCoverage(item, state, state.coverageData, options);
|
|
827
855
|
|
|
828
856
|
};
|
|
829
857
|
|
|
@@ -860,14 +888,9 @@ const unpackSourceMap = async (item, state, options) => {
|
|
|
860
888
|
|
|
861
889
|
// handle lines info before handle ranges to update line count
|
|
862
890
|
originalMap.forEach((originalState) => {
|
|
891
|
+
|
|
863
892
|
handleFunctionsCoverage(originalState);
|
|
864
893
|
handleBranchesCoverage(originalState);
|
|
865
|
-
handleLinesCoverage(originalState);
|
|
866
|
-
|
|
867
|
-
// console.log(originalState.sourcePath, '================================');
|
|
868
|
-
// console.log(originalState.astInfo.functions);
|
|
869
|
-
// console.log(originalState.source.length);
|
|
870
|
-
// console.log(originalState.coverageInfo.functions);
|
|
871
894
|
|
|
872
895
|
// if (originalState.sourcePath.endsWith('demo.js')) {
|
|
873
896
|
// console.log('=================================', originalState.sourcePath);
|
|
@@ -877,21 +900,20 @@ const unpackSourceMap = async (item, state, options) => {
|
|
|
877
900
|
});
|
|
878
901
|
|
|
879
902
|
// handle ranges after lines ready
|
|
880
|
-
|
|
903
|
+
handleOriginalBytesCoverage(state, originalMap);
|
|
881
904
|
|
|
882
905
|
// collect coverage for original list
|
|
883
|
-
state.sourceList = collectOriginalList(item, state, originalMap);
|
|
906
|
+
state.sourceList = collectOriginalList(item, state, originalMap, options);
|
|
884
907
|
|
|
885
908
|
};
|
|
886
909
|
|
|
887
|
-
// ========================================================================================================
|
|
888
|
-
|
|
889
910
|
const unpackDistFile = async (item, state, options) => {
|
|
890
911
|
|
|
891
912
|
if (state.sourceMap) {
|
|
892
913
|
if (Util.loggingType === 'debug') {
|
|
893
914
|
// js self
|
|
894
|
-
|
|
915
|
+
item.debug = true;
|
|
916
|
+
generateCoverageForDist(item, state, options);
|
|
895
917
|
} else {
|
|
896
918
|
item.dedupe = true;
|
|
897
919
|
}
|
|
@@ -902,7 +924,7 @@ const unpackDistFile = async (item, state, options) => {
|
|
|
902
924
|
} else {
|
|
903
925
|
|
|
904
926
|
// css/js self
|
|
905
|
-
generateCoverageForDist(item, state);
|
|
927
|
+
generateCoverageForDist(item, state, options);
|
|
906
928
|
|
|
907
929
|
}
|
|
908
930
|
|