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()))
})
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