-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Istanbul Coverage + Svelte: Incorrectly Identifying an If / Else Block #1893
Comments
I don't think there is anything we can do on Vitest's codebase. Changes in Svelte compiler could fix this. Looking at @kgladfelder's repro we can see that Svelte compiler is adding helper-functions which end up getting instrumented. I think these helper functions are included in source maps so that debugging tools can stop on breakpoints. But when instrumenting code, we end up collecting coverage from these unnecessary if-blocks. When the transpiled code is mapped back to sources, we can see covered and uncovered lines on unexpected lines+columns. This is why Look at these lines+columns in sources: 12 | <span>{result.gameName}</span>
^^^^^ In the transpiled code those map into this single character here: 225 | if (dirty & /*searchResults*/ 1 && t0$_value$ !== (t0$_value$ = /*result*/ ctx[2].gameName + "")) set_data_dev$(t0$, t0$_value$);
^ Now looking at the instrumented transpiled code. A branch counter is added here. When code is executed it is never reached. 4980 | if ((cov_1a56qtdo1c().b[7][0]++, dirty &
4981 | /*searchResults*/
4982 | 1) && (cov_1a56qtdo1c().b[7][1]++, t0$_value$ !== (t0$_value$ =
4983 | /*result*/
4984 | ctx[2].gameName + ""))) {
4985 | cov_1a56qtdo1c().b[6][0]++;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Branch counter!
4986 | cov_1a56qtdo1c().s[92]++;
4987 | set_data_dev$(t0$, t0$_value$);
4988 | } else { In the same repro repo there are also some 100% correctly working source maps. Here is one example: 16 | {#if !searched}
^^^^^^^^
17 | <h6>Please search for a game.</h6>
18 | {:else} 44 | if (!/*searched*/ ctx[1]) return create_if_block$;
^^^ 4672 | if (!
4673 | /*searched*/
4674 | ctx[1]) {
4675 | cov_1a56qtdo1c().b[0][0]++;
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Branch counter!
4676 | cov_1a56qtdo1c().s[6]++;
4677 | return create_if_block$;
4678 | } else { I'm 99% sure I've seen some code transformer tool adding A possible solution here would be if Svelte compiler excluded its helper functions from instrumenters. |
Upstream issue open sveltejs/svelte#7824. |
This is fixed on Svelte 5. |
Describe the bug
In a svelte.kit application, while outputting data in an each block, any time the iterator is accessed, Istanbul is reporting that I never go into an
if
block that doesn't exist. Also, in the coverage report it shows line 97 as partially covered and the HTML shows it as fully covered.Reproduction
https://github.com/kgladfelder/vitest-issue-repro
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: