monocart-coverage-reports 2.0.8 → 2.0.9

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.
@@ -5,9 +5,17 @@
5
5
  * @false means that there is a single range and its count is the number of times the function was called.
6
6
  * @true means that the ranges form a tree of blocks representing how many times each statement or expression inside was executed.
7
7
  * It detects skipped or repeated statements. The root range counts the number of function calls.
8
- *
9
8
  * @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
10
9
  */
10
+ // https://github.com/bcoe/v8-coverage
11
+ /**
12
+ * @ranges is always non-empty. The first range is called the "root range".
13
+ * @isBlockCoverage indicates if the function has block coverage information.
14
+ If this is false, it usually means that the functions was never called.
15
+ It seems to be equivalent to ranges.length === 1 && ranges[0].count === 0.
16
+ * @functionName can be an empty string. This is common for the FunctionCov representing the whole module.
17
+ */
18
+
11
19
  // if you have a line of code that says `var x= 10; console.log(x);` that's one line and 2 statements.
12
20
 
13
21
  const path = require('path');
@@ -101,7 +109,6 @@ const updateLinesCount = (bytes, locator, lineMap) => {
101
109
 
102
110
  // if (state.sourcePath.endsWith('component.js')) {
103
111
  // console.log('===========================================', state.sourcePath);
104
- // console.log(coverageInfo.lines);
105
112
  // }
106
113
 
107
114
  };
@@ -209,21 +216,6 @@ const calculateV8Lines = (lines, blankCount, commentCount) => {
209
216
  };
210
217
 
211
218
  // ========================================================================================================
212
-
213
- const createEmptyCoverageInfo = () => {
214
- return {
215
- // v8 UI
216
- data: {
217
- bytes: [],
218
- functions: [],
219
- branches: []
220
- },
221
- // istanbul
222
- functions: [],
223
- branches: []
224
- };
225
- };
226
-
227
219
  // istanbul coverage format
228
220
  /**
229
221
  * * `path` - the file path for which coverage is being tracked
@@ -237,34 +229,69 @@ const createEmptyCoverageInfo = () => {
237
229
  const collectFileCoverage = (item, state, coverageData, options) => {
238
230
 
239
231
  const { sourcePath } = item;
240
- const { coverageInfo, locator } = state;
241
-
242
232
  const {
243
- data,
233
+ bytes,
244
234
  functions,
245
- branches
246
- } = coverageInfo;
235
+ branches,
236
+ locator
237
+ } = state;
247
238
 
248
239
  // ==========================================
249
- // v8
250
- data.bytes = dedupeCountRanges(data.bytes);
240
+ // v8 data
241
+ const data = {
242
+ bytes: dedupeCountRanges(bytes),
243
+ functions: [],
244
+ branches: []
245
+ };
251
246
 
247
+ // ==========================================
248
+ // ignore
252
249
  const ignoredRanges = getIgnoredRanges(locator, options);
253
250
  if (ignoredRanges) {
254
251
 
252
+ // data bytes is start/end/count object
255
253
  handleIgnoredRanges(data.bytes, ignoredRanges);
256
- handleIgnoredRanges(data.functions, ignoredRanges);
257
- handleIgnoredRanges(data.branches, ignoredRanges);
254
+
255
+ // functions is InfoFunction start/end/count instance
256
+ handleIgnoredRanges(functions, ignoredRanges);
257
+
258
+ // branches is InfoBranch start/end/count instance
259
+ handleIgnoredRanges(branches, ignoredRanges);
260
+
261
+ // branch locations start/end/count object
262
+ branches.forEach((group) => {
263
+ if (group.ignored) {
264
+ // all branch group ignored
265
+ group.locations.forEach((it) => {
266
+ it.ignored = true;
267
+ });
268
+ } else {
269
+ handleIgnoredRanges(group.locations, ignoredRanges);
270
+ }
271
+ });
258
272
 
259
273
  // console.log(ignoredRanges);
260
274
 
261
275
  }
262
276
 
277
+ data.functions = functions.map((info) => {
278
+ return info.getRange();
279
+ });
280
+
281
+ // branch group with locations to flat branches
282
+ data.branches = branches.map((info) => {
283
+ return info.getRanges();
284
+ }).flat();
285
+
286
+ // ==========================================
287
+ // lines
263
288
  // after bytes with ignored, before calculateV8Lines
264
289
  const {
265
290
  lines, blankCount, commentCount
266
291
  } = handleLinesCoverage(data.bytes, locator);
267
292
 
293
+ // ==========================================
294
+ // v8 data and summary
268
295
  item.data = data;
269
296
  item.summary = {
270
297
  functions: calculateV8Functions(data.functions),
@@ -286,19 +313,20 @@ const collectFileCoverage = (item, state, coverageData, options) => {
286
313
  b: {}
287
314
  };
288
315
 
289
- lines.forEach((line, index) => {
316
+ lines.filter((it) => !it.ignored).forEach((line, index) => {
290
317
  istanbulCoverage.statementMap[`${index}`] = line.generate();
291
318
  istanbulCoverage.s[`${index}`] = line.count;
292
319
  });
293
320
 
294
- functions.forEach((fn, index) => {
295
- istanbulCoverage.fnMap[`${index}`] = fn.generate();
321
+ functions.filter((it) => !it.ignored).forEach((fn, index) => {
322
+ istanbulCoverage.fnMap[`${index}`] = fn.generate(locator);
296
323
  istanbulCoverage.f[`${index}`] = fn.count;
297
324
  });
298
325
 
299
- branches.forEach((branch, index) => {
300
- istanbulCoverage.branchMap[`${index}`] = branch.generate();
301
- istanbulCoverage.b[`${index}`] = branch.generateCounts();
326
+ branches.filter((it) => !it.ignored).forEach((branch, index) => {
327
+ const { map, counts } = branch.generate(locator);
328
+ istanbulCoverage.branchMap[`${index}`] = map;
329
+ istanbulCoverage.b[`${index}`] = counts;
302
330
  });
303
331
 
304
332
  // append to dist file state
@@ -309,13 +337,11 @@ const collectFileCoverage = (item, state, coverageData, options) => {
309
337
  // ========================================================================================================
310
338
 
311
339
  const addJsBytesCoverage = (state, range) => {
312
- const { coverageInfo } = state;
313
- const { data } = coverageInfo;
314
340
  const {
315
341
  startOffset, endOffset, count
316
342
  } = range;
317
343
  // add bytes range
318
- data.bytes.push({
344
+ state.bytes.push({
319
345
  start: startOffset,
320
346
  end: endOffset,
321
347
  count
@@ -323,75 +349,35 @@ const addJsBytesCoverage = (state, range) => {
323
349
  };
324
350
 
325
351
  const addCssBytesCoverage = (state, range) => {
326
- const { coverageInfo } = state;
327
- const { data } = coverageInfo;
328
352
  const {
329
353
  start, end, count
330
354
  } = range;
331
355
  // add css bytes range, already start, end
332
- data.bytes.push({
356
+ state.bytes.push({
333
357
  start,
334
358
  end,
335
359
  count
336
360
  });
337
361
  };
338
362
 
339
- const updateOffsetToLocation = (locator, loc) => {
340
- const sLoc = locator.offsetToLocation(loc.start);
341
- loc.start = {
342
- line: sLoc.line,
343
- column: sLoc.column
344
- };
345
- const eLoc = locator.offsetToLocation(loc.end);
346
- loc.end = {
347
- line: eLoc.line,
348
- column: eLoc.column
349
- };
350
- };
351
-
352
363
  // ========================================================================================================
353
364
 
354
365
  const handleFunctionsCoverage = (state) => {
355
366
 
356
367
  // functions only for js
357
368
  if (!state.js) {
358
- // use css rules data for functions
359
369
  return;
360
370
  }
361
371
 
362
- const {
363
- locator, coverageInfo, astInfo
364
- } = state;
365
-
366
- const v8Functions = coverageInfo.data.functions;
367
- const istanbulFunctions = coverageInfo.functions;
368
-
372
+ const { functions, astInfo } = state;
369
373
  astInfo.functions.forEach((it) => {
370
374
  const {
371
375
  start, end, functionName, count
372
376
  } = it;
373
-
374
- v8Functions.push({
375
- start,
376
- end,
377
- count
378
- });
379
-
380
- const loc = {
381
- start,
382
- end
383
- };
384
- updateOffsetToLocation(locator, loc);
385
- const functionInfo = new InfoFunction(loc, count, functionName);
386
- istanbulFunctions.push(functionInfo);
377
+ const functionInfo = new InfoFunction(start, end, count, functionName);
378
+ functions.push(functionInfo);
387
379
  });
388
380
 
389
- // if (state.sourcePath.endsWith('store.js')) {
390
- // console.log('==========================================================');
391
- // console.log(astInfo.functions);
392
- // console.log(functions);
393
- // }
394
-
395
381
  };
396
382
 
397
383
  const handleBranchesCoverage = (state) => {
@@ -401,52 +387,13 @@ const handleBranchesCoverage = (state) => {
401
387
  return;
402
388
  }
403
389
 
404
- const {
405
- locator, coverageInfo, astInfo
406
- } = state;
407
-
408
- const v8Branches = coverageInfo.data.branches;
409
- const isTanbulBranches = coverageInfo.branches;
390
+ const { branches, astInfo } = state;
410
391
  astInfo.branches.forEach((it) => {
411
-
412
- const branchType = it.type;
413
- const branchLoc = {
414
- ... it.loc
415
- };
416
- updateOffsetToLocation(locator, branchLoc);
417
-
418
- // locations
419
- // [ { start:{line,column}, end:{line,column}, count }, ...]
420
- const locations = it.locations.map((oLoc) => {
421
- const newLoc = {
422
- ... oLoc
423
- };
424
- if (newLoc.none) {
425
-
426
- // the branch count is not very accurate
427
- v8Branches.push({
428
- start: it.loc.start,
429
- end: it.loc.end,
430
- count: oLoc.count,
431
- none: true
432
- });
433
-
434
- return newLoc;
435
- }
436
-
437
- // the branch count is not very accurate
438
- v8Branches.push({
439
- start: oLoc.start,
440
- end: oLoc.end,
441
- count: oLoc.count
442
- });
443
-
444
- updateOffsetToLocation(locator, newLoc);
445
- return newLoc;
446
- });
447
-
448
- const branchInfo = new InfoBranch(branchLoc, locations, branchType);
449
- isTanbulBranches.push(branchInfo);
392
+ const {
393
+ start, end, locations, type
394
+ } = it;
395
+ const branchInfo = new InfoBranch(start, end, locations, type);
396
+ branches.push(branchInfo);
450
397
  });
451
398
 
452
399
  };
@@ -533,14 +480,12 @@ const handleOriginalBranchesCoverage = (state, originalMap) => {
533
480
  // function count
534
481
  state.astInfo.branches.forEach((it) => {
535
482
 
536
- const {
537
- type, loc, locations
538
- } = it;
483
+ const { type, locations } = it;
539
484
 
540
485
  // rename to startOffset and endOffset
541
486
  const bRange = {
542
- startOffset: loc.start,
543
- endOffset: loc.end
487
+ startOffset: it.start,
488
+ endOffset: it.end
544
489
  };
545
490
 
546
491
  // start
@@ -551,10 +496,8 @@ const handleOriginalBranchesCoverage = (state, originalMap) => {
551
496
  }
552
497
  const { originalRange, originalState } = result;
553
498
 
554
- const newBranchLoc = {
555
- start: originalRange.startOffset,
556
- end: originalRange.endOffset
557
- };
499
+ const groupStart = originalRange.startOffset;
500
+ const groupEnd = originalRange.endOffset;
558
501
 
559
502
  let hasError;
560
503
  const newLocations = locations.map((oLoc) => {
@@ -564,6 +507,8 @@ const handleOriginalBranchesCoverage = (state, originalMap) => {
564
507
  };
565
508
 
566
509
  if (newLoc.none) {
510
+ newLoc.start = groupStart;
511
+ newLoc.end = groupEnd;
567
512
  return newLoc;
568
513
  }
569
514
 
@@ -586,6 +531,7 @@ const handleOriginalBranchesCoverage = (state, originalMap) => {
586
531
  return newLoc;
587
532
  }
588
533
 
534
+ // mapping to new range
589
535
  const oRage = res.originalRange;
590
536
  newLoc.start = oRage.startOffset;
591
537
  newLoc.end = oRage.endOffset;
@@ -593,6 +539,7 @@ const handleOriginalBranchesCoverage = (state, originalMap) => {
593
539
  return newLoc;
594
540
  });
595
541
 
542
+ // ignored group when found error
596
543
  if (hasError) {
597
544
  return;
598
545
  }
@@ -600,7 +547,8 @@ const handleOriginalBranchesCoverage = (state, originalMap) => {
600
547
  // add back to original ast
601
548
  originalState.astInfo.branches.push({
602
549
  type,
603
- loc: newBranchLoc,
550
+ start: groupStart,
551
+ end: groupEnd,
604
552
  locations: newLocations
605
553
  });
606
554
 
@@ -794,7 +742,10 @@ const initOriginalList = (state, originalDecodedMap, options) => {
794
742
  source: sourceContent,
795
743
  locator,
796
744
  decodedMappings,
797
- coverageInfo: createEmptyCoverageInfo(),
745
+ // coverage info
746
+ bytes: [],
747
+ functions: [],
748
+ branches: [],
798
749
  astInfo: {
799
750
  functions: [],
800
751
  branches: []
@@ -814,6 +765,7 @@ const collectOriginalList = (item, state, originalMap, options) => {
814
765
 
815
766
  // collect original files
816
767
  const sourceList = [];
768
+
817
769
  originalMap.forEach((originalState) => {
818
770
 
819
771
  const {
@@ -822,7 +774,8 @@ const collectOriginalList = (item, state, originalMap, options) => {
822
774
 
823
775
  // add file item
824
776
  const url = fileUrls[sourcePath] || sourcePath;
825
- const id = Util.calculateSha1(url + source);
777
+ // add dist for id
778
+ const id = Util.calculateSha1(distFile + url + source);
826
779
 
827
780
  const sourceItem = {
828
781
  url,
@@ -834,7 +787,7 @@ const collectOriginalList = (item, state, originalMap, options) => {
834
787
  source
835
788
  };
836
789
 
837
- // generate coverage, coverageInfo for current file, state for dist file
790
+ // generate coverage for current file, state for dist file
838
791
  collectFileCoverage(sourceItem, originalState, state.coverageData, options);
839
792
 
840
793
  sourceList.push(sourceItem);
@@ -894,7 +847,6 @@ const unpackSourceMap = async (item, state, options) => {
894
847
 
895
848
  // if (originalState.sourcePath.endsWith('demo.js')) {
896
849
  // console.log('=================================', originalState.sourcePath);
897
- // console.log(originalState.coverageInfo.lineMap);
898
850
  // }
899
851
 
900
852
  });
@@ -949,7 +901,7 @@ const dedupeV8List = (v8list) => {
949
901
 
950
902
  const convertV8List = async (v8list, options) => {
951
903
 
952
- // global file sources and coverage data
904
+ // global file sources and coverage
953
905
  const fileSources = {};
954
906
  const coverageData = {};
955
907
  let sourceList = [];
@@ -978,9 +930,6 @@ const convertV8List = async (v8list, options) => {
978
930
  delete item.sourceMap;
979
931
  }
980
932
 
981
- // ============================
982
- const coverageInfo = createEmptyCoverageInfo();
983
-
984
933
  // ============================
985
934
  // move functions and ranges to coverageList
986
935
  let coverageList = [];
@@ -1011,9 +960,12 @@ const convertV8List = async (v8list, options) => {
1011
960
  sourceMap,
1012
961
  coverageList,
1013
962
  locator,
1014
- coverageInfo,
963
+ // coverage info
964
+ bytes: [],
965
+ functions: [],
966
+ branches: [],
1015
967
  astInfo,
1016
- // for istanbul data
968
+ // for istanbul
1017
969
  fileSources: {},
1018
970
  coverageData: {}
1019
971
  };
@@ -1,29 +1,74 @@
1
+ const Util = require('../utils/util.js');
1
2
  module.exports = class InfoBranch {
2
- constructor(loc, locations, type) {
3
- this.loc = loc;
4
- this.line = loc.start.line;
5
- // [ { start:{line,column}, end:{line,column}, count }, ...]
3
+ constructor(start, end, locations, type) {
4
+ this.start = start;
5
+ this.end = end;
6
6
  this.locations = locations;
7
7
  this.type = type || 'branch';
8
8
  }
9
9
 
10
- generate() {
11
- return {
12
- loc: this.loc,
10
+ getRanges() {
11
+ return this.locations.map((item) => {
12
+ const range = {
13
+ start: item.start,
14
+ end: item.end,
15
+ count: item.count
16
+ };
17
+ if (item.none) {
18
+ range.none = true;
19
+ }
20
+ if (item.ignored) {
21
+ range.ignored = true;
22
+ }
23
+ return range;
24
+ });
25
+ }
26
+
27
+ generate(locator) {
28
+ const groupLoc = {
29
+ start: this.start,
30
+ end: this.end
31
+ };
32
+ Util.updateOffsetToLocation(locator, groupLoc);
33
+ const line = groupLoc.start.line;
34
+
35
+ // remove ignored
36
+ const locations = this.locations.filter((it) => !it.ignored);
37
+
38
+ // [ { start:{line,column}, end:{line,column}, count }, ...]
39
+ locations.forEach((item) => {
40
+ Util.updateOffsetToLocation(locator, item);
41
+ });
42
+
43
+ const map = {
44
+ loc: groupLoc,
13
45
  type: this.type,
14
- locations: this.locations.map((item) => {
15
- const { start, end } = item;
46
+ locations: locations.map((item) => {
47
+ const {
48
+ start, end, none
49
+ } = item;
50
+ if (none) {
51
+ // none with group start/end, should be empty for istanbul
52
+ return {
53
+ start: {},
54
+ end: {}
55
+ };
56
+ }
16
57
  return {
17
- start: start || {},
18
- end: end || {}
58
+ start,
59
+ end
19
60
  };
20
61
 
21
62
  }),
22
- line: this.line
63
+ line: line
23
64
  };
24
- }
25
65
 
26
- generateCounts() {
27
- return this.locations.map((item) => item.count);
66
+ const counts = locations.map((item) => item.count);
67
+
68
+ return {
69
+ map,
70
+ counts
71
+ };
28
72
  }
73
+
29
74
  };
@@ -1,17 +1,40 @@
1
+ const Util = require('../utils/util.js');
1
2
  module.exports = class InfoFunction {
2
- constructor(loc, count, name) {
3
- this.loc = loc;
4
- this.line = loc.start.line;
3
+ constructor(start, end, count, name) {
4
+ this.start = start;
5
+ this.end = end;
5
6
  this.count = count;
6
7
  this.name = name || '(anonymous)';
7
8
  }
8
9
 
9
- generate() {
10
+ getRange() {
11
+ const range = {
12
+ start: this.start,
13
+ end: this.end,
14
+ count: this.count
15
+ };
16
+ if (this.ignored) {
17
+ range.ignored = true;
18
+ }
19
+ return range;
20
+ }
21
+
22
+ generate(locator) {
23
+
24
+ const loc = {
25
+ start: this.start,
26
+ end: this.end
27
+ };
28
+
29
+ Util.updateOffsetToLocation(locator, loc);
30
+
31
+ const line = loc.start.line;
32
+
10
33
  return {
11
34
  name: this.name,
12
- decl: this.loc,
13
- loc: this.loc,
14
- line: this.line
35
+ decl: loc,
36
+ loc: loc,
37
+ line: line
15
38
  };
16
39
  }
17
40
  };