Skip to content

Commit

Permalink
fix: write to disk incrementally (#40)
Browse files Browse the repository at this point in the history
@SanterreJo thank you for the contribution 👍 I'll make an effort to get a release out soon, if I get buried in other work, please feel free to contact me here:

http://devtoolscommunity.herokuapp.com/
  • Loading branch information
SanterreJo authored and bcoe committed Nov 4, 2019
1 parent dec48a2 commit c57bd74
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/puppeteer-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit c57bd74

Please sign in to comment.