Skip to content

Commit 3a5b312

Browse files
authored
feat: allow the output file to not include the hostname (#57)
1 parent eb1aabc commit 3a5b312

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Convert coverage from the format outputted by [puppeteer](https://developers.goo
3333
page.coverage.stopJSCoverage(),
3434
page.coverage.stopCSSCoverage(),
3535
]);
36-
pti.write([...jsCoverage, ...cssCoverage], { storagePath: './.nyc_output' })
36+
pti.write([...jsCoverage, ...cssCoverage], { includeHostname: true , storagePath: './.nyc_output' })
3737
await browser.close()
3838
})()
3939
```

lib/output-files.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let iterator = {}
1414
class OutputFiles {
1515
constructor (coverageInfo, options = {}) {
1616
this.storagePath = options.storagePath || './.nyc_output/js'
17+
this.includeHostname = options.hasOwnProperty('includeHostname') ? options.includeHostname : true
1718

1819
// Clone coverageInfo to prevent mutating the passed in data
1920
this.coverageInfo = clone(coverageInfo)
@@ -32,7 +33,7 @@ class OutputFiles {
3233

3334
let postProtocolPath = urlPath.pathname.substring(1)
3435

35-
if (urlPath.hostname) {
36+
if (urlPath.hostname && this.includeHostname) {
3637
let hostnameAndPort = urlPath.hostname
3738
if (urlPath.port) {
3839
hostnameAndPort = hostnameAndPort + '_' + urlPath.port

lib/puppeteer-to-istanbul.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let jsonPart = {}
99
class PuppeteerToIstanbul {
1010
constructor (coverageInfo, options = {}) {
1111
this.storagePath = options.storagePath || './.nyc_output'
12+
this.includeHostname = options.hasOwnProperty('includeHostname') ? options.includeHostname : true
1213

1314
this.coverageInfo = coverageInfo
1415
this.options = options

test/output-files.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ describe('output-files', () => {
7979
coverageInfo[3].url.should.include('js/views/record.js')
8080
})
8181

82+
it('appropriately handles modules required via http/https, with hostName excluded', () => {
83+
const fixture = require('./fixtures/http-es6-modules.json')
84+
const coverageInfo = OutputFiles(fixture, { includeHostname: false }).getTransformedCoverage().map(info => ({...info, url: info.url.replace(/\\/g, '/')}))
85+
86+
coverageInfo[0].url.should.include('js/index.js')
87+
coverageInfo[1].url.should.include('js/utils/doc_ready.js')
88+
coverageInfo[2].url.should.include('js/models/record.js')
89+
coverageInfo[3].url.should.include('js/views/record.js')
90+
})
91+
8292
it('maintains original url in output', () => {
8393
const fixture = require('./fixtures/http-es6-modules.json')
8494
const coverageInfo = OutputFiles(fixture).getTransformedCoverage()

0 commit comments

Comments
 (0)