Skip to content

Doubts about the v8-to-istanbul parameter #250

@travzhang

Description

@travzhang

Why does the first parameter of v8-to-istanbul need to be a string, I see that you can just pass in sources.source.
https://github.com/istanbuljs/v8-to-istanbul/blob/master/lib/v8-to-istanbul.js#L48

const v8toIstanbul = require('v8-to-istanbul')
// the path to the original source-file is required, as its contents are
// used during the conversion algorithm.
const converter = v8toIstanbul('',undefined,{
    source:"function add(a:number,b:number){\n    return a+b\n}\n\nconsole.log(add(1,2))"
})
// await converter.load() // this is required due to async file reading.
// provide an array of coverage information in v8 format.

converter.load().then(res=>{
    converter.applyCoverage([
        {
            "functionName": "",
            "ranges": [
                {
                    "startOffset": 0,
                    "endOffset": 520,
                    "count": 1
                }
            ],
            "isBlockCoverage": true
        },
        // ...
    ])
// output coverage information in a form that can
// be consumed by Istanbul.
    console.info(JSON.stringify(converter.toIstanbul()))
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions