monocart-coverage-reports 2.0.6 → 2.0.8

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
@@ -19,6 +19,7 @@
19
19
  * [How to convert V8 to Istanbul](#how-to-convert-v8-to-istanbul)
20
20
  - [Using `v8-to-istanbul`](#using-v8-to-istanbul)
21
21
  - [How Monocart Works](#how-monocart-works)
22
+ * [Ignoring Uncovered Lines](#ignoring-uncovered-lines)
22
23
  * [Chromium Coverage API](#chromium-coverage-api)
23
24
  * [Istanbul Introduction](#istanbul-introduction)
24
25
  * [Thanks](#thanks)
@@ -43,24 +44,6 @@ console.log(coverageResults.summary);
43
44
  - [lib/default/options.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/lib/default/options.js)
44
45
 
45
46
  ## Available Reports
46
- ```js
47
- const CoverageReport = require('monocart-coverage-reports');
48
- const options = {
49
- outputDir: './coverage-reports',
50
- reports: [
51
- ['console-summary'],
52
- ['v8'],
53
- ['html', {
54
- subdir: 'istanbul'
55
- }],
56
- ['json', {
57
- file: 'my-json-file.json'
58
- }],
59
- 'lcovonly'
60
- ]
61
- }
62
- const coverageReport = new CoverageReport(options);
63
- ```
64
47
  - `v8` (V8 data only)
65
48
  - [V8 html](https://cenfun.github.io/monocart-coverage-reports/v8) - Example for browser, build with webpack, and also [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild)
66
49
  - [V8 Node](https://cenfun.github.io/monocart-coverage-reports/v8-node-env) - Example for Node.js using env, and also [V8 API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp)
@@ -94,6 +77,25 @@ const coverageReport = new CoverageReport(options);
94
77
  - `text-lcov`
95
78
  - `text-summary`
96
79
 
80
+ ```js
81
+ const CoverageReport = require('monocart-coverage-reports');
82
+ const options = {
83
+ outputDir: './coverage-reports',
84
+ reports: [
85
+ ['console-summary'],
86
+ ['v8'],
87
+ ['html', {
88
+ subdir: 'istanbul'
89
+ }],
90
+ ['json', {
91
+ file: 'my-json-file.json'
92
+ }],
93
+ 'lcovonly'
94
+ ]
95
+ }
96
+ const coverageReport = new CoverageReport(options);
97
+ ```
98
+
97
99
  ## Integration
98
100
  - [monocart-reporter](https://cenfun.github.io/monocart-reporter/) - Test reporter for [Playwright](https://github.com/microsoft/playwright)
99
101
  - [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - Integration with [Vitest](https://github.com/vitest-dev/vitest) coverage
@@ -165,8 +167,9 @@ console.log(coverageResults.summary);
165
167
 
166
168
  ## Collecting V8 Coverage Data
167
169
  - For source code: enable `sourcemap` and do not compress/minify:
168
- - Webpack: with `source-map` [devtool](https://webpack.js.org/configuration/devtool/) and `development` [mode](https://webpack.js.org/configuration/mode/), example [webpack.config-v8.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/webpack.config-v8.js)
169
- - Rollup: [options](https://rollupjs.org/configuration-options/) `sourcemap: true`
170
+ - Webpack: build with `source-map` [devtool](https://webpack.js.org/configuration/devtool/) and `development` [mode](https://webpack.js.org/configuration/mode/), example [webpack.config-v8.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/webpack.config-v8.js)
171
+ - Rollup: build with [options](https://rollupjs.org/configuration-options/) `sourcemap: true`
172
+ - Vite: build with [options](https://vitejs.dev/config/build-options.html) `sourcemap: true` and `minify: false`
170
173
  - Browser (Chromium Only)
171
174
  > Collecting coverage data with [Chromium Coverage API](#chromium-coverage-api), see [example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-v8.js)
172
175
  - Node.js
@@ -246,11 +249,9 @@ functions.forEach(block => {
246
249
  // Problem: not every block is branch, and the first block is actually function.
247
250
  if (block.functionName && i === 0) {
248
251
  // v8-to-istanbul: count range as function here.
249
- // Problem: there is no function name if the function is anonymous or expression.
250
252
  }
251
253
  } else if (block.functionName) {
252
254
  // v8-to-istanbul: count range as function here.
253
- // Problem: same as above function.
254
255
  }
255
256
  }
256
257
  });
@@ -271,6 +272,28 @@ We have removed `v8-to-istanbul` because of the two major problems and implement
271
272
  | LogicalExpression | ✔ Not Perfect |
272
273
  | SwitchStatement | ✔ Not Perfect |
273
274
 
275
+ ## Ignoring Uncovered Codes
276
+ To ignore codes, use the special comment which starts with `v8 ignore `:
277
+ - ignoring all until told
278
+ ```js
279
+ /* v8 ignore start */
280
+ function uncovered() {
281
+ }
282
+ /* v8 ignore stop */
283
+ ```
284
+ - ignoring the next line or next N lines
285
+ ```js
286
+ /* v8 ignore next */
287
+ const os = platform === 'wind32' ? 'Windows' : 'Other';
288
+
289
+ const os = platform === 'wind32' ? 'Windows' /* v8 ignore next */ : 'Other';
290
+
291
+ /* v8 ignore next 3 */
292
+ if (platform === 'linux') {
293
+ console.info('hello linux');
294
+ }
295
+ ```
296
+
274
297
  ## Chromium Coverage API
275
298
  - [V8 coverage report](https://v8.dev/blog/javascript-code-coverage) - Native support for JavaScript code coverage to V8. (Chromium only)
276
299
  - [Puppeteer Coverage Class](https://pptr.dev/api/puppeteer.coverage)
@@ -3,9 +3,8 @@ const {
3
3
  } = require('../packages/monocart-coverage-vendor.js');
4
4
  const Util = require('../utils/util.js');
5
5
 
6
- const {
7
- createBranches, collectBranches, findInRanges
8
- } = require('./branches.js');
6
+ const { createBranches, collectBranches } = require('./branches.js');
7
+ const findInRanges = require('./find-in-ranges.js');
9
8
 
10
9
  const getFunctionRange = (start, end, state) => {
11
10
 
@@ -1,40 +1,5 @@
1
1
  const Util = require('../utils/util.js');
2
-
3
- const quickFindRange = (position, ranges) => {
4
- let start = 0;
5
- let end = ranges.length - 1;
6
- while (end - start > 1) {
7
- const i = Math.floor((start + end) * 0.5);
8
- const item = ranges[i];
9
- if (position < item.startOffset) {
10
- end = i;
11
- continue;
12
- }
13
- if (position > item.endOffset) {
14
- start = i;
15
- continue;
16
- }
17
- return ranges[i];
18
- }
19
- // last two items, less is start
20
- const endItem = ranges[end];
21
- if (position < endItem.startOffset) {
22
- return ranges[start];
23
- }
24
- return ranges[end];
25
- };
26
-
27
-
28
- const findInRanges = (start, end, ranges) => {
29
- if (!Util.isList(ranges)) {
30
- return;
31
- }
32
- const range = quickFindRange(start, ranges);
33
- if (start >= range.startOffset && end <= range.endOffset) {
34
- return range;
35
- }
36
- };
37
-
2
+ const findInRanges = require('./find-in-ranges.js');
38
3
 
39
4
  const findBranchBlock = (start, end, functionInfo) => {
40
5
  const { range } = functionInfo;
@@ -432,7 +397,6 @@ const collectBranches = (branchMap) => {
432
397
  };
433
398
 
434
399
  module.exports = {
435
- findInRanges,
436
400
  createBranches,
437
401
  collectBranches
438
402
  };