@web/test-runner-core
Advanced tools
Comparing version 0.6.2 to 0.6.3
# @web/test-runner-core | ||
## 0.6.3 | ||
### Patch Changes | ||
- a9603b5: fix merging v8 code coverage | ||
## 0.6.2 | ||
@@ -4,0 +10,0 @@ |
@@ -11,8 +11,66 @@ "use strict"; | ||
]; | ||
const locEquals = (a, b) => a.column === b.column && a.line === b.line; | ||
const rangeEquals = (a, b) => locEquals(a.start, b.start) && locEquals(a.end, b.end); | ||
function findBranchKey(branches, branch) { | ||
for (const [key, m] of Object.entries(branches)) { | ||
if (rangeEquals(m.loc, branch.loc)) { | ||
return key; | ||
} | ||
} | ||
} | ||
/** | ||
* Cross references coverage mapping data, looking for missing code branches | ||
* and adding empty entries for them if found. This is necessary because istanbul | ||
* expects code branch data to be equal for all coverage entries, while v8 only | ||
* outputs actual covered code branches. | ||
* | ||
* See https://github.com/istanbuljs/istanbuljs/issues/531 for more. | ||
* @param coverages | ||
*/ | ||
function addingMissingCoverageBranches(coverages) { | ||
const branchesPerFile = new Map(); | ||
// collect code branches from all code coverage entries | ||
for (const coverage of coverages) { | ||
for (const [filePath, fileCoverage] of Object.entries(coverage)) { | ||
let branches = branchesPerFile.get(filePath); | ||
if (!branches) { | ||
branches = {}; | ||
branchesPerFile.set(filePath, branches); | ||
} | ||
for (const branch of Object.values(fileCoverage.branchMap)) { | ||
if (findBranchKey(branches, branch) == null) { | ||
const key = Object.keys(branches).length; | ||
branches[key] = branch; | ||
} | ||
} | ||
} | ||
} | ||
// patch coverage entries to add missing code branches | ||
for (const coverage of coverages) { | ||
for (const [filePath, fileCoverage] of Object.entries(coverage)) { | ||
const branches = branchesPerFile.get(filePath); | ||
const originalBranches = fileCoverage.branchMap; | ||
const originalB = fileCoverage.b; | ||
fileCoverage.branchMap = branches; | ||
fileCoverage.b = {}; | ||
for (const [key, mapping] of Object.entries(branches)) { | ||
const originalKey = findBranchKey(originalBranches, mapping); | ||
if (originalKey != null) { | ||
fileCoverage.b[key] = originalB[originalKey]; | ||
} | ||
else { | ||
fileCoverage.b[key] = [0]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function getTestCoverage(sessions, config) { | ||
const coverageMap = istanbul_lib_coverage_1.createCoverageMap(); | ||
for (const session of sessions) { | ||
if (session.testCoverage) { | ||
coverageMap.merge(session.testCoverage); | ||
} | ||
const coverages = Array.from(sessions) | ||
.map(s => s.testCoverage) | ||
.filter(c => c); | ||
addingMissingCoverageBranches(coverages); | ||
for (const coverage of coverages) { | ||
coverageMap.merge(coverage); | ||
} | ||
@@ -19,0 +77,0 @@ const summary = coverageMap.getCoverageSummary().data; |
{ | ||
"name": "@web/test-runner-core", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67936
819