Skip to content

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

Open
koutaro-masaki wants to merge 3 commits into
vitest-dev:mainfrom
koutaro-masaki:fix/collect-insource-tests
Open

fix: collect in-source tests when the module is cached (fix #10577)#10589
koutaro-masaki wants to merge 3 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.

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

1 participant