Skip to content

Commit

Permalink
fix: exclude CJS-MJS coverages from results
Browse files Browse the repository at this point in the history
fix #14
  • Loading branch information
shinnn committed Apr 28, 2019
1 parent 51a9fa7 commit ab23cb1
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 10 deletions.
15 changes: 13 additions & 2 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,19 @@ class Report {
try {
const path = resolve(this.resolve, v8ScriptCov.url)
const script = v8toIstanbul(path, this.wrapperLength)
script.applyCoverage(v8ScriptCov.functions)
map.merge(script.toIstanbul())

if (v8ScriptCov.functions.every(({ ranges }) => {
for (const { endOffset } of ranges) {
if (endOffset > script.source.length) {
return false
}
}

return true
})) {
script.applyCoverage(v8ScriptCov.functions)
map.merge(script.toIstanbul())
}
} catch (err) {
console.warn(`file: ${v8ScriptCov.url} error: ${err.stack}`)
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"rimraf": "^2.6.2",
"test-exclude": "^5.0.0",
"uuid": "^3.3.2",
"v8-to-istanbul": "^2.0.4",
"v8-to-istanbul": "^2.1.0",
"yargs": "^13.1.0",
"yargs-parser": "^10.1.0"
},
Expand Down
354 changes: 354 additions & 0 deletions test/fixtures/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,354 @@
module.exports = function foo() {
/* This file contains a lot of lines to test if `endOffset` of the CJS-ESM bridge is always larger than the EOF position.
*/
return 'foo'
}
Loading

0 comments on commit ab23cb1

Please sign in to comment.