monocart-coverage-reports 2.8.6 → 2.9.0

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
@@ -35,6 +35,7 @@
35
35
  * [Common issues](#common-issues)
36
36
  - [Unexpected coverage](#unexpected-coverage)
37
37
  - [Unparsable source](#unparsable-source)
38
+ - [JavaScript heap out of memory](#javascript-heap-out-of-memory)
38
39
  * [Debug for Coverage and Sourcemap](#debug-for-coverage-and-sourcemap)
39
40
  * [Integration with Any Testing Framework](#integration-with-any-testing-framework)
40
41
  * [Integration Examples](#integration-examples)
@@ -138,19 +139,27 @@ For more information, see [Command Line](#command-line)
138
139
 
139
140
  > Other build-in reports (both V8 and Istanbul data):
140
141
 
141
- - `codecov`
142
- - coverage data for [Codecov](https://docs.codecov.com/docs/codecov-custom-coverage-format), see [example](https://app.codecov.io/github/cenfun/monocart-coverage-reports)
142
+ - `codecov` Save coverage data to a json file with [Codecov](https://docs.codecov.com/docs/codecov-custom-coverage-format) format (defaults to `codecov.json`), see [example](https://app.codecov.io/github/cenfun/monocart-coverage-reports).
143
143
 
144
- - `console-summary` shows coverage summary in the console
144
+ - `codacy` Save coverage data to a json file with [Codacy API](https://api.codacy.com/swagger#tocscoveragereport) format (defaults to `codacy.json`).
145
+
146
+ - `console-summary` shows coverage summary in the console.
145
147
 
146
148
  ![](./assets/console-summary.png)
147
149
 
148
- - `console-details` Show file coverage and uncovered lines in the console. Like `text`, but for V8. For Github actions, we can enforce color with env: `FORCE_COLOR: true`.
150
+ - `console-details` Show coverage details in the console. Like `text`, but for V8. For Github actions, we can enforce color with env: `FORCE_COLOR: true`.
149
151
 
150
152
  ![](./assets/console-details.png)
151
153
 
152
- - `raw` only keep all original data, which can be used for other reports input with `inputDir`
153
- - see [Merge Coverage Reports](#merge-coverage-reports)
154
+ - `markdown-summary` Save coverage summary to a markdown file (defaults to `coverage-summary.md`). For Github actions, we can show the markdown content to [a job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary)
155
+ ```sh
156
+ cat path-to/coverage-summary.md >> $GITHUB_STEP_SUMMARY
157
+ ```
158
+ ![](./assets/markdown-summary.png)
159
+
160
+ - `markdown-details` Save coverage details to a markdown file (defaults to `coverage-details.md`).
161
+
162
+ - `raw` only keep all original data, which can be used for other reports input with `inputDir`. see [Merge Coverage Reports](#merge-coverage-reports)
154
163
 
155
164
  - Custom Reporter
156
165
  ```js
@@ -881,6 +890,15 @@ const coverageOptions = {
881
890
  }
882
891
  ```
883
892
 
893
+ ### JavaScript heap out of memory
894
+ When there are a lot of raw v8 coverage files to process, it may cause OOM. We can try the following Node.js options:
895
+ ```sh
896
+ - run: npm run test:coverage
897
+ env:
898
+ NODE_OPTIONS: --max-old-space-size=8192
899
+ ```
900
+
901
+
884
902
  ## Debug for Coverage and Sourcemap
885
903
  > Sometimes, the coverage is not what we expect. The next step is to figure out why, and we can easily find out the answer step by step through debugging.
886
904
  - Start debugging for v8 report with option `logging: 'debug'`
@@ -900,6 +918,11 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
900
918
 
901
919
  ![](./assets/debug-sourcemap.png)
902
920
 
921
+ - Show time logs with env `MCR_LOG_TIME`
922
+ ```js
923
+ process.env.MCR_LOG_TIME = true
924
+ ```
925
+
903
926
  ## Integration with Any Testing Framework
904
927
  - API
905
928
  - Collecting coverage data when any stage of the test is completed, and adding the coverage data to the coverage reporter. `await mcr.add(coverageData)`
package/README.zh-Hans.md CHANGED
@@ -35,6 +35,7 @@
35
35
  * [常见问题](#common-issues)
36
36
  - [Unexpected coverage](#unexpected-coverage)
37
37
  - [Unparsable source](#unparsable-source)
38
+ - [JavaScript heap out of memory](#javascript-heap-out-of-memory)
38
39
  * [如何调试覆盖率数据和查看sourcemap](#debug-for-coverage-and-sourcemap)
39
40
  * [如何跟其他框架集成](#integration-with-any-testing-framework)
40
41
  * [集成的例子](#integration-examples)
@@ -138,8 +139,9 @@ mcr node my-app.js -r v8,console-details
138
139
 
139
140
  > 其他内置报告 (V8和Istanbul格式数据都支持):
140
141
 
141
- - `codecov`
142
- - 专属支持[Codecov](https://docs.codecov.com/docs/codecov-custom-coverage-format)的报告, see [example](https://app.codecov.io/github/cenfun/monocart-coverage-reports)
142
+ - `codecov` 保存覆盖率数据到 [Codecov](https://docs.codecov.com/docs/codecov-custom-coverage-format) 专属的json文件 (默认是`codecov.json`), 见[例子](https://app.codecov.io/github/cenfun/monocart-coverage-reports)
143
+
144
+ - `codacy` 保存覆盖率数据到 [Codacy](https://api.codacy.com/swagger#tocscoveragereport) 专属的json文件 (默认是`codacy.json`)
143
145
 
144
146
  - `console-summary` 在控制台显示覆盖率概要
145
147
 
@@ -149,8 +151,15 @@ mcr node my-app.js -r v8,console-details
149
151
 
150
152
  ![](./assets/console-details.png)
151
153
 
152
- - `raw` 只是保存原始覆盖率数据, 用于使用`inputDir`参数来导入多个原始数据进行合并报告
153
- - 参见 [合并覆盖率报告](#merge-coverage-reports)
154
+ - `markdown-summary` 保存概要信息到markdown文件 (默认是`coverage-summary.md`)。 如果是Github actions, 可以把markdown的内容添加到[a job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary)
155
+ ```sh
156
+ cat path-to/coverage-summary.md >> $GITHUB_STEP_SUMMARY
157
+ ```
158
+ ![](./assets/markdown-summary.png)
159
+
160
+ - `markdown-details` 保存覆盖率详情到markdown文件 (默认是 `coverage-details.md`)
161
+
162
+ - `raw` 只是保存原始覆盖率数据, 用于使用`inputDir`参数来导入多个原始数据进行合并报告。参见 [合并覆盖率报告](#merge-coverage-reports)
154
163
 
155
164
  - 自定义报告
156
165
  ```js
@@ -884,6 +893,15 @@ const coverageOptions = {
884
893
  }
885
894
  ```
886
895
 
896
+ ### JavaScript heap out of memory
897
+ 内存溢出问题可能出现在有太多的原生V8覆盖率文件要处理. 我们可以使用Node.js的一个选项来增加内存使用:
898
+ ```sh
899
+ - run: npm run test:coverage
900
+ env:
901
+ NODE_OPTIONS: --max-old-space-size=8192
902
+ ```
903
+
904
+
887
905
  ## Debug for Coverage and Sourcemap
888
906
  > 当你觉得覆盖率存在问题的时候,`MCR`支持自行调试来核验覆盖率的准确性
889
907
  - 首先打开调试设置`logging: 'debug'`
@@ -903,6 +921,11 @@ const coverageOptions = {
903
921
 
904
922
  ![](./assets/debug-sourcemap.png)
905
923
 
924
+ - 使用环境变量`MCR_LOG_TIME`显示时间日志
925
+ ```js
926
+ process.env.MCR_LOG_TIME = true
927
+ ```
928
+
906
929
  ## Integration with Any Testing Framework
907
930
  通用集成方案
908
931
  - 通过API接口在程序集成
@@ -115,24 +115,30 @@ const handleLinesCoverage = (bytes, locator, ignoredRanges) => {
115
115
  // init lines
116
116
  let blankCount = 0;
117
117
  let commentCount = 0;
118
+ const dataExtras = {};
118
119
  // line 1 based
119
120
  const lineMap = new Map();
120
121
  locator.lines.forEach((lineItem) => {
122
+ // line 1-base
123
+ const line = lineItem.line + 1;
124
+
121
125
  // exclude blank and comment
122
126
  if (lineItem.blank) {
123
127
  blankCount += 1;
128
+ dataExtras[line] = 'b';
124
129
  return;
125
130
  }
126
131
  if (lineItem.comment) {
127
132
  commentCount += 1;
133
+ dataExtras[line] = 'c';
128
134
  return;
129
135
  }
130
136
  const ignored = Util.findInRanges(lineItem.start, lineItem.end, ignoredRanges);
131
137
  if (ignored) {
138
+ dataExtras[line] = 'i';
132
139
  return;
133
140
  }
134
- // line 1-base
135
- const line = lineItem.line + 1;
141
+
136
142
  lineItem.coveredCount = 1;
137
143
  lineItem.uncoveredEntire = null;
138
144
  lineItem.uncoveredPieces = [];
@@ -147,8 +153,7 @@ const handleLinesCoverage = (bytes, locator, ignoredRanges) => {
147
153
  blank: blankCount,
148
154
  comment: commentCount
149
155
  };
150
- // data lines for codecov
151
- // https://docs.codecov.com/docs/codecov-custom-coverage-format
156
+ // data lines
152
157
  const dataLines = {};
153
158
 
154
159
  // no ignore items
@@ -165,6 +170,7 @@ const handleLinesCoverage = (bytes, locator, ignoredRanges) => {
165
170
 
166
171
  return {
167
172
  dataLines,
173
+ dataExtras,
168
174
  summaryLines
169
175
  };
170
176
  };
@@ -263,9 +269,12 @@ const collectFileCoverage = (v8Data, state, options) => {
263
269
  // ==========================================
264
270
  // lines
265
271
  // after bytes with ignored, before calculateV8Lines
266
- const { dataLines, summaryLines } = handleLinesCoverage(data.bytes, locator, ignoredRanges);
272
+ const {
273
+ dataLines, dataExtras, summaryLines
274
+ } = handleLinesCoverage(data.bytes, locator, ignoredRanges);
267
275
 
268
276
  data.lines = dataLines;
277
+ data.extras = dataExtras;
269
278
 
270
279
  // console.log('statements', state.sourcePath, statements.length);
271
280
 
@@ -27,6 +27,9 @@ module.exports = {
27
27
  // {string} base dir for normalizing the relative source path, defaults to cwd
28
28
  baseDir: null,
29
29
 
30
+ // {string} coverage data dir, alternative to method `addFromDir()`, defaults to null
31
+ dataDir: null,
32
+
30
33
  // (V8 only) {function} A filter function to execute for each element in the V8 list.
31
34
  // entryFilter: (entry) => {
32
35
  // if (entry.url.indexOf('googleapis.com') !== -1) {