-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: switch to using Node's built in coverage #22
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
const Exclude = require('test-exclude') | ||
const libCoverage = require('istanbul-lib-coverage') | ||
const libReport = require('istanbul-lib-report') | ||
const reports = require('istanbul-reports') | ||
const {readdirSync, readFileSync} = require('fs') | ||
const {resolve} = require('path') | ||
const { readdirSync, readFileSync } = require('fs') | ||
const { resolve } = require('path') | ||
const v8CoverageMerge = require('v8-coverage-merge') | ||
const v8toIstanbul = require('v8-to-istanbul') | ||
|
||
class Report { | ||
constructor ({reporter, coverageDirectory, watermarks}) { | ||
constructor ({ | ||
exclude, | ||
include, | ||
reporter, | ||
coverageDirectory, | ||
watermarks, | ||
resolve | ||
}) { | ||
this.reporter = reporter | ||
this.coverageDirectory = coverageDirectory | ||
this.watermarks = watermarks | ||
this.resolve = resolve | ||
this.exclude = Exclude({ | ||
exclude: exclude, | ||
include: include | ||
}) | ||
} | ||
run () { | ||
const map = this._getCoverageMapFromAllCoverageFiles() | ||
|
@@ -25,9 +40,34 @@ class Report { | |
} | ||
_getCoverageMapFromAllCoverageFiles () { | ||
const map = libCoverage.createCoverageMap({}) | ||
const mergedResults = {} | ||
this._loadReports().forEach((report) => { | ||
report.result.forEach((result) => { | ||
if (this.exclude.shouldInstrument(result.url)) { | ||
if (mergedResults[result.url]) { | ||
mergedResults[result.url] = v8CoverageMerge( | ||
mergedResults[result.url], | ||
result | ||
) | ||
} else { | ||
mergedResults[result.url] = result | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
this._loadReports().forEach(function (report) { | ||
map.merge(report) | ||
Object.keys(mergedResults).forEach((url) => { | ||
const result = mergedResults[url] | ||
// console.info(JSON.stringify(result, null, 2)) | ||
try { | ||
const path = resolve(this.resolve, result.url) | ||
const script = v8toIstanbul(path) | ||
script.applyCoverage(result.functions) | ||
map.merge(script.toIstanbul()) | ||
} catch (err) { | ||
// most likely this was an internal Node.js library. | ||
if (err.code !== 'ENOENT' && err.code !== 'EISDIR') throw err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TimothyGu any thoughts about how to easily tell whether the coverage outputted was for one of Node.js' built in libraries, e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about checking whether the URL was an absolute path or not? |
||
} | ||
}) | ||
|
||
return map | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be required for the Node.js codebase itself.