Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve coverage normalization, for now cannot properly merge v8 and …
…istanbul coverage. See istanbuljs/v8-to-istanbul#144
- Loading branch information
Damien Maillard
committed
May 3, 2021
1 parent
b94be2a
commit 61a8fa6
Showing
10 changed files
with
93 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 9 additions & 15 deletions
24
src/internal/executing/coverage/composeIstanbulCoverages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { require } from "../../require.js" | ||
|
||
const { createFileCoverage } = require("istanbul-lib-coverage") | ||
const { createCoverageMap } = require("istanbul-lib-coverage") | ||
|
||
// https://github.com/istanbuljs/istanbuljs/blob/5405550c3868712b14fd8bfe0cbd6f2e7ac42279/packages/istanbul-lib-coverage/lib/coverage-map.js#L43 | ||
export const composeIstanbulCoverages = (...istanbulCoverages) => { | ||
const istanbulCoverageComposed = {} | ||
const istanbulCoverageMap = createCoverageMap() | ||
istanbulCoverages.forEach((istanbulCoverage) => { | ||
Object.keys(istanbulCoverage).forEach((filename) => { | ||
const fileCoverage = istanbulCoverage[filename] | ||
istanbulCoverageComposed[filename] = | ||
filename in istanbulCoverageComposed | ||
? merge(istanbulCoverageComposed[filename], fileCoverage) | ||
: fileCoverage | ||
}) | ||
istanbulCoverageMap.merge(istanbulCoverage) | ||
}) | ||
return istanbulCoverageComposed | ||
} | ||
|
||
const merge = (coverageA, coverageB) => { | ||
const fileCoverage = createFileCoverage(coverageA) | ||
fileCoverage.merge(coverageB) | ||
return fileCoverage.toJSON() | ||
const istanbulCoverageComposed = {} | ||
const coverageMap = istanbulCoverageMap.toJSON() | ||
Object.keys(coverageMap).forEach((key) => { | ||
istanbulCoverageComposed[key] = coverageMap[key].toJSON() | ||
}) | ||
return istanbulCoverageComposed | ||
} |
13 changes: 0 additions & 13 deletions
13
src/internal/executing/coverage/ensureRelativePathsInCoverage.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
src/internal/executing/coverage/makeIstanbulCoverageRelative.js
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/internal/executing/coverage/normalizeIstanbulCoverage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { urlToRelativeUrl, fileSystemPathToUrl, isFileSystemPath, resolveUrl } from "@jsenv/util" | ||
|
||
export const normalizeIstanbulCoverage = (istanbulCoverage, projectDirectoryUrl) => { | ||
const istanbulCoverageNormalized = {} | ||
|
||
Object.keys(istanbulCoverage).forEach((key) => { | ||
const fileCoverage = istanbulCoverage[key] | ||
const { path } = fileCoverage | ||
const url = isFileSystemPath(path) | ||
? fileSystemPathToUrl(path) | ||
: resolveUrl(path, projectDirectoryUrl) | ||
const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl) | ||
|
||
istanbulCoverageNormalized[`./${relativeUrl}`] = { | ||
...fileCoverage, | ||
path: `./${relativeUrl}`, | ||
} | ||
}) | ||
|
||
return istanbulCoverageNormalized | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
src/internal/executing/coverage/runtimeResultMapToCoverageMap.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters