fix: collect in-source tests when the module is cached (fix #10577) - #10589
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
9e30bef to
143608f
Compare
sheremet-va
left a comment
There was a problem hiding this comment.
Hm, actually I am not sure how this is treated by plugins for non-ts/js files. If it is a .vue file, for example, does it recognize it? (It usually checks for .vue extension, but with a query it's harder) Or should we strip the query for transform, but keep it for cache? viteModuleRunner: false has its own handling for this (search for vitest= in the repo)
When `isolate: false` and `maxWorkers: 1` are set, a source file with in-source tests can already be in the worker's module cache when it is collected, so importing it has no side effect and no tests are found. Re-import it with a `?vitest` query to force re-evaluation. close vitest-dev#10577
4c0f1dd to
cbfa55f
Compare
|
I added a repro test and confirmed that the previous fix breaks plugins that check the file extension (like the vue plugin). |
Description
When in-source testing is used with both
isolate: falseandmaxWorkers: 1, files that were already imported by another test file fail with"No test suite found".This happens because tests are registered as a side effect of importing the file. With this configuration, all test files share the same worker's module cache, so files that are already imported are not re-evaluated during collection and no tests are registered.
This was a known problem in the mode that runs tests with Node.js's native loader (
viteModuleRunner: false), where a workaround is implemented in native.ts and nodejsWorkerLoader.ts in #9210, but it was not covered when running with the default Vite module runner.This PR applies the same workaround to the default Vite module runner.
Resolves #10577
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.