File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
packages/test-runner-coverage-v8/src Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @web/test-runner-coverage-v8 ' : patch
3
+ ---
4
+
5
+ fix: reset coverage result converters between Chrome session runs
Original file line number Diff line number Diff line change @@ -85,7 +85,20 @@ export async function v8ToIstanbul(
85
85
if ( ! cachedConverter ) {
86
86
await converter . load ( ) ;
87
87
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
+ }
89
102
90
103
converter . applyCoverage ( entry . functions ) ;
91
104
Object . assign ( istanbulCoverage , converter . toIstanbul ( ) ) ;
You can’t perform that action at this time.
0 commit comments