Skip to content

fix(mocker): hoist vi.mock() for vite-plus/test imports [backport to v4]#10548

Merged
sheremet-va merged 2 commits into
vitest-dev:v4from
hi-ogawa:backport-10489-v4
Jun 9, 2026
Merged

fix(mocker): hoist vi.mock() for vite-plus/test imports [backport to v4]#10548
sheremet-va merged 2 commits into
vitest-dev:v4from
hi-ogawa:backport-10489-v4

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

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:.

`vite-plus` re-exports Vitest's mocking API as `vite-plus/test`. Recognize
that specifier as the hoisted module so `import { vi } from 'vite-plus/test'`
followed by `vi.mock(...)` is statically hoisted exactly like `vitest`,
instead of being left unhoisted (silent breakage / TDZ at runtime).

Recognition only — the injected import for files that use the API without
importing it is unchanged. This upstreams the pnpm patch vite-plus currently
ships to do the same thing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit f82f39a)
@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026

Copy link
Copy Markdown
@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@10548

@vitest/browser-playwright

npm i https://pkg.pr.new/@vitest/browser-playwright@10548

@vitest/browser-preview

npm i https://pkg.pr.new/@vitest/browser-preview@10548

@vitest/browser-webdriverio

npm i https://pkg.pr.new/@vitest/browser-webdriverio@10548

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@10548

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@10548

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@10548

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@10548

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@10548

@vitest/runner

npm i https://pkg.pr.new/@vitest/runner@10548

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@10548

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@10548

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@10548

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@10548

vitest

npm i https://pkg.pr.new/vitest@10548

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@10548

@vitest/ws-client

npm i https://pkg.pr.new/@vitest/ws-client@10548

commit: ca2add6

@hi-ogawa hi-ogawa marked this pull request as ready for review June 9, 2026 02:27
@hi-ogawa hi-ogawa changed the title feat(mocker): hoist vi.mock() for vite-plus/test imports [backport to v4] fix(mocker): hoist vi.mock() for vite-plus/test imports [backport to v4] Jun 9, 2026
@sheremet-va sheremet-va merged commit 2c9559c into vitest-dev:v4 Jun 9, 2026
11 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants