Description
Describe the problem
When transpiled Svelte code is instrumented with istanbul
, there are a lot of unrelated statements and branches in the coverage report. The source maps received from svelte/compiler
include mappings which I think are intended for debugging breakpoints. However when we instrument the transpiled svelte code with istanbul
, these unnecessary if-blocks and other statements end up getting instrumented. See vitest-dev/vitest#1893.
For inspecting sourcemaps of transpiled and instrumented svelte file, see https://gist.github.com/AriPerkkio/8399007031cb747b2811c07358b8daa2.
Here is one example where the file is completely covered by a test. However statements and branches are not 100%. We can see uncovered code highlighted in results.
The reason why there is an if-block in middle of <li>{user}</li>
is due to having an actual if-statement in transpiled code.
Those other red-highlighted blocks are marked as uncovered, as source map points to a helper function which is not executed.
Describe the proposed solution
If those source mappings are unnecessary, those could be just removed from the mappings. But as I think those are indeed used for debugging, those cannot be simply removed.
But svelte compiler could be placing hints from instrumenters. I'm 99% sure I've seen some code transformation tools placing /* istanbul ignore, c8 ignore */
comments around their internal helper functions. Could svelte do the same?
// This is the if-block from example above
p(ctx, dirty) {
/* istanbul ignore, c8 ignore */ // <---- This would be added by svelte
if (dirty & /*users*/ 1 && t_value !== (t_value = /*user*/ ctx[1] + "")) set_data(t, t_value);
},
Svelte is already adding some extra comments, e.g. variable names, in the transpiled code. Adding some more comments should not be an issue.
I have zero knowledge about svelte's internals so I'm not sure whether these cases can easily be identified.
Alternatives considered
I don't think any coverage tool is currently working perfectly for svelte.
Importance
nice to have