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 e0f4a0e
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 16 deletions.
19 changes: 17 additions & 2 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,23 @@ 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(({ functionName, ranges }) => {
if (!script.source.includes(functionName)) {
return false
}

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
Loading

0 comments on commit e0f4a0e

Please sign in to comment.