Skip to content

fix mock type isolation between test files#10758

Draft
Minghan2005 wants to merge 2 commits into
vitest-dev:mainfrom
Minghan2005:codex/fix-mock-registry-isolation
Draft

fix mock type isolation between test files#10758
Minghan2005 wants to merge 2 commits into
vitest-dev:mainfrom
Minghan2005:codex/fix-mock-registry-isolation

Conversation

@Minghan2005

Copy link
Copy Markdown

Fixes #10290.

When isolate: false reuses a module runner, an evaluated module can retain the mockedModule stored in its metadata from an earlier test file. A later file may register a different mock type for the same module, but the runner previously used the cached metadata as long as any active mock existed. This allowed the earlier manual factory to leak into a later automock.

This change resolves the active mock from the current test file's registry before dispatching. Cached metadata is still used to detect redirect self-imports, while removed mocks continue to fall back to the original module.

The regression test runs two ordered files in one non-isolated worker: the first registers a manual factory and the second registers an automock for the same module.

Checks:

  • CI=true pnpm test test/mock-isolation.test.ts --run in test/e2e
  • related mocking tests in both threads and forks projects (26 tests)
  • pnpm lint:fix
  • pnpm typecheck

@github-actions github-actions Bot added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Jul 11, 2026
@github-actions

Copy link
Copy Markdown

Hello @Minghan2005. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Confirm you've read, reviewed and stand behind its content
  • Confirm you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

1 similar comment
@github-actions

Copy link
Copy Markdown

Hello @Minghan2005. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Confirm you've read, reviewed and stand behind its content
  • Confirm you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

@netlify

netlify Bot commented Jul 11, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cdbf1be
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a52c3130eb8e000082de632
😎 Deploy Preview https://deploy-preview-10758--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.

@Minghan2005

Copy link
Copy Markdown
Author

Yes, I am a real human being. I have read and understand the context, and I read the full issues and commets I will follow the rules, I will respond to them, and I am willing to give feedback. My AI tool is Codex.I am a fresh man, if you have any problems, please tell me

@Minghan2005

Copy link
Copy Markdown
Author

Could you pass it

@Minghan2005 Minghan2005 force-pushed the codex/fix-mock-registry-isolation branch from bf664a2 to d66a5f4 Compare July 13, 2026 18:21
@Minghan2005

Copy link
Copy Markdown
Author

CI follow-up: the current head (d66a5f431) has three failures that appear flaky rather than caused by this diff:

  • Browsers: shard 2/2 expected port 51122, but Vite selected 51123 because the fixed port was unavailable.
  • Ubuntu E2E failed the existing playwright virtual-mock test; that exact node + playwright case passes in 10/10 repeated local runs on this head, and the job passed on the previous run.
  • Windows E2E timed out waiting for JUNIT report written; the same job passed on the previous run.

The originally failing Windows E2E scenario also passed on the next run. I cannot rerun individual upstream Actions jobs because GitHub requires repository admin permission. Could a maintainer please rerun these three failed jobs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module mocking regression from Vitest 3 to Vitest 4

1 participant