monocart-coverage-reports 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,13 +24,16 @@ const findMapping = (list, offset) => {
24
24
 
25
25
  };
26
26
 
27
- const findOffsetMapping = (generatedState, offset) => {
27
+ const findOffsetMapping = (state, offset) => {
28
28
 
29
- const decodedMappings = generatedState.decodedMappings;
29
+ const decodedMappings = state.decodedMappings;
30
30
 
31
31
  // possible no length
32
32
  if (!decodedMappings.length) {
33
- return;
33
+ return {
34
+ error: true,
35
+ errors: [`not found decoded mappings for offset: ${offset}`]
36
+ };
34
37
  }
35
38
 
36
39
  const mapping = findMapping(decodedMappings, offset);
@@ -39,7 +42,10 @@ const findOffsetMapping = (generatedState, offset) => {
39
42
 
40
43
  // not found, allow > last, not allow < first
41
44
  if (offset < generatedOffset) {
42
- return;
45
+ return {
46
+ error: true,
47
+ errors: [`not found generated offset: ${offset}`]
48
+ };
43
49
  }
44
50
 
45
51
  // exact matched no need fix
@@ -69,8 +75,8 @@ const findNextOriginalDiffMapping = (originalState, mapping) => {
69
75
  }
70
76
  };
71
77
 
72
- const findNextGeneratedDiffMapping = (generatedState, mapping) => {
73
- const decodedMappings = generatedState.decodedMappings;
78
+ const findNextGeneratedDiffMapping = (state, mapping) => {
79
+ const decodedMappings = state.decodedMappings;
74
80
  const i = mapping.generatedIndex + 1;
75
81
  const l = decodedMappings.length;
76
82
  if (i < l) {
@@ -78,7 +84,7 @@ const findNextGeneratedDiffMapping = (generatedState, mapping) => {
78
84
  }
79
85
  };
80
86
 
81
- const getGeneratedText = (mapping, generatedState) => {
87
+ const getGeneratedText = (mapping, state) => {
82
88
 
83
89
  const generatedText = mapping.generatedText;
84
90
  if (typeof generatedText === 'string') {
@@ -87,13 +93,13 @@ const getGeneratedText = (mapping, generatedState) => {
87
93
 
88
94
  let text = '';
89
95
 
90
- const { positionMapping } = generatedState;
91
- const nextMapping = findNextGeneratedDiffMapping(generatedState, mapping);
96
+ const locator = state.locator;
97
+ const nextMapping = findNextGeneratedDiffMapping(state, mapping);
92
98
  if (nextMapping) {
93
- text = positionMapping.getSlice(mapping.generatedOffset, nextMapping.generatedOffset);
99
+ text = locator.getSlice(mapping.generatedOffset, nextMapping.generatedOffset);
94
100
  } else {
95
101
  // to the end
96
- text = positionMapping.getSlice(mapping.generatedOffset);
102
+ text = locator.getSlice(mapping.generatedOffset);
97
103
  }
98
104
 
99
105
  // never cross line
@@ -118,13 +124,13 @@ const getOriginalText = (mapping, originalState) => {
118
124
 
119
125
  let text = '';
120
126
 
121
- const { positionMapping } = originalState;
127
+ const { locator } = originalState;
122
128
  const nextMapping = findNextOriginalDiffMapping(originalState, mapping);
123
129
  if (nextMapping) {
124
- text = positionMapping.getSlice(mapping.originalOffset, nextMapping.originalOffset);
130
+ text = locator.getSlice(mapping.originalOffset, nextMapping.originalOffset);
125
131
  } else {
126
132
  // to the end
127
- text = positionMapping.getSlice(mapping.originalOffset);
133
+ text = locator.getSlice(mapping.originalOffset);
128
134
  }
129
135
 
130
136
  // the last two items could have same line and column
@@ -326,7 +332,7 @@ const getOriginalEndPosition = (originalText, generatedText, generatedPos) => {
326
332
 
327
333
  // ========================================================================================================
328
334
 
329
- const fixStartColumn = (startMapping, range, generatedState, originalState) => {
335
+ const fixStartColumn = (startMapping, range, state, originalState) => {
330
336
  // exact matched no need fix
331
337
  if (startMapping.exact) {
332
338
  // originalColumn is the column
@@ -337,14 +343,14 @@ const fixStartColumn = (startMapping, range, generatedState, originalState) => {
337
343
  const originalColumn = startMapping.originalColumn;
338
344
 
339
345
  const originalText = getOriginalText(startMapping, originalState);
340
- const generatedText = getGeneratedText(startMapping, generatedState);
346
+ const generatedText = getGeneratedText(startMapping, state);
341
347
 
342
- // actual generatedOffset < range startOffset
348
+ // actual generatedOffset < startOffset
343
349
  const generatedPos = range.startOffset - startMapping.generatedOffset;
344
350
 
345
351
  const originalPos = getOriginalStartPosition(originalText, generatedText, generatedPos);
346
352
 
347
- // if (originalState.sourcePath.endsWith('src/components/report.vue') && range.count === 0) {
353
+ // if (originalState.sourcePath.endsWith('src/components/report.vue')) {
348
354
  // console.log('====================================================================');
349
355
  // console.log('fix startMapping', originalState.sourcePath);
350
356
  // console.log(startMapping);
@@ -361,7 +367,7 @@ const fixStartColumn = (startMapping, range, generatedState, originalState) => {
361
367
 
362
368
  // ========================================================================================================
363
369
 
364
- const fixEndColumn = (endMapping, range, startMapping, generatedState, originalState) => {
370
+ const fixEndColumn = (endMapping, range, startMapping, state, originalState) => {
365
371
 
366
372
  const originalColumn = endMapping.originalColumn;
367
373
 
@@ -373,16 +379,28 @@ const fixEndColumn = (endMapping, range, startMapping, generatedState, originalS
373
379
 
374
380
  // ================================
375
381
  // diff line, to the line end
376
- if (endMapping.originalLine !== startMapping.originalLine) {
377
- endMapping.column = Infinity;
378
- return;
379
- }
382
+ // if (endMapping.originalLine !== startMapping.originalLine) {
383
+ // endMapping.column = Infinity;
384
+ // return;
385
+
386
+ // console.log(originalState.sourcePath, '-------------------------------diff line---------------------------------------');
387
+ // console.log(range, startMapping, endMapping);
388
+
389
+ // }
380
390
 
381
391
  // ================================
382
392
  // in the same line
383
393
 
384
394
  const originalText = getOriginalText(endMapping, originalState);
385
395
 
396
+ // if (originalState.sourcePath.indexOf('comments.js') !== -1) {
397
+ // if (range.endOffset === 1077) {
398
+ // console.log('----------------------------------------------------------------------');
399
+ // console.log(originalText);
400
+ // console.log(range, startMapping, endMapping);
401
+ // }
402
+ // }
403
+
386
404
  // exclusive, need exclude some end strings
387
405
  if (!endMapping.exclusive) {
388
406
  endMapping.column = originalColumn + originalText.length;
@@ -390,14 +408,14 @@ const fixEndColumn = (endMapping, range, startMapping, generatedState, originalS
390
408
  }
391
409
 
392
410
 
393
- const generatedText = getGeneratedText(endMapping, generatedState);
411
+ const generatedText = getGeneratedText(endMapping, state);
394
412
 
395
- // actual generatedOffset < range endOffset
413
+ // actual generatedOffset < endOffset
396
414
  const generatedPos = range.endOffset - endMapping.generatedOffset;
397
415
 
398
416
  const originalPos = getOriginalEndPosition(originalText, generatedText, generatedPos);
399
417
 
400
- // if (originalState.sourcePath.endsWith('v8/src/app.vue') && range.count === 0) {
418
+ // if (originalState.sourcePath.endsWith('v8/src/app.vue')) {
401
419
  // console.log('====================================================================');
402
420
  // console.log('fix endMapping', originalState.sourcePath);
403
421
  // console.log(startMapping, endMapping);
@@ -429,14 +447,17 @@ const isOffsetCrossLine = (startMapping, offset) => {
429
447
  return false;
430
448
  };
431
449
 
432
- const findStartMapping = (range, generatedState, originalMap) => {
450
+ const findStartMapping = (range, state, originalMap) => {
433
451
 
434
452
  // startOffset: inclusive
435
453
  const startOffset = range.startOffset;
436
454
 
437
- const startMapping = findOffsetMapping(generatedState, startOffset);
438
- if (!startMapping) {
439
- return;
455
+ const startMapping = findOffsetMapping(state, startOffset);
456
+ if (startMapping.error) {
457
+ return {
458
+ error: true,
459
+ errors: startMapping.errors.concat(`not found start mapping: ${startOffset}`)
460
+ };
440
461
  }
441
462
 
442
463
  // check end offset for start mapping only
@@ -444,17 +465,23 @@ const findStartMapping = (range, generatedState, originalMap) => {
444
465
  // but end mapping is exclusive and offset do -1, possible no mapping found, do not check it
445
466
  if (isOffsetCrossLine(startMapping, startOffset)) {
446
467
  // try next mapping if its offset in the range
447
- const nextMapping = findNextGeneratedDiffMapping(generatedState, startMapping);
468
+ const nextMapping = findNextGeneratedDiffMapping(state, startMapping);
448
469
  if (!nextMapping) {
449
- return;
470
+ return {
471
+ error: true,
472
+ errors: [`not found next generated mapping: ${startMapping}`]
473
+ };
450
474
  }
451
475
 
452
476
  // ignore out of range
453
477
  if (nextMapping.generatedOffset >= range.endOffset) {
454
- return;
478
+ return {
479
+ error: true,
480
+ errors: [`next generated mapping is out of end offset: ${nextMapping.generatedOffset} >= ${range.endOffset}`]
481
+ };
455
482
  }
456
483
 
457
- // if (startMapping.sourceIndex === 1 && range.count === 0) {
484
+ // if (startMapping.sourceIndex === 1) {
458
485
  // console.log('=========================================================');
459
486
  // console.log('find next start');
460
487
  // console.log(startMapping, nextMapping, range);
@@ -474,7 +501,10 @@ const findStartMapping = (range, generatedState, originalMap) => {
474
501
 
475
502
  const originalState = originalMap.get(sourceIndex);
476
503
  if (!originalState) {
477
- return;
504
+ return {
505
+ error: true,
506
+ errors: [`not found original state by source index: ${sourceIndex}`]
507
+ };
478
508
  }
479
509
 
480
510
  return {
@@ -484,24 +514,30 @@ const findStartMapping = (range, generatedState, originalMap) => {
484
514
  };
485
515
 
486
516
 
487
- const findEndMapping = (range, generatedState, startMapping) => {
517
+ const findEndMapping = (range, state, startMapping) => {
488
518
 
489
519
  // endOffset: exclusive
490
520
  const endOffset = range.endOffset;
491
521
 
492
522
  // there could be some comments before end mapping even exact matched
493
- const endMapping = findOffsetMapping(generatedState, endOffset - 1);
494
- if (!endMapping) {
495
- return;
523
+ const endMapping = findOffsetMapping(state, endOffset - 1);
524
+ if (endMapping.error) {
525
+ return {
526
+ error: true,
527
+ errors: startMapping.errors.concat(`not found end mapping: ${endOffset} - 1 (exclusive)`)
528
+ };
496
529
  }
497
530
 
498
531
  // cross file ignore
499
532
  if (endMapping.sourceIndex !== startMapping.sourceIndex) {
500
- return;
533
+ return {
534
+ error: true,
535
+ errors: [`The source index of start and end are not equal: ${startMapping.sourceIndex} != ${endMapping.sourceIndex}`]
536
+ };
501
537
  }
502
538
 
503
539
  // still exclusive
504
- const exclusiveMapping = findOffsetMapping(generatedState, endOffset);
540
+ const exclusiveMapping = findOffsetMapping(state, endOffset);
505
541
  if (exclusiveMapping && exclusiveMapping.originalOffset === endMapping.originalOffset) {
506
542
  endMapping.exclusive = true;
507
543
  }
@@ -509,14 +545,16 @@ const findEndMapping = (range, generatedState, startMapping) => {
509
545
  return endMapping;
510
546
  };
511
547
 
512
- const findOriginalRange = (range, generatedState, originalMap) => {
548
+ const findOriginalRange = (range, state, originalMap) => {
513
549
 
514
550
  // startOffset: inclusive
515
551
  // endOffset: exclusive
516
-
517
- const startResult = findStartMapping(range, generatedState, originalMap);
518
- if (!startResult) {
519
- return;
552
+ const startResult = findStartMapping(range, state, originalMap);
553
+ if (startResult.error) {
554
+ return {
555
+ error: true,
556
+ errors: startResult.errors.concat(`not found start mapping: ${range.startOffset}`)
557
+ };
520
558
  }
521
559
  const { startMapping, originalState } = startResult;
522
560
 
@@ -531,38 +569,44 @@ const findOriginalRange = (range, generatedState, originalMap) => {
531
569
  // }
532
570
  // ==================================================================================
533
571
 
534
- const endMapping = findEndMapping(range, generatedState, startMapping);
535
- if (!endMapping) {
536
- return;
572
+ const endMapping = findEndMapping(range, state, startMapping);
573
+ if (endMapping.error) {
574
+ return {
575
+ error: true,
576
+ errors: endMapping.errors.concat(`not found end mapping: ${range.endOffset}`)
577
+ };
537
578
  }
538
579
 
539
580
  // fix start
540
- fixStartColumn(startMapping, range, generatedState, originalState);
581
+ fixStartColumn(startMapping, range, state, originalState);
541
582
 
542
583
  // fix end
543
- fixEndColumn(endMapping, range, startMapping, generatedState, originalState);
584
+ fixEndColumn(endMapping, range, startMapping, state, originalState);
544
585
 
545
- const positionMapping = originalState.positionMapping;
546
- const originalStart = positionMapping.locationToOffset({
586
+ const locator = originalState.locator;
587
+ const originalStart = locator.locationToOffset({
547
588
  line: startMapping.originalLine + 1,
548
589
  column: startMapping.column
549
590
  });
550
- const originalEnd = positionMapping.locationToOffset({
591
+ const originalEnd = locator.locationToOffset({
551
592
  line: endMapping.originalLine + 1,
552
593
  column: endMapping.column
553
594
  });
554
595
 
555
596
  // range start greater than end
556
- if (originalStart >= originalEnd) {
557
- // console.log(`start >= end: ${originalState.sourcePath}`);
597
+ if (originalStart > originalEnd) {
598
+ // console.log(`start > end: ${originalState.sourcePath}`);
558
599
  // console.log(range, originalRange);
559
- return;
600
+ return {
601
+ error: true,
602
+ errors: [`original start is greater than end: ${originalStart} > ${originalEnd}`]
603
+ };
560
604
  }
561
605
 
562
606
  const originalRange = {
607
+ ... range,
563
608
  startOffset: originalStart,
564
- endOffset: originalEnd,
565
- count: range.count
609
+ endOffset: originalEnd
566
610
  };
567
611
 
568
612
  // if (originalState.showLog) {
@@ -573,7 +617,9 @@ const findOriginalRange = (range, generatedState, originalMap) => {
573
617
 
574
618
  return {
575
619
  originalRange,
576
- originalState
620
+ originalState,
621
+ startMapping,
622
+ endMapping
577
623
  };
578
624
 
579
625
  };
@@ -1,30 +1,29 @@
1
1
  module.exports = class InfoBranch {
2
- constructor(sLoc, eLoc, count) {
3
- this.startLine = sLoc.line;
4
- this.startColumn = sLoc.column;
5
- this.endLine = eLoc.line;
6
- this.endColumn = eLoc.column;
7
- this.count = count;
2
+ constructor(loc, locations, type) {
3
+ this.loc = loc;
4
+ this.line = loc.start.line;
5
+ // [ { start:{line,column}, end:{line,column}, count }, ...]
6
+ this.locations = locations;
7
+ this.type = type || 'branch';
8
8
  }
9
9
 
10
10
  generate() {
11
- const location = {
12
- start: {
13
- line: this.startLine,
14
- column: this.startColumn
15
- },
16
- end: {
17
- line: this.endLine,
18
- column: this.endColumn
19
- }
20
- };
21
11
  return {
22
- type: 'branch',
23
- line: this.startLine,
24
- loc: location,
25
- locations: [{
26
- ... location
27
- }]
12
+ loc: this.loc,
13
+ type: this.type,
14
+ locations: this.locations.map((item) => {
15
+ const { start, end } = item;
16
+ return {
17
+ start: start || {},
18
+ end: end || {}
19
+ };
20
+
21
+ }),
22
+ line: this.line
28
23
  };
29
24
  }
25
+
26
+ generateCounts() {
27
+ return this.locations.map((item) => item.count);
28
+ }
30
29
  };
@@ -1,29 +1,17 @@
1
1
  module.exports = class InfoFunction {
2
- constructor(sLoc, eLoc, count, name) {
3
- this.startLine = sLoc.line;
4
- this.startColumn = sLoc.column;
5
- this.endLine = eLoc.line;
6
- this.endColumn = eLoc.column;
2
+ constructor(loc, count, name) {
3
+ this.loc = loc;
4
+ this.line = loc.start.line;
7
5
  this.count = count;
8
6
  this.name = name || '(anonymous)';
9
7
  }
10
8
 
11
9
  generate() {
12
- const loc = {
13
- start: {
14
- line: this.startLine,
15
- column: this.startColumn
16
- },
17
- end: {
18
- line: this.endLine,
19
- column: this.endColumn
20
- }
21
- };
22
10
  return {
23
11
  name: this.name,
24
- decl: loc,
25
- loc: loc,
26
- line: this.startLine
12
+ decl: this.loc,
13
+ loc: this.loc,
14
+ line: this.line
27
15
  };
28
16
  }
29
17
  };
@@ -1,8 +1,11 @@
1
1
  module.exports = class InfoLine {
2
2
  constructor(line, column, count = 1) {
3
+ // 1 based
3
4
  this.line = line;
4
5
  this.column = column;
5
6
  this.count = count;
7
+ // covered full line, could be false even count > 0
8
+ this.covered = count > 0;
6
9
  }
7
10
 
8
11
  generate() {
package/lib/generate.js CHANGED
@@ -67,8 +67,12 @@ const getReportGroup = (reports, lcov, dataType) => {
67
67
  }
68
68
 
69
69
  const allSupportedReports = [
70
+
71
+ // v8
70
72
  'v8',
71
73
  'v8-json',
74
+
75
+ // istanbul
72
76
  'clover',
73
77
  'cobertura',
74
78
  'html',
@@ -7,7 +7,7 @@ const istanbulLibReport = require('istanbul-lib-report');
7
7
  const Util = require('../utils/util.js');
8
8
  const IstanbulSummary = require('./istanbul-summary.js');
9
9
 
10
- const { initIstanbulSourcePath } = require('../converter/source-path.js');
10
+ const { initIstanbulSourcePath } = require('../utils/source-path.js');
11
11
 
12
12
  const findHtmlPath = (outputDir) => {
13
13
  const defaultHtml = path.resolve(outputDir, 'index.html');