Skip to content

fix: fix re-mocking virtual module#9748

Merged
sheremet-va merged 5 commits intovitest-dev:mainfrom
hi-ogawa:02-26-test_add_reproduction_for_https__github.com_vitest-dev_vitest_issues_9742
Feb 26, 2026
Merged

fix: fix re-mocking virtual module#9748
sheremet-va merged 5 commits intovitest-dev:mainfrom
hi-ogawa:02-26-test_add_reproduction_for_https__github.com_vitest-dev_vitest_issues_9742

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Feb 26, 2026

Description

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
Copy link

netlify bot commented Feb 26, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 52d07fe
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/699fcab22291450008f6855a
😎 Deploy Preview https://deploy-preview-9748--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

id,
url: id,
id: resolvedMock.id,
url: resolvedMock.url,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the case of virtual module, here we previously had id = /@id/virtual-module (aka "url") as module runner fetchModule result, which then leaded to evaluatedModuleNode.id = mock:/@id/virtual-module during later mock interception.

However, when invalidating mock for next doMock calls, we use resolveId of virtual-module and it tries to invalidate mock:virtual-module. This inconsistency makes invalidation to miss.

What this resolvedMock case should do instead is to return id as resolvedId of mocked module, which is already available as resolvedMock.id, so that is the solution here.

@hi-ogawa hi-ogawa marked this pull request as ready for review February 26, 2026 05:23
@sheremet-va sheremet-va merged commit 3cbbb17 into vitest-dev:main Feb 26, 2026
14 of 16 checks passed
@hi-ogawa hi-ogawa deleted the 02-26-test_add_reproduction_for_https__github.com_vitest-dev_vitest_issues_9742 branch February 26, 2026 09:18
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.

Virtual module mocking issue in Vitest 4

2 participants