Skip to content

fix(runtime): reset modules after nuxt setup runs#726

Merged
danielroe merged 5 commits intomainfrom
fix/mock
Jan 22, 2024
Merged

fix(runtime): reset modules after nuxt setup runs#726
danielroe merged 5 commits intomainfrom
fix/mock

Conversation

@danielroe
Copy link
Copy Markdown
Member

@danielroe danielroe commented Jan 19, 2024

resolves #693

import { vi } from 'vitest'
import { mockNuxtImport } from '@nuxt/test-utils/runtime'

vi.resetModules()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it mandatory ?

Copy link
Copy Markdown
Member Author

@danielroe danielroe Jan 19, 2024

Choose a reason for hiding this comment

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

yes, without it vitest errors and tells us to reset these mocks... I felt it was a vitest design decision rather than something we should do - but happy to be proven otherwise 🤷

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So i guess we should warn users that this is needed within setup files ? Or probably inject it ourselves with a transform plugin ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm thinking we shouldn't insert it ourselves as they might want to run some setup steps that rely on not resetting modules. In future we could add it as an enhancement (or bugfix!) if there's not a reason to allow manually calling it.

@danielroe danielroe merged commit 94d3e1e into main Jan 22, 2024
@danielroe danielroe deleted the fix/mock branch January 22, 2024 16:46
This was referenced Jan 22, 2024
This was referenced Jan 28, 2024
@github-actions github-actions bot mentioned this pull request Jan 28, 2024
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 mock "#app/nuxt" because it is already loaded error in Nuxt environment

2 participants