Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubts about the v8-to-istanbul parameter #250

Open
zhangtao25 opened this issue Jun 11, 2024 · 0 comments
Open

Doubts about the v8-to-istanbul parameter #250

zhangtao25 opened this issue Jun 11, 2024 · 0 comments

Comments

@zhangtao25
Copy link

zhangtao25 commented Jun 11, 2024

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()))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant