Skip to content

Commit

Permalink
fix: JSON encode URL
Browse files Browse the repository at this point in the history
solves issue on Windows with backslash path separator
  • Loading branch information
larsthorup authored May 11, 2020
1 parent e1bde3f commit 8aa1c44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/puppeteer-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PuppeteerToIstanbul {
const data = jsonPart[url]
const isLastIteration = index === (keys.length - 1)

fs.writeSync(fd, `"${url}": ${JSON.stringify(data)}${(isLastIteration ? '' : ',')}`)
fs.writeSync(fd, `${JSON.stringify(url)}: ${JSON.stringify(data)}${(isLastIteration ? '' : ',')}`)
})
fs.writeSync(fd, '}')
fs.closeSync(fd)
Expand Down
3 changes: 2 additions & 1 deletion test/output-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('output-files', () => {
// Since block-else-not-covered was generated by the above line, this
// should make a new file with -1 appended to the name
var newPath = outputFiles.rewritePath('./sample_js/block-else-not-covered-1.js')
if (newPath.includes('\\')) newPath = newPath.replace(/\\/g, '/')
newPath.should.include(storagePath + '/sample_js/block-else-not-covered-1.js')
})

Expand Down Expand Up @@ -70,7 +71,7 @@ describe('output-files', () => {

it('appropriately handles modules required via http/https', () => {
const fixture = require('./fixtures/http-es6-modules.json')
const coverageInfo = OutputFiles(fixture).getTransformedCoverage()
const coverageInfo = OutputFiles(fixture).getTransformedCoverage().map(info => ({...info, url: info.url.replace(/\\/g, '/')}))

coverageInfo[0].url.should.include('js/index.js')
coverageInfo[1].url.should.include('js/utils/doc_ready.js')
Expand Down

0 comments on commit 8aa1c44

Please sign in to comment.