| 1 | # v8-to-istanbul
|
|---|
| 2 |
|
|---|
| 3 | [](https://travis-ci.org/istanbuljs/v8-to-istanbul)
|
|---|
| 4 | [](https://conventionalcommits.org)
|
|---|
| 5 | 
|
|---|
| 6 |
|
|---|
| 7 | converts from v8 coverage format to [istanbul's coverage format](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md).
|
|---|
| 8 |
|
|---|
| 9 | ## Usage
|
|---|
| 10 |
|
|---|
| 11 | ```js
|
|---|
| 12 | const v8toIstanbul = require('v8-to-istanbul')
|
|---|
| 13 | // the path to the original source-file is required, as its contents are
|
|---|
| 14 | // used during the conversion algorithm.
|
|---|
| 15 | const converter = v8toIstanbul('./path-to-instrumented-file.js')
|
|---|
| 16 | await converter.load() // this is required due to the async source-map dependency.
|
|---|
| 17 | // provide an array of coverage information in v8 format.
|
|---|
| 18 | converter.applyCoverage([
|
|---|
| 19 | {
|
|---|
| 20 | "functionName": "",
|
|---|
| 21 | "ranges": [
|
|---|
| 22 | {
|
|---|
| 23 | "startOffset": 0,
|
|---|
| 24 | "endOffset": 520,
|
|---|
| 25 | "count": 1
|
|---|
| 26 | }
|
|---|
| 27 | ],
|
|---|
| 28 | "isBlockCoverage": true
|
|---|
| 29 | },
|
|---|
| 30 | // ...
|
|---|
| 31 | ])
|
|---|
| 32 | // output coverage information in a form that can
|
|---|
| 33 | // be consumed by Istanbul.
|
|---|
| 34 | console.info(JSON.stringify(converter.toIstanbul()))
|
|---|
| 35 |
|
|---|
| 36 | // cleanup resources allocated in "load" (i.e. by the source-map dependency),
|
|---|
| 37 | // the converter may not be used anymore afterwards
|
|---|
| 38 | converter.destroy()
|
|---|
| 39 | ```
|
|---|
| 40 |
|
|---|
| 41 | ## Ignoring Uncovered Lines
|
|---|
| 42 |
|
|---|
| 43 | Sometimes you might find yourself wanting to ignore uncovered lines
|
|---|
| 44 | in your application (for example, perhaps you run your tests in Linux, but
|
|---|
| 45 | there's code that only executes on Windows).
|
|---|
| 46 |
|
|---|
| 47 | To ignore lines, use the special comment `/* c8 ignore next */`.
|
|---|
| 48 |
|
|---|
| 49 | ### ignoring the next line
|
|---|
| 50 |
|
|---|
| 51 | ```js
|
|---|
| 52 | const myVariable = 99
|
|---|
| 53 | /* c8 ignore next */
|
|---|
| 54 | if (process.platform === 'win32') console.info('hello world')
|
|---|
| 55 | ```
|
|---|
| 56 |
|
|---|
| 57 | ### ignoring the next N lines
|
|---|
| 58 |
|
|---|
| 59 | ```js
|
|---|
| 60 | const myVariable = 99
|
|---|
| 61 | /* c8 ignore next 3 */
|
|---|
| 62 | if (process.platform === 'win32') {
|
|---|
| 63 | console.info('hello world')
|
|---|
| 64 | }
|
|---|
| 65 | ```
|
|---|
| 66 |
|
|---|
| 67 | ### ignoring all lines until told
|
|---|
| 68 |
|
|---|
| 69 | ```js
|
|---|
| 70 | /* c8 ignore start */
|
|---|
| 71 | function dontMindMe() {
|
|---|
| 72 | // ...
|
|---|
| 73 | }
|
|---|
| 74 | /* c8 ignore stop */
|
|---|
| 75 | ```
|
|---|
| 76 |
|
|---|
| 77 | ### ignoring the same line as the comment
|
|---|
| 78 |
|
|---|
| 79 | ```js
|
|---|
| 80 | const myVariable = 99
|
|---|
| 81 | const os = process.platform === 'darwin' ? 'OSXy' /* c8 ignore next */ : 'Windowsy'
|
|---|
| 82 | ```
|
|---|
| 83 |
|
|---|
| 84 | ## Testing
|
|---|
| 85 |
|
|---|
| 86 | To execute tests, simply run:
|
|---|
| 87 |
|
|---|
| 88 | ```bash
|
|---|
| 89 | npm test
|
|---|
| 90 | ```
|
|---|