monocart-coverage-reports 2.10.0 → 2.10.2
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 +8 -5
- package/README.zh-Hans.md +6 -4
- package/lib/converter/ast-visitor.js +39 -1
- package/lib/converter/ast.js +3 -1
- package/lib/converter/converter.js +16 -7
- package/lib/converter/find-original-range.js +20 -13
- package/lib/generate.js +3 -1
- package/lib/packages/monocart-coverage-assets.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +10 -10
- package/lib/platform/share.js +6 -0
- package/lib/reports/custom.js +34 -0
- package/lib/reports/markdown-details.js +1 -2
- package/lib/reports/markdown-summary.js +1 -2
- package/lib/utils/markdown.js +2 -2
- package/lib/utils/util.js +86 -30
- package/lib/v8/v8.js +2 -1
- package/package.json +116 -116
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
- [Playwright](#playwright)
|
|
43
43
|
- [c8](#c8)
|
|
44
44
|
- [CodeceptJS](#codeceptjs)
|
|
45
|
+
- [VSCode](#vscode)
|
|
45
46
|
- [Jest](#jest)
|
|
46
47
|
- [Vitest](#vitest)
|
|
47
48
|
- [Puppeteer](#puppeteer)
|
|
@@ -116,8 +117,10 @@ For more information, see [Command Line](#command-line)
|
|
|
116
117
|

|
|
117
118
|
|
|
118
119
|
- `v8-json`
|
|
119
|
-
- Save `CoverageResults` to a json file
|
|
120
|
-
-
|
|
120
|
+
- Save `CoverageResults` to a json file (defaults to [`coverage-report.json`](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)).
|
|
121
|
+
- Shows native V8 code coverage with VSCode extension: [Monocart Coverage for VSCode](https://github.com/cenfun/monocart-coverage-vscode)
|
|
122
|
+
|
|
123
|
+

|
|
121
124
|
|
|
122
125
|
> Istanbul build-in reports (both V8 and Istanbul data):
|
|
123
126
|
|
|
@@ -973,6 +976,9 @@ c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js
|
|
|
973
976
|
### [CodeceptJS](https://github.com/codeceptjs/CodeceptJS)
|
|
974
977
|
- CodeceptJS is a [BDD](https://codecept.io/bdd/) + [AI](https://codecept.io/ai/) testing framework for e2e testing, it has integrated `MCR` since [v3.5.15](https://github.com/codeceptjs/CodeceptJS/releases/tag/3.5.15), see [plugins/coverage](https://codecept.io/plugins/#coverage)
|
|
975
978
|
|
|
979
|
+
### [VSCode](https://github.com/microsoft/vscode)
|
|
980
|
+
- [Monocart Coverage for VSCode](https://github.com/cenfun/monocart-coverage-vscode) - Shows native V8 code coverage in VSCode
|
|
981
|
+
|
|
976
982
|
### [Jest](https://github.com/jestjs/jest/)
|
|
977
983
|
- [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - Jest custom reporter for coverage reports
|
|
978
984
|
- [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (Jest unit + Playwright e2e sharding)
|
|
@@ -1119,9 +1125,6 @@ git commit -m "Saving files before refreshing line endings"
|
|
|
1119
1125
|
npm run eol
|
|
1120
1126
|
```
|
|
1121
1127
|
|
|
1122
|
-
### VSCode Extension
|
|
1123
|
-
- [Coverage Gutters](https://github.com/ryanluker/vscode-coverage-gutters) - Display test coverage generated by lcov or xml in VSCode editor.
|
|
1124
|
-
|
|
1125
1128
|
## Thanks
|
|
1126
1129
|
- [@bcoe](https://github.com/bcoe)
|
|
1127
1130
|
- [@edumserrano](https://github.com/edumserrano)
|
package/README.zh-Hans.md
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
- [Playwright](#playwright)
|
|
43
43
|
- [c8](#c8)
|
|
44
44
|
- [CodeceptJS](#codeceptjs)
|
|
45
|
+
- [VSCode](#vscode)
|
|
45
46
|
- [Jest](#jest)
|
|
46
47
|
- [Vitest](#vitest)
|
|
47
48
|
- [Puppeteer](#puppeteer)
|
|
@@ -117,7 +118,8 @@ mcr node my-app.js -r v8,console-details
|
|
|
117
118
|
|
|
118
119
|
- `v8-json`
|
|
119
120
|
- 保存 `CoverageResults` 到一个json文件
|
|
120
|
-
-
|
|
121
|
+
- 保存 `CoverageResults` 到一个json文件 (默认是 [`coverage-report.json`](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json))
|
|
122
|
+
- 用于VSCode扩展来显示原生V8代码覆盖率: [Monocart Coverage for VSCode](https://github.com/cenfun/monocart-coverage-vscode)
|
|
121
123
|
|
|
122
124
|
> 内置Istanbul报告 (V8和Istanbul格式数据都支持):
|
|
123
125
|
|
|
@@ -977,6 +979,9 @@ c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js
|
|
|
977
979
|
### [CodeceptJS](https://github.com/codeceptjs/CodeceptJS)
|
|
978
980
|
- CodeceptJS is a [BDD](https://codecept.io/bdd/) + [AI](https://codecept.io/ai/) testing framework for e2e testing, it has integrated `MCR` since [v3.5.15](https://github.com/codeceptjs/CodeceptJS/releases/tag/3.5.15), see [plugins/coverage](https://codecept.io/plugins/#coverage)
|
|
979
981
|
|
|
982
|
+
### [VSCode](https://github.com/microsoft/vscode)
|
|
983
|
+
- [Monocart Coverage for VSCode](https://github.com/cenfun/monocart-coverage-vscode) - Shows native V8 code coverage in VSCode
|
|
984
|
+
|
|
980
985
|
### [Jest](https://github.com/jestjs/jest/)
|
|
981
986
|
- [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - Jest custom reporter for coverage reports
|
|
982
987
|
- [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (Jest unit + Playwright e2e sharding)
|
|
@@ -1123,9 +1128,6 @@ git commit -m "Saving files before refreshing line endings"
|
|
|
1123
1128
|
npm run eol
|
|
1124
1129
|
```
|
|
1125
1130
|
|
|
1126
|
-
### VSCode Extension
|
|
1127
|
-
- [Coverage Gutters](https://github.com/ryanluker/vscode-coverage-gutters) - Display test coverage generated by lcov or xml in VSCode editor.
|
|
1128
|
-
|
|
1129
1131
|
## Thanks
|
|
1130
1132
|
- [@bcoe](https://github.com/bcoe)
|
|
1131
1133
|
- [@edumserrano](https://github.com/edumserrano)
|
|
@@ -632,6 +632,7 @@ const getRootFunctionState = (ast, coverageInfo) => {
|
|
|
632
632
|
return rootState;
|
|
633
633
|
};
|
|
634
634
|
|
|
635
|
+
// eslint-disable-next-line complexity
|
|
635
636
|
const findFunctionRange = (item, coverageInfo) => {
|
|
636
637
|
|
|
637
638
|
const { node, reverseParents } = item;
|
|
@@ -645,13 +646,49 @@ const findFunctionRange = (item, coverageInfo) => {
|
|
|
645
646
|
return functionRange;
|
|
646
647
|
}
|
|
647
648
|
|
|
649
|
+
// `static async` case:
|
|
650
|
+
// [1]static [2]async [3]covered(active) {
|
|
651
|
+
// v8 start: 2
|
|
652
|
+
// ast start: 1,3
|
|
653
|
+
|
|
654
|
+
// fixed by async or static
|
|
655
|
+
|
|
656
|
+
// handle for static async
|
|
657
|
+
if (node.async) {
|
|
658
|
+
// 'async '.length
|
|
659
|
+
const asyncLen = 6;
|
|
660
|
+
const asyncStart = start - asyncLen;
|
|
661
|
+
// console.log(asyncStart, 'asyncStart ===============================================');
|
|
662
|
+
const asyncRange = getFunctionRange(asyncStart, end, type, coverageInfo);
|
|
663
|
+
if (asyncRange) {
|
|
664
|
+
return asyncRange;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
648
668
|
// try if class MethodDefinition
|
|
649
669
|
// 0 is function self
|
|
650
670
|
const parent = reverseParents[1];
|
|
651
671
|
if (parent && parent.type === 'MethodDefinition') {
|
|
652
|
-
|
|
672
|
+
|
|
673
|
+
const parentRange = getFunctionRange(parent.start, parent.end, parent.type, coverageInfo);
|
|
674
|
+
if (parentRange) {
|
|
675
|
+
return parentRange;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (parent.static) {
|
|
679
|
+
// 'static '.length
|
|
680
|
+
const staticLen = 7;
|
|
681
|
+
const staticStart = parent.start + staticLen;
|
|
682
|
+
// console.log(staticStart, ' staticStart ============================================');
|
|
683
|
+
const staticRange = getFunctionRange(staticStart, parent.end, parent.type, coverageInfo);
|
|
684
|
+
if (staticRange) {
|
|
685
|
+
return staticRange;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
653
689
|
}
|
|
654
690
|
|
|
691
|
+
|
|
655
692
|
};
|
|
656
693
|
|
|
657
694
|
const collectAstInfo = (ast, coverageInfo) => {
|
|
@@ -669,6 +706,7 @@ const collectAstInfo = (ast, coverageInfo) => {
|
|
|
669
706
|
const {
|
|
670
707
|
start, end, id
|
|
671
708
|
} = node;
|
|
709
|
+
|
|
672
710
|
const bodyStart = node.body.start;
|
|
673
711
|
const bodyEnd = node.body.end;
|
|
674
712
|
const functionName = id && id.name;
|
package/lib/converter/ast.js
CHANGED
|
@@ -58,7 +58,9 @@ const getCoverageInfo = (coverageList) => {
|
|
|
58
58
|
|
|
59
59
|
functionMap.set(functionRange.startOffset, functionRange);
|
|
60
60
|
if (functionName) {
|
|
61
|
-
|
|
61
|
+
// can not handle `async functionName`
|
|
62
|
+
const possibleNameOffset = functionRange.startOffset + functionName.length;
|
|
63
|
+
functionNameMap.set(possibleNameOffset, functionRange);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
if (functionName === '<static_initializer>') {
|
|
@@ -66,8 +66,8 @@ const applyBytesToLines = (bytes, locator, lineMap) => {
|
|
|
66
66
|
start, end, count, ignored
|
|
67
67
|
} = range;
|
|
68
68
|
|
|
69
|
-
// no need handle ignored
|
|
70
|
-
if (
|
|
69
|
+
// no need handle ignored byte
|
|
70
|
+
if (ignored) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -141,9 +141,8 @@ const handleLinesCoverage = (bytes, locator, ignoredRanges) => {
|
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
lineItem
|
|
145
|
-
|
|
146
|
-
lineItem.uncoveredPieces = [];
|
|
144
|
+
Util.initLineCoverage(lineItem);
|
|
145
|
+
|
|
147
146
|
lineMap.set(line, lineItem);
|
|
148
147
|
});
|
|
149
148
|
|
|
@@ -507,6 +506,11 @@ const handleGeneratedBytesCoverage = (state) => {
|
|
|
507
506
|
if (js) {
|
|
508
507
|
coverageList.forEach((block) => {
|
|
509
508
|
block.ranges.forEach((range) => {
|
|
509
|
+
|
|
510
|
+
const { fixedStart, fixedEnd } = Util.fixSourceRange(state.locator, range.startOffset, range.endOffset);
|
|
511
|
+
range.startOffset = fixedStart;
|
|
512
|
+
range.endOffset = fixedEnd;
|
|
513
|
+
|
|
510
514
|
addJsBytesCoverage(state, range);
|
|
511
515
|
});
|
|
512
516
|
});
|
|
@@ -555,7 +559,9 @@ const handleOriginalFunctionsCoverage = (state, originalStateMap) => {
|
|
|
555
559
|
start, end, bodyStart, bodyEnd
|
|
556
560
|
} = it;
|
|
557
561
|
|
|
558
|
-
const result = findOriginalRange(start, end, state, originalStateMap,
|
|
562
|
+
const result = findOriginalRange(start, end, state, originalStateMap, {
|
|
563
|
+
checkName: true
|
|
564
|
+
});
|
|
559
565
|
if (result.error) {
|
|
560
566
|
logMappingErrors('function', result);
|
|
561
567
|
return;
|
|
@@ -796,6 +802,7 @@ const handleOriginalEmptyBytesCoverage = (state, originalStateMap) => {
|
|
|
796
802
|
});
|
|
797
803
|
};
|
|
798
804
|
|
|
805
|
+
|
|
799
806
|
const handleAllOriginalBytesCoverage = (state, originalStateMap) => {
|
|
800
807
|
|
|
801
808
|
const { js, coverageList } = state;
|
|
@@ -818,7 +825,9 @@ const handleAllOriginalBytesCoverage = (state, originalStateMap) => {
|
|
|
818
825
|
startOffset, endOffset, count
|
|
819
826
|
} = range;
|
|
820
827
|
|
|
821
|
-
const result = findOriginalRange(startOffset, endOffset, state, originalStateMap
|
|
828
|
+
const result = findOriginalRange(startOffset, endOffset, state, originalStateMap, {
|
|
829
|
+
fixOriginalRange: true
|
|
830
|
+
});
|
|
822
831
|
if (result.error) {
|
|
823
832
|
logMappingErrors('byte', result);
|
|
824
833
|
return;
|
|
@@ -534,13 +534,13 @@ const getGeneratedText = (m1, m2, state, offset) => {
|
|
|
534
534
|
};
|
|
535
535
|
|
|
536
536
|
// ========================================================================================================
|
|
537
|
-
const getFunctionName = (mp, state,
|
|
538
|
-
if (checkName && typeof mp.nameIndex !== 'undefined') {
|
|
537
|
+
const getFunctionName = (mp, state, options) => {
|
|
538
|
+
if (options.checkName && typeof mp.nameIndex !== 'undefined') {
|
|
539
539
|
return state.sourceMapNames[mp.nameIndex];
|
|
540
540
|
}
|
|
541
541
|
};
|
|
542
542
|
|
|
543
|
-
const getFixedOriginalStart = (start, mappings, state, cache,
|
|
543
|
+
const getFixedOriginalStart = (start, mappings, state, cache, options) => {
|
|
544
544
|
|
|
545
545
|
const [m1, m2] = mappings;
|
|
546
546
|
const { originalState, crossStart } = cache;
|
|
@@ -549,7 +549,7 @@ const getFixedOriginalStart = (start, mappings, state, cache, checkName) => {
|
|
|
549
549
|
if (crossStart) {
|
|
550
550
|
return {
|
|
551
551
|
originalStart: m2.originalOffset,
|
|
552
|
-
originalName: getFunctionName(m2, state,
|
|
552
|
+
originalName: getFunctionName(m2, state, options)
|
|
553
553
|
};
|
|
554
554
|
}
|
|
555
555
|
|
|
@@ -581,7 +581,7 @@ const getFixedOriginalStart = (start, mappings, state, cache, checkName) => {
|
|
|
581
581
|
|
|
582
582
|
return {
|
|
583
583
|
originalStart: originalOffset + originalPos,
|
|
584
|
-
originalName: getFunctionName(m1, state,
|
|
584
|
+
originalName: getFunctionName(m1, state, options)
|
|
585
585
|
};
|
|
586
586
|
};
|
|
587
587
|
|
|
@@ -642,18 +642,18 @@ const getFixedOriginalEnd = (end, mappings, state, cache) => {
|
|
|
642
642
|
|
|
643
643
|
// ========================================================================================================
|
|
644
644
|
|
|
645
|
-
const getOriginalStartPosition = (cache, state,
|
|
645
|
+
const getOriginalStartPosition = (cache, state, options) => {
|
|
646
646
|
|
|
647
647
|
const { start, startMappings } = cache;
|
|
648
648
|
|
|
649
649
|
if (Array.isArray(startMappings)) {
|
|
650
|
-
return getFixedOriginalStart(start, startMappings, state, cache,
|
|
650
|
+
return getFixedOriginalStart(start, startMappings, state, cache, options);
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
// Exact match
|
|
654
654
|
return {
|
|
655
655
|
originalStart: startMappings.originalOffset,
|
|
656
|
-
originalName: getFunctionName(startMappings, state,
|
|
656
|
+
originalName: getFunctionName(startMappings, state, options)
|
|
657
657
|
};
|
|
658
658
|
};
|
|
659
659
|
|
|
@@ -880,11 +880,12 @@ const getMappingInfo = (start, end, state) => {
|
|
|
880
880
|
};
|
|
881
881
|
};
|
|
882
882
|
|
|
883
|
-
|
|
883
|
+
|
|
884
|
+
const findOriginalRange = (start, end, state, originalMap, options = {}) => {
|
|
884
885
|
|
|
885
886
|
const { sourcePath, rangeCache } = state;
|
|
886
887
|
|
|
887
|
-
const key = `${start}_${end}`;
|
|
888
|
+
const key = `${start}_${end}_${Boolean(options.fixOriginalRange)}`;
|
|
888
889
|
if (rangeCache.has(key)) {
|
|
889
890
|
return rangeCache.get(key);
|
|
890
891
|
}
|
|
@@ -909,7 +910,7 @@ const findOriginalRange = (start, end, state, originalMap, checkName) => {
|
|
|
909
910
|
return createMappingError(cache.errors);
|
|
910
911
|
}
|
|
911
912
|
|
|
912
|
-
const originalStartResult = getOriginalStartPosition(cache, state,
|
|
913
|
+
const originalStartResult = getOriginalStartPosition(cache, state, options);
|
|
913
914
|
const { originalStart, originalName } = originalStartResult;
|
|
914
915
|
// could be used for end
|
|
915
916
|
cache.originalStart = originalStart;
|
|
@@ -926,13 +927,13 @@ const findOriginalRange = (start, end, state, originalMap, checkName) => {
|
|
|
926
927
|
}
|
|
927
928
|
|
|
928
929
|
const { originalState } = cache;
|
|
930
|
+
const locator = originalState.locator;
|
|
929
931
|
|
|
930
|
-
const inComment =
|
|
932
|
+
const inComment = locator.lineParser.commentParser.isComment(originalStart, originalEnd);
|
|
931
933
|
if (inComment) {
|
|
932
934
|
return createMappingError(['the range in a original comment']);
|
|
933
935
|
}
|
|
934
936
|
|
|
935
|
-
|
|
936
937
|
const res = {
|
|
937
938
|
start: originalStart,
|
|
938
939
|
end: originalEnd,
|
|
@@ -940,6 +941,12 @@ const findOriginalRange = (start, end, state, originalMap, checkName) => {
|
|
|
940
941
|
originalState
|
|
941
942
|
};
|
|
942
943
|
|
|
944
|
+
if (options.fixOriginalRange) {
|
|
945
|
+
const { fixedStart, fixedEnd } = Util.fixSourceRange(locator, originalStart, originalEnd);
|
|
946
|
+
res.start = fixedStart;
|
|
947
|
+
res.end = fixedEnd;
|
|
948
|
+
}
|
|
949
|
+
|
|
943
950
|
// cache response
|
|
944
951
|
rangeCache.set(key, res);
|
|
945
952
|
|
package/lib/generate.js
CHANGED
|
@@ -32,6 +32,8 @@ const { markdownSummaryReport } = require('./reports/markdown-summary.js');
|
|
|
32
32
|
|
|
33
33
|
const { rawReport } = require('./reports/raw.js');
|
|
34
34
|
|
|
35
|
+
const { customReport } = require('./reports/custom.js');
|
|
36
|
+
|
|
35
37
|
const allBuiltInReports = {
|
|
36
38
|
// v8
|
|
37
39
|
'v8': 'v8',
|
|
@@ -208,7 +210,7 @@ const generateCoverageReports = async (dataList, sourceCache, options) => {
|
|
|
208
210
|
if (builtInHandler) {
|
|
209
211
|
await builtInHandler(coverageResults, reportOptions, options);
|
|
210
212
|
} else {
|
|
211
|
-
await
|
|
213
|
+
await customReport(reportName, coverageResults, reportOptions, options);
|
|
212
214
|
}
|
|
213
215
|
Util.logTime(`┌ [generate] saved report: ${reportName}`, t1);
|
|
214
216
|
}
|