Skip to content

fix: collect in-source tests when the module is cached (fix #10577) - #10589

Merged
sheremet-va merged 4 commits into
vitest-dev:mainfrom
koutaro-masaki:fix/collect-insource-tests
Jul 29, 2026
Merged

fix: collect in-source tests when the module is cached (fix #10577)#10589
sheremet-va merged 4 commits into
vitest-dev:mainfrom
koutaro-masaki:fix/collect-insource-tests

Conversation

@koutaro-masaki

Copy link
Copy Markdown
Contributor

Description

When in-source testing is used with both isolate: false and maxWorkers: 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:

  • 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.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • 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:, or chore:.

@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4c0f1dd
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a33d195ef7b09000886873c
😎 Deploy Preview https://deploy-preview-10589--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@koutaro-masaki
koutaro-masaki force-pushed the fix/collect-insource-tests branch from 9e30bef to 143608f Compare June 12, 2026 19:50
@koutaro-masaki
koutaro-masaki marked this pull request as ready for review June 12, 2026 20:12

@sheremet-va sheremet-va left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@koutaro-masaki
koutaro-masaki force-pushed the fix/collect-insource-tests branch from 4c0f1dd to cbfa55f Compare July 14, 2026 18:18
@koutaro-masaki

Copy link
Copy Markdown
Contributor Author

I added a repro test and confirmed that the previous fix breaks plugins that check the file extension (like the vue plugin).
I should have invalidated the module cache from the start, like source === 'setup' already does. The fix now does that instead of appending the ?vitest query.

@sheremet-va
sheremet-va merged commit a7bf2b2 into vitest-dev:main Jul 29, 2026
25 of 27 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some in-source tests are not detected when isolate: false and maxWorkers: 1 are set

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo