Skip to content

Commit e7f8cf2

Browse files
demurgosbcoe
authored andcommitted
fix: file URL to system path conversion (#46)
This commit fixes the conversion from `file://` urls to system-dependent paths. It ensures that it works on Windows and with special characters.
1 parent a22c4e0 commit e7f8cf2

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

lib/report.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Exclude = require('test-exclude')
2+
const furi = require('furi')
23
const libCoverage = require('istanbul-lib-coverage')
34
const libReport = require('istanbul-lib-report')
45
const reports = require('istanbul-reports')
@@ -74,7 +75,7 @@ class Report {
7475
_getMergedProcessCov () {
7576
const v8ProcessCovs = []
7677
for (const v8ProcessCov of this._loadReports()) {
77-
v8ProcessCovs.push(this._filterProcessCov(v8ProcessCov))
78+
v8ProcessCovs.push(this._normalizeProcessCov(v8ProcessCov))
7879
}
7980
return mergeProcessCovs(v8ProcessCovs)
8081
}
@@ -101,21 +102,26 @@ class Report {
101102
}
102103

103104
/**
104-
* Returns a filtered process coverage.
105+
* Normalizes a process coverage.
106+
*
107+
* This function replaces file URLs (`url` property) by their corresponding
108+
* system-dependent path and applies the current inclusion rules to filter out
109+
* the excluded script coverages.
105110
*
106111
* The result is a copy of the input, with script coverages filtered based
107112
* on their `url` and the current inclusion rules.
108113
* There is no deep cloning.
109114
*
110-
* @param v8ProcessCov V8 process coverage to filter.
111-
* @return {v8ProcessCov} Filtered V8 process coverage.
115+
* @param v8ProcessCov V8 process coverage to normalize.
116+
* @return {v8ProcessCov} Normalized V8 process coverage.
112117
* @private
113118
*/
114-
_filterProcessCov (v8ProcessCov) {
119+
_normalizeProcessCov (v8ProcessCov) {
115120
const result = []
116121
for (const v8ScriptCov of v8ProcessCov.result) {
117-
// TODO: implement real fix from https://github.com/nodejs/node/issues/23783
118-
v8ScriptCov.url = v8ScriptCov.url.replace(/^file:\/\//, '')
122+
if (/^file:\/\//.test(v8ScriptCov.url)) {
123+
v8ScriptCov.url = furi.toSysPath(v8ScriptCov.url)
124+
}
119125
if (this.exclude.shouldInstrument(v8ScriptCov.url) &&
120126
(!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
121127
result.push(v8ScriptCov)

package-lock.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@c88/v8-coverage": "^0.1.0",
3636
"find-up": "^3.0.0",
3737
"foreground-child": "^1.5.6",
38+
"furi": "^1.0.0",
3839
"istanbul-lib-coverage": "^2.0.1",
3940
"istanbul-lib-report": "^2.0.1",
4041
"istanbul-reports": "^2.0.0",

0 commit comments

Comments
 (0)