vitest
vitest copied to clipboard
fix: extraneous coverage for --project (fix #6331)
Description
Coverage was reported for projects outside of the specified project filter. For example, given a monorepo with two projects, p1 and p2, vitest run --coverage --project=p1 reported coverage for code from p2 at 0% because no tests from p2 were run.
Resolves: #6331
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
- [ ] Ideally, include a test that fails without this PR but passes with it.
- [x] Please, don't make changes to
pnpm-lock.yamlunless you introduce a new test example.
Tests
- [x] Run the tests with
pnpm test:ci.
Documentation
- [x] If you introduce new functionality, document it. You can run documentation with
pnpm run docscommand.
Changesets
- [x] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with
feat:,fix:,perf:,docs:, orchore:.
@AriPerkkio Does this align with what you were thinking? I still need to familiarize myself with how the tests are written, but I wanted to ensure I was on the right track first.
Also, should I move the duplicate code to a common location (like BaseCoverageProvider)?
Deploy Preview for vitest-dev ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | 11107dc73eb970e6fac75130722a96237c418e83 |
| Latest deploy log | https://app.netlify.com/projects/vitest-dev/deploys/685c29ca9f575b0008d296bc |
| Deploy Preview | https://deploy-preview-7885--vitest-dev.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
That should do it. It seems to work for my project. I will add tests when I figure that out 🙂
As an aside, I wasn't able to move the duplicate code to BaseCoverageProvider because vitest/node doesn't reference test-exclude. I figured it wasn't worth adding the extra reference for this fix.
Hey @gtbuchanan, do you have any time to finalize this PR? I'm also happy to take over and finish it if you prefer that. Thanks for all the work so far! 💯
@AriPerkkio I would have liked to finish it myself, but I'm running into some issues:
- I figured out how to write the tests, but the one testing my fix is actually failing. I'm trying to debug the coverage test in VS Code using these steps, but clicking "Run and Debug" immediately stops debugging. Do you have any tips? Is there a specific file I'm supposed to have open?
- ~Obviously, my branch is now outdated. Out of curiosity, I added my unit tests on top of
mainto make sure one would fail, but they actually passed. I'm assuming my test is just wrong sincemaindoesn't appear to have a fix for this. Will you glance at my tests to see if something stands out?~
EDIT: Disregard 2. There must have been some caching involved. I picked the PR back up on my work computer and the test fails there as expected. Now to reapply the fix...
I didn't figure out how to debug the coverage tests in VS Code, but I was able to get everything working! It seems to work without updating isIncluded, but let me know if I'm missing something.