vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Wrong coverage for svelte components

Open jerrythomas opened this issue 3 years ago • 1 comments
trafficstars

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

jerrythomas avatar Jun 04 '22 00:06 jerrythomas

The coverage seems correct with the new provider: 'istanbul' option. Does this work for you @jerrythomas?

C8:

Istanbul:

AriPerkkio avatar Aug 18 '22 13:08 AriPerkkio

Maybe related: https://github.com/rspieker/jest-transform-svelte/issues/16

matpen avatar Jan 18 '23 15:01 matpen

The coverage seems correct with the new provider: 'istanbul' option. Does this work for you @jerrythomas?

C8:

Istanbul:

Thanks. This looks good.

jerrythomas avatar Feb 22 '23 03:02 jerrythomas

istanbul coverage shows better coverage for svelte.

jerrythomas avatar Feb 22 '23 03:02 jerrythomas