fix(repo): Mock @formkit/auto-animate/react in vitest setup#7903
fix(repo): Mock @formkit/auto-animate/react in vitest setup#7903jacekradko merged 3 commits intomainfrom
Conversation
The __mocks__ directory in src/elements/ was not detected by Vitest for node_module mocks, so auto-animate ran in tests and leaked timers that fired after jsdom teardown, causing requestAnimationFrame errors.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 3cda8c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAn explicit Vitest mock for 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/clerk-js/vitest.setup.mts`:
- Around line 265-270: Tests are missing to verify the explicit vi.mock of
'@formkit/auto-animate/react' (the vi.mock call that returns useAutoAnimate: ()
=> [null]) prevents requestAnimationFrame/timer leaks; add a unit test that
imports a component relying on useAutoAnimate (or directly imports the mocked
module), mounts/render it under Vitest, asserts no pending timers or raf
callbacks after unmount/teardown (or uses vi.useFakeTimers/vi.runAllTimers to
prove no leaked timers), and include the test file in the existing test suite so
coverage records the mock behavior; reference the mocked symbol useAutoAnimate
and the vi.mock declaration in vitest.setup.mts when locating where to base the
test.
This mock was never picked up by Vitest since __mocks__ directories nested inside src/ are not detected for node_module mocks. The explicit vi.mock in vitest.setup.mts now handles this.
Summary
vi.mock('@formkit/auto-animate/react')to the vitest setup file to prevent unhandledrequestAnimationFrame is not definederrors that fail CIThe
__mocks__directory atpackages/ui/src/elements/__mocks__/@formkit/auto-animate/react/was not being detected by Vitest for node_module mocks, soauto-animateactually ran in tests, created real timers, and leakedsetTimeoutcallbacks that fired after jsdom teardown — causingReferenceError: requestAnimationFrame is not defined.Test plan
pnpm test --filter=@clerk/uipasses with no unhandled errorspackages/clerk-js/vitest.setup.mtsSummary by CodeRabbit