monocart-coverage-reports 2.10.1 → 2.10.3

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 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,7 @@ For more information, see [Command Line](#command-line)
117
118
 
118
119
  - `v8-json`
119
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)).
120
- - Shows native V8 code coverage with VSCode extension [monocart-coverage-vscode](https://github.com/cenfun/monocart-coverage-vscode)
121
+ - Shows native V8 code coverage with VSCode extension: [Monocart Coverage for VSCode](https://github.com/cenfun/monocart-coverage-vscode)
121
122
 
122
123
  ![](./assets/mcv.gif)
123
124
 
@@ -975,6 +976,9 @@ c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js
975
976
  ### [CodeceptJS](https://github.com/codeceptjs/CodeceptJS)
976
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)
977
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
+
978
982
  ### [Jest](https://github.com/jestjs/jest/)
979
983
  - [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - Jest custom reporter for coverage reports
980
984
  - [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (Jest unit + Playwright e2e sharding)
@@ -1121,9 +1125,6 @@ git commit -m "Saving files before refreshing line endings"
1121
1125
  npm run eol
1122
1126
  ```
1123
1127
 
1124
- ### VSCode Extension
1125
- - [Coverage Gutters](https://github.com/ryanluker/vscode-coverage-gutters) - Display test coverage generated by lcov or xml in VSCode editor.
1126
-
1127
1128
  ## Thanks
1128
1129
  - [@bcoe](https://github.com/bcoe)
1129
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
- - 预览 [coverage-report.json](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)
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)
@@ -146,7 +146,9 @@ const createBranchGroup = (type, node, parents, branchMap) => {
146
146
  };
147
147
 
148
148
  const addBranch = (group, node, locationMap) => {
149
- const { start, end } = node;
149
+ const {
150
+ start, end, type
151
+ } = node;
150
152
 
151
153
  const branchKey = `${group.start}_${group.end}`;
152
154
 
@@ -159,6 +161,24 @@ const addBranch = (group, node, locationMap) => {
159
161
  count: 0
160
162
  };
161
163
 
164
+ if (type === 'SwitchCase') {
165
+
166
+ // console.log(node);
167
+
168
+ // check break
169
+ if (node.consequent) {
170
+ const breakItem = node.consequent.find((it) => it.type === 'BreakStatement');
171
+ if (breakItem) {
172
+ branchInfo.hasBreak = true;
173
+ }
174
+ }
175
+
176
+ // check default
177
+ if (!node.test) {
178
+ branchInfo.isDefault = true;
179
+ }
180
+ }
181
+
162
182
  group.locations.push(branchInfo);
163
183
 
164
184
  // update group end
@@ -183,12 +203,14 @@ const addNoneBranch = (group) => {
183
203
  const updateBlockLocations = (locations) => {
184
204
  const noBlockList = [];
185
205
  let blockCount = 0;
186
- locations.forEach((item) => {
206
+ locations.forEach((item, i) => {
187
207
  if (item.block) {
188
208
  item.count = item.block.count;
189
209
  blockCount += item.count;
190
210
  return;
191
211
  }
212
+ // for calculate mo break branches
213
+ item.index = i;
192
214
  noBlockList.push(item);
193
215
  });
194
216
 
@@ -240,13 +262,34 @@ const LogicalExpression = (group, parentCount) => {
240
262
  };
241
263
 
242
264
  const SwitchStatement = (group, parentCount) => {
243
- const { noBlockList, blockCount } = updateBlockLocations(group.locations);
265
+
266
+ const locations = group.locations;
267
+
268
+ const { noBlockList, blockCount } = updateBlockLocations(locations);
244
269
  if (!noBlockList.length) {
245
270
  return;
246
271
  }
247
- const count = parentCount - blockCount;
272
+
273
+ // calculate switch/case count
274
+ const countLeft = parentCount - blockCount;
248
275
  noBlockList.forEach((item) => {
249
- item.count = count;
276
+
277
+ let hasCount = false;
278
+
279
+ // check no break branches
280
+ for (let i = item.index - 1; i >= 0; i--) {
281
+ const b = locations[i];
282
+ if (b && !b.hasBreak && b.count > 0) {
283
+ item.count += b.count;
284
+ hasCount = true;
285
+ continue;
286
+ }
287
+ break;
288
+ }
289
+
290
+ if (!hasCount) {
291
+ item.count = countLeft;
292
+ }
250
293
  });
251
294
  };
252
295
 
@@ -632,6 +675,7 @@ const getRootFunctionState = (ast, coverageInfo) => {
632
675
  return rootState;
633
676
  };
634
677
 
678
+ // eslint-disable-next-line complexity
635
679
  const findFunctionRange = (item, coverageInfo) => {
636
680
 
637
681
  const { node, reverseParents } = item;
@@ -645,13 +689,49 @@ const findFunctionRange = (item, coverageInfo) => {
645
689
  return functionRange;
646
690
  }
647
691
 
692
+ // `static async` case:
693
+ // [1]static [2]async [3]covered(active) {
694
+ // v8 start: 2
695
+ // ast start: 1,3
696
+
697
+ // fixed by async or static
698
+
699
+ // handle for static async
700
+ if (node.async) {
701
+ // 'async '.length
702
+ const asyncLen = 6;
703
+ const asyncStart = start - asyncLen;
704
+ // console.log(asyncStart, 'asyncStart ===============================================');
705
+ const asyncRange = getFunctionRange(asyncStart, end, type, coverageInfo);
706
+ if (asyncRange) {
707
+ return asyncRange;
708
+ }
709
+ }
710
+
648
711
  // try if class MethodDefinition
649
712
  // 0 is function self
650
713
  const parent = reverseParents[1];
651
714
  if (parent && parent.type === 'MethodDefinition') {
652
- return getFunctionRange(parent.start, parent.end, parent.type, coverageInfo);
715
+
716
+ const parentRange = getFunctionRange(parent.start, parent.end, parent.type, coverageInfo);
717
+ if (parentRange) {
718
+ return parentRange;
719
+ }
720
+
721
+ if (parent.static) {
722
+ // 'static '.length
723
+ const staticLen = 7;
724
+ const staticStart = parent.start + staticLen;
725
+ // console.log(staticStart, ' staticStart ============================================');
726
+ const staticRange = getFunctionRange(staticStart, parent.end, parent.type, coverageInfo);
727
+ if (staticRange) {
728
+ return staticRange;
729
+ }
730
+ }
731
+
653
732
  }
654
733
 
734
+
655
735
  };
656
736
 
657
737
  const collectAstInfo = (ast, coverageInfo) => {
@@ -669,6 +749,7 @@ const collectAstInfo = (ast, coverageInfo) => {
669
749
  const {
670
750
  start, end, id
671
751
  } = node;
752
+
672
753
  const bodyStart = node.body.start;
673
754
  const bodyEnd = node.body.end;
674
755
  const functionName = id && id.name;
@@ -58,7 +58,9 @@ const getCoverageInfo = (coverageList) => {
58
58
 
59
59
  functionMap.set(functionRange.startOffset, functionRange);
60
60
  if (functionName) {
61
- functionNameMap.set(functionRange.startOffset + functionName.length, functionRange);
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>') {