Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(runtime-utils): avoid local variable in mockNuxtImport macro#1564

Merged
danielroe merged 1 commit intonuxt:mainnuxt/test-utils:mainfrom
yamachi4416:fix-mock-nuxt-import-mocks-variableyamachi4416/test-utils:fix-mock-nuxt-import-mocks-variableCopy head branch name to clipboard
Jan 26, 2026
Merged

fix(runtime-utils): avoid local variable in mockNuxtImport macro#1564
danielroe merged 1 commit intonuxt:mainnuxt/test-utils:mainfrom
yamachi4416:fix-mock-nuxt-import-mocks-variableyamachi4416/test-utils:fix-mock-nuxt-import-mocks-variableCopy head branch name to clipboard

Conversation

@yamachi4416
Copy link
Copy Markdown
Member

@yamachi4416 yamachi4416 commented Jan 25, 2026

🔗 Linked issue

resolves #1553

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 25, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1564

commit: d8ca890

@yamachi4416 yamachi4416 marked this pull request as ready for review January 25, 2026 05:52
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

This PR addresses a scoping issue with mockNuxtImport when using Vitest's hoisted mocks. The changes refactor the mocking mechanism in the core plugin to use per-import hoist module entries stored in globalThis.__NUXT_VITEST_MOCKS rather than a shared global map. Each mocked module now receives its own scoped entry accessed via the source module key, enabling proper variable reference within hoisted mock factories. Test files are updated to demonstrate the new pattern with hoisted mocks, and async/await is added to test assertions for consistency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing the mockNuxtImport macro to avoid using a local variable named 'mocks' that was causing the reported issue.
Description check ✅ Passed The description adequately references the linked issue (#1553) and identifies the PR as a bug fix related to the mockNuxtImport macro.
Linked Issues check ✅ Passed The code changes align with issue #1553: the macro implementation now uses per-import hoisted objects (mockModuleEntry) instead of a shared global mocks map, eliminating variable shadowing and allowing factories to properly reference external 'mocks' variables.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the mockNuxtImport macro issue. Tests were updated to verify the fix works (new hoisted mocks test) and converted to async for consistency; no unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

❤️

@danielroe danielroe merged commit 5152194 into nuxt:main Jan 26, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jan 26, 2026
@yamachi4416 yamachi4416 deleted the fix-mock-nuxt-import-mocks-variable branch January 26, 2026 23:01
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.

cannot correctly reference the variable named mocks in mockNuxtImport factory

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.