Skip to content

Commit

Permalink
fix(coverage): remove work-around for implicit else (#6014)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jul 2, 2024
1 parent d87bef9 commit 368c137
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 91 deletions.
2 changes: 1 addition & 1 deletion packages/coverage-istanbul/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"istanbul-lib-coverage": "^3.2.2",
"istanbul-lib-instrument": "^6.0.3",
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^5.0.5",
"istanbul-lib-source-maps": "^5.0.6",
"istanbul-reports": "^3.1.7",
"magicast": "^0.3.4",
"picocolors": "^1.0.1",
Expand Down
43 changes: 0 additions & 43 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ export class IstanbulCoverageProvider
}

async function transformCoverage(coverageMap: CoverageMap) {
includeImplicitElseBranches(coverageMap)

const sourceMapStore = libSourceMaps.createSourceMapStore()
return await sourceMapStore.transformCoverage(coverageMap)
}
Expand All @@ -429,44 +427,3 @@ async function transformCoverage(coverageMap: CoverageMap) {
function removeQueryParameters(filename: string) {
return filename.split('?')[0]
}

/**
* Work-around for #1887 and #2239 while waiting for https://github.com/istanbuljs/istanbuljs/pull/706
*
* Goes through all files in the coverage map and checks if branchMap's have
* if-statements with implicit else. When finds one, copies source location of
* the if-statement into the else statement.
*/
function includeImplicitElseBranches(coverageMap: CoverageMap) {
for (const file of coverageMap.files()) {
const fileCoverage = coverageMap.fileCoverageFor(file)

for (const branchMap of Object.values(fileCoverage.branchMap)) {
if (branchMap.type === 'if') {
const lastIndex = branchMap.locations.length - 1

if (lastIndex > 0) {
const elseLocation = branchMap.locations[lastIndex]

if (elseLocation && isEmptyCoverageRange(elseLocation)) {
const ifLocation = branchMap.locations[0]

elseLocation.start = { ...ifLocation.start }
elseLocation.end = { ...ifLocation.end }
}
}
}
}
}
}

function isEmptyCoverageRange(range: libCoverage.Range) {
return (
range.start === undefined
|| range.start.line === undefined
|| range.start.column === undefined
|| range.end === undefined
|| range.end.line === undefined
|| range.end.column === undefined
)
}
2 changes: 1 addition & 1 deletion packages/coverage-v8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"debug": "^4.3.5",
"istanbul-lib-coverage": "^3.2.2",
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^5.0.5",
"istanbul-lib-source-maps": "^5.0.6",
"istanbul-reports": "^3.1.7",
"magic-string": "^0.30.10",
"magicast": "^0.3.4",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,8 @@
}
},
{
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 5,
"column": 3
}
"start": {},
"end": {}
}
]
},
Expand Down Expand Up @@ -191,14 +185,8 @@
}
},
{
"start": {
"line": 10,
"column": 2
},
"end": {
"line": 13,
"column": 3
}
"start": {},
"end": {}
}
]
},
Expand Down Expand Up @@ -226,14 +214,8 @@
}
},
{
"start": {
"line": 15,
"column": 2
},
"end": {
"line": 18,
"column": 3
}
"start": {},
"end": {}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,8 @@
}
},
{
"start": {
"line": 33,
"column": 2
},
"end": {
"line": 36,
"column": null
}
"start": {},
"end": {}
}
]
},
Expand Down Expand Up @@ -473,14 +467,8 @@
}
},
{
"start": {
"line": 39,
"column": 2
},
"end": {
"line": 42,
"column": null
}
"start": {},
"end": {}
}
]
}
Expand Down

0 comments on commit 368c137

Please sign in to comment.