Skip to content

Commit

Permalink
fix: file URL to system path conversion (#46)
Browse files Browse the repository at this point in the history
This commit fixes the conversion from `file://` urls to system-dependent paths. It ensures that it works on Windows and with special characters.
  • Loading branch information
demurgos authored and bcoe committed Dec 23, 2018
1 parent a22c4e0 commit e7f8cf2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/report.js
@@ -1,4 +1,5 @@
const Exclude = require('test-exclude')
const furi = require('furi')
const libCoverage = require('istanbul-lib-coverage')
const libReport = require('istanbul-lib-report')
const reports = require('istanbul-reports')
Expand Down Expand Up @@ -74,7 +75,7 @@ class Report {
_getMergedProcessCov () {
const v8ProcessCovs = []
for (const v8ProcessCov of this._loadReports()) {
v8ProcessCovs.push(this._filterProcessCov(v8ProcessCov))
v8ProcessCovs.push(this._normalizeProcessCov(v8ProcessCov))
}
return mergeProcessCovs(v8ProcessCovs)
}
Expand All @@ -101,21 +102,26 @@ class Report {
}

/**
* Returns a filtered process coverage.
* Normalizes a process coverage.
*
* This function replaces file URLs (`url` property) by their corresponding
* system-dependent path and applies the current inclusion rules to filter out
* the excluded script coverages.
*
* The result is a copy of the input, with script coverages filtered based
* on their `url` and the current inclusion rules.
* There is no deep cloning.
*
* @param v8ProcessCov V8 process coverage to filter.
* @return {v8ProcessCov} Filtered V8 process coverage.
* @param v8ProcessCov V8 process coverage to normalize.
* @return {v8ProcessCov} Normalized V8 process coverage.
* @private
*/
_filterProcessCov (v8ProcessCov) {
_normalizeProcessCov (v8ProcessCov) {
const result = []
for (const v8ScriptCov of v8ProcessCov.result) {
// TODO: implement real fix from https://github.com/nodejs/node/issues/23783
v8ScriptCov.url = v8ScriptCov.url.replace(/^file:\/\//, '')
if (/^file:\/\//.test(v8ScriptCov.url)) {
v8ScriptCov.url = furi.toSysPath(v8ScriptCov.url)
}
if (this.exclude.shouldInstrument(v8ScriptCov.url) &&
(!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
result.push(v8ScriptCov)
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -35,6 +35,7 @@
"@c88/v8-coverage": "^0.1.0",
"find-up": "^3.0.0",
"foreground-child": "^1.5.6",
"furi": "^1.0.0",
"istanbul-lib-coverage": "^2.0.1",
"istanbul-lib-report": "^2.0.1",
"istanbul-reports": "^2.0.0",
Expand Down

0 comments on commit e7f8cf2

Please sign in to comment.