fix: collect in-source tests when the module is cached (fix #10577)#10589
Open
koutaro-masaki wants to merge 3 commits into
Open
fix: collect in-source tests when the module is cached (fix #10577)#10589koutaro-masaki wants to merge 3 commits into
koutaro-masaki wants to merge 3 commits into
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. |
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
9e30bef to
143608f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:.