diff --git a/lib/puppeteer-to-istanbul.js b/lib/puppeteer-to-istanbul.js index 3d350c8..f8471b0 100644 --- a/lib/puppeteer-to-istanbul.js +++ b/lib/puppeteer-to-istanbul.js @@ -16,7 +16,14 @@ class PuppeteerToIstanbul { } writeIstanbulFormat () { - var fullJson = {} + mkdirp.sync('./.nyc_output') + + const outFilePath = './.nyc_output/out.json' + + fs.writeFileSync(outFilePath, '') + + const fd = fs.openSync(outFilePath, 'a') + fs.writeSync(fd, '{') this.puppeteerToV8Info.forEach(jsFile => { const script = v8toIstanbul(jsFile.url) @@ -25,12 +32,18 @@ class PuppeteerToIstanbul { let istanbulCoverage = script.toIstanbul() let keys = Object.keys(istanbulCoverage) - fullJson[keys[0]] = istanbulCoverage[keys[0]] - fullJson[keys[0]].originalUrl = jsFile.originalUrl + let jsonPart = {} + jsonPart[keys[0]] = istanbulCoverage[keys[0]] + jsonPart[keys[0]].originalUrl = jsFile.originalUrl + + let jsonStr = JSON.stringify(jsonPart) + .replace(/^{/, '') + .replace(/}$/, '') + fs.writeSync(fd, jsonStr) }) - mkdirp.sync('./.nyc_output') - fs.writeFileSync('./.nyc_output/out.json', JSON.stringify(fullJson), 'utf8') + fs.writeSync(fd, '}') + fs.closeSync(fd) } }