Skip to content

Commit 58b560a

Browse files
tmsnsWestbrook
authored andcommitted
fix: reset coverage result converters between Chrome session runs
1 parent 893320e commit 58b560a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.changeset/breezy-crabs-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/test-runner-coverage-v8': patch
3+
---
4+
5+
fix: reset coverage result converters between Chrome session runs

packages/test-runner-coverage-v8/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,20 @@ export async function v8ToIstanbul(
8585
if (!cachedConverter) {
8686
await converter.load();
8787
cachedConverters.set(filePath, converter);
88-
}
88+
} else {
89+
// When we reuse a cached converter, we need to reset it before using its `applyCoverage` function.
90+
// If we don't, the coverage results will be poisoned with the results of the previous uses.
91+
//
92+
// This "workaround" is resetting some internal variables of the `V8ToIstanbul` class: `branches` & `functions`.
93+
// This can break when newer versions of v8-to-istanbul are released. (variable renaming, more variables are used, ...)
94+
//
95+
// TODO: use a (stable) clone technique instead when available (`structuredClone` is available in node 17)
96+
//
97+
// @ts-ignore
98+
converter.branches = {};
99+
// @ts-ignore
100+
converter.functions = {};
101+
}
89102

90103
converter.applyCoverage(entry.functions);
91104
Object.assign(istanbulCoverage, converter.toIstanbul());

0 commit comments

Comments
 (0)