Skip to content
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

Unexpected istanbul code coverage #5438

Closed
6 tasks done
sagargurtu opened this issue Mar 26, 2024 · 3 comments
Closed
6 tasks done

Unexpected istanbul code coverage #5438

sagargurtu opened this issue Mar 26, 2024 · 3 comments

Comments

@sagargurtu
Copy link
Contributor

sagargurtu commented Mar 26, 2024

Describe the bug

For v1.4.0, istanbul shows exported string constants as not covered. This is a deviation from v0.34.6 where it correctly skips string constants in code coverage.

Is this an expected change in behavior? Or a bug?

Reproduction

See terminal for coverage results:

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (3) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/coverage-istanbul: 0.34.6 => 0.34.6 
    vite: ^5 => 5.2.6 
    vitest: 0.34.6 => 0.34.6

Used Package Manager

npm

Validations

@AriPerkkio
Copy link
Member

AriPerkkio commented Mar 27, 2024

In Vitest v1 we enabled coverage.all by default:

Add this option in your v0.34.6 and you should see the same results. Or disable it in the v1.4.0 reproduction.

@sagargurtu
Copy link
Contributor Author

I see. Thanks for the info! Will close this issue.

However, is it valid for coverage to be collected for an exported string constant (or an exported number or boolean)? Would the recommendation be to write a test that checks if the value is as expected 🤔? I just wanted to export a public constant from my package and it feels weird to write a test to check its value.

@AriPerkkio
Copy link
Member

However, is it valid for coverage to be collected for an exported string constant (or an exported number or boolean)?

Looks like Istanbul does add a statement counter there: https://evanw.github.io/source-map-visualization/#MTMzOQB....

You can use ignore hints or coverage.exclude for this. Personally I think I would add test case for the file that actually imports this file. Then it would become covered automatically.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants