-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
When using coverage.all
typescript files with no executable code are colored red in the coverage report
#3605
Comments
Which file is covering it? When I add
Is that with Jest's |
This import exists in import { Pet } from '../utils/server-data-model'; if I change it to: import '../utils/server-data-model'; the file is reported as covered. Yes - the jest setup was using the default provider. I changed my vitest setup's provider to |
I don't wish to open another issue for which seems to be the same issue, so here the thing. I'm trying to incorporate Here is repro:
Expected behavior: export type ResponseType = string
export type ResponseCode = number I expect it to not be tested for coverage or 100% covered. Actual behavior: Vitest reports it as not covered with tests: Is it expected behavior? |
@Kolobamanacas either remove This file is picked due to |
@Kolobamanacas try and |
@HristoKolev Just checked, unfortunately it didn't help. @AriPerkkio So it's a feature then. ) Ok, thank you. I'll stick to excluding all types files in config. |
## PR Checklist - [x] Addresses an existing open issue: fixes #692 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Skips using istanbul, in favor of v8. I'm hoping using the same coverage report format will help Codecov figure things out. Note that this now triggers vitest-dev/vitest#3605 issue of v8 counting types as untested.
Ehh, this really doesn't feel like a feature IMO. If the file has no runtime code (other than CJS Example file that just contains an Request: can we please consider this a bug rather than a feature? |
When using V8 coverage in Jest, is it really able to detect whether file contains only types? By default Jest uses Istanbul instrumented code coverage which is identical with Vitest's |
Tested with Similar issues:
Root cause is described here: #3605 (comment) |
Sorry for the delay in responding - but yes, +1 to the last comment. I have a standalone repro at https://github.com/JoshuaKGoldberg/repros/tree/v8-types-coverage-jest-vs-vitest.
|
@JoshuaKGoldberg your reproduction case is missing If you want Vitest to behave similarly in your reproduction, set |
D'oh! Thanks - updated the branch. Sorry for the noise. |
@AriPerkkio If you disable all, then uncovered pure interface files are ignored - but so are uncovered component files too which do not have a .spec file at all. Please reopen this issue! Typescript interfaces should very obviously not be covered by coverage as they are compiled away at runtime. This is the behaviour that any developer would expect, so this should be considered a bug. |
This issue is open. You can use As mentioned before here, in Vitest, Jest and I've been thinking about experimenting with introducing AST analysis to |
@AriPerkkio Sorry, my bad, I got confused by the big purple closed above my comment which was just a referenced other issue. It's good to see you are working on this, thank you! In general, Vitest has been a blessing for our project. |
In #5457 there are more improvements related to Typescript typings and code coverage. The v8 provider can now exclude non-runtime code from covered files as well. |
Describe the bug
I have a typescript file that only contains typescript interfaces. When I run vitest with coverage I get it reported as red (uncovered) even when the interfaces are referenced by other files that are covered by tests.
The way jest handles this situation is to not count these file as neither covered or uncovered but just empty and colored in gray:
Reproduction
Here is the github repo from the images:
https://github.com/HristoKolev/vite-workshop/tree/6549514d7940d642a51aebcfd049466c3cc25e7b
to run it:
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: