vitest
vitest copied to clipboard
Wrong coverage for svelte components
Describe the bug
The coverage report is incorrect when testing svelte components using vitest.
component
<script>
function handleClick(){
...
}
<div on:click={handleClick}>?</div>
</script>
test
const { container } = render(Click)
expect(container).toBeTruthy()
When running the coverage report it shows 100% coverage without any lines missing from the coverage. I expected the function handler to show up in "uncovered" lines.
When using fire event to ensure that the function is actually being tested, I see that the coverage is dropping and some lines with 'data-' attributes show up in the uncovered lines list.
Reproduction
The main branch of the repo below shows 100% coverage even when the event is not being tested
https://github.com/jerrythomas/repro-vitest-coverage
The develop branch, where the event handler is being tested shows uncovered lines for 'data-' attributes. https://github.com/jerrythomas/repro-vitest-coverage/tree/develop
System Info
System:
OS: macOS 12.4
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 80.86 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
Browsers:
Brave Browser: 102.1.39.111
Chrome: 102.0.5005.61
Firefox: 100.0
Safari: 15.5
npmPackages:
vite: ^2.9.9 => 2.9.9
vitest: ~0.12.10 => 0.12.10
Used Package Manager
pnpm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
The coverage seems correct with the new provider: 'istanbul' option. Does this work for you @jerrythomas?
C8:

Istanbul:

Maybe related: https://github.com/rspieker/jest-transform-svelte/issues/16
The coverage seems correct with the new
provider: 'istanbul'option. Does this work for you @jerrythomas?C8:
Istanbul:
Thanks. This looks good.
istanbul coverage shows better coverage for svelte.