Skip to content

Conversation

@yamachi4416
Copy link
Contributor

@yamachi4416 yamachi4416 commented Dec 15, 2025

πŸ”— Linked issue

resolves #1496

❓ 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

I explored whether we could mock the modules used in our global middleware using the existing setupFile mechanism that starts the NuxtApp. However, I realized that this approach couldn't support both scenarios: mocking the module when the NuxtApp starts and mocking it after it has already started.

To resolve this, I introduced a new startOn option. This allows us to choose the timing for starting the NuxtApp, which can now be toggled per test file using @vitest-environment-options.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 15, 2025

Open in StackBlitz

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

commit: 575fbba

@yamachi4416 yamachi4416 marked this pull request as ready for review December 15, 2025 11:50
@yamachi4416
Copy link
Contributor Author

I’ve realized there are some points I haven't fully considered yet, so I’ll revert this to a draft for further refinement. My apologies.

@yamachi4416 yamachi4416 marked this pull request as draft December 16, 2025 11:34
@yamachi4416 yamachi4416 force-pushed the feat/support-mock-in-middleware branch from 1823a5c to c2fbe7b Compare December 19, 2025 12:08
@yamachi4416 yamachi4416 changed the title fix(runtime): make mockNuxtImport work inside middleware feat(runtime): add startOn environment option Dec 19, 2025
@yamachi4416 yamachi4416 force-pushed the feat/support-mock-in-middleware branch from c2fbe7b to 4a89806 Compare December 19, 2025 16:40
directives: vueApp._context.directives,
provide: vueApp._context.provides,
components: { RouterLink },
components: { ...vueApp._context.components, RouterLink },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While testing a mocked component provided through a plugin, I encountered a failure and realized it needed to be adjusted to align with how mountSuspended works.

@yamachi4416 yamachi4416 force-pushed the feat/support-mock-in-middleware branch from 4a89806 to 575fbba Compare December 19, 2025 17:02
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.

mockNuxtImport: not mocking inside middleware/

1 participant