monocart-coverage-reports 2.0.7 → 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)
@@ -166,8 +167,9 @@ console.log(coverageResults.summary);
166
167
 
167
168
  ## Collecting V8 Coverage Data
168
169
  - For source code: enable `sourcemap` and do not compress/minify:
169
- - 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)
170
- - 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`
171
173
  - Browser (Chromium Only)
172
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)
173
175
  - Node.js
@@ -247,11 +249,9 @@ functions.forEach(block => {
247
249
  // Problem: not every block is branch, and the first block is actually function.
248
250
  if (block.functionName && i === 0) {
249
251
  // v8-to-istanbul: count range as function here.
250
- // Problem: there is no function name if the function is anonymous or expression.
251
252
  }
252
253
  } else if (block.functionName) {
253
254
  // v8-to-istanbul: count range as function here.
254
- // Problem: same as above function.
255
255
  }
256
256
  }
257
257
  });
@@ -272,6 +272,28 @@ We have removed `v8-to-istanbul` because of the two major problems and implement
272
272
  | LogicalExpression | ✔ Not Perfect |
273
273
  | SwitchStatement | ✔ Not Perfect |
274
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
+
275
297
  ## Chromium Coverage API
276
298
  - [V8 coverage report](https://v8.dev/blog/javascript-code-coverage) - Native support for JavaScript code coverage to V8. (Chromium only)
277
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
  };