[PR #7888] [MERGED] test: use vitest best practice #24514

Closed
opened 2026-04-15 22:24:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7888
Author: @himself65
Created: 2/10/2026
Status: Merged
Merged: 2/10/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/10/best-practice


📝 Commits (1)

  • f0e3a6c test: use vitest best practice

📊 Changes

73 files changed (+305 additions, -189 deletions)

View changed files

📝 packages/better-auth/src/api/middlewares/origin-check.test.ts (+6 -6)
📝 packages/better-auth/src/api/routes/account.test.ts (+2 -0)
📝 packages/better-auth/src/api/routes/email-verification.test.ts (+5 -1)
📝 packages/better-auth/src/api/routes/password.test.ts (+8 -4)
📝 packages/better-auth/src/api/routes/session-api.test.ts (+37 -1)
📝 packages/better-auth/src/api/routes/sign-in.test.ts (+6 -6)
📝 packages/better-auth/src/api/routes/sign-out.test.ts (+2 -2)
📝 packages/better-auth/src/api/routes/sign-up.test.ts (+9 -9)
📝 packages/better-auth/src/client/client.test.ts (+5 -1)
📝 packages/better-auth/src/client/proxy.test.ts (+5 -1)
📝 packages/better-auth/src/client/session-refresh.test.ts (+5 -1)
📝 packages/better-auth/src/context/create-context.test.ts (+1 -1)
📝 packages/better-auth/src/db/internal-adapter.test.ts (+0 -1)
📝 packages/better-auth/src/db/to-zod.test.ts (+3 -0)
📝 packages/better-auth/src/oauth2/utils.test.ts (+3 -0)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+6 -1)
📝 packages/better-auth/src/plugins/anonymous/anon.test.ts (+1 -1)
📝 packages/better-auth/src/plugins/api-key/api-key.test.ts (+5 -1)
📝 packages/better-auth/src/plugins/captcha/captcha.test.ts (+6 -6)
📝 packages/better-auth/src/plugins/device-authorization/device-authorization.test.ts (+5 -1)

...and 53 more files

📄 Description

Summary by cubic

Standardized Vitest usage across the repo to improve test reliability and reduce flakiness by fixing timer/mocking cleanup and replacing non-standard patterns.

  • Refactors
    • Removed passing “it” into describe; use standard describe/it imports.
    • Replaced .each with typed .for helpers where available for parameterized tests.
    • Added afterEach vi.useRealTimers in tests that use fake timers; centralized mock lifecycle by enabling clearMocks/restoreMocks in vitest.config.
    • Set default testTimeout and cleaned up redundant mockReset/mockRestore calls.
    • Minor test tidy-ups and added issue references in comments for clarity.

Written for commit f0e3a6c6b2. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7888 **Author:** [@himself65](https://github.com/himself65) **Created:** 2/10/2026 **Status:** ✅ Merged **Merged:** 2/10/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/10/best-practice` --- ### 📝 Commits (1) - [`f0e3a6c`](https://github.com/better-auth/better-auth/commit/f0e3a6c6b2c2cae51db00e4f2fc94095c451f998) test: use vitest best practice ### 📊 Changes **73 files changed** (+305 additions, -189 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/middlewares/origin-check.test.ts` (+6 -6) 📝 `packages/better-auth/src/api/routes/account.test.ts` (+2 -0) 📝 `packages/better-auth/src/api/routes/email-verification.test.ts` (+5 -1) 📝 `packages/better-auth/src/api/routes/password.test.ts` (+8 -4) 📝 `packages/better-auth/src/api/routes/session-api.test.ts` (+37 -1) 📝 `packages/better-auth/src/api/routes/sign-in.test.ts` (+6 -6) 📝 `packages/better-auth/src/api/routes/sign-out.test.ts` (+2 -2) 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+9 -9) 📝 `packages/better-auth/src/client/client.test.ts` (+5 -1) 📝 `packages/better-auth/src/client/proxy.test.ts` (+5 -1) 📝 `packages/better-auth/src/client/session-refresh.test.ts` (+5 -1) 📝 `packages/better-auth/src/context/create-context.test.ts` (+1 -1) 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+0 -1) 📝 `packages/better-auth/src/db/to-zod.test.ts` (+3 -0) 📝 `packages/better-auth/src/oauth2/utils.test.ts` (+3 -0) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+6 -1) 📝 `packages/better-auth/src/plugins/anonymous/anon.test.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/api-key/api-key.test.ts` (+5 -1) 📝 `packages/better-auth/src/plugins/captcha/captcha.test.ts` (+6 -6) 📝 `packages/better-auth/src/plugins/device-authorization/device-authorization.test.ts` (+5 -1) _...and 53 more files_ </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Standardized Vitest usage across the repo to improve test reliability and reduce flakiness by fixing timer/mocking cleanup and replacing non-standard patterns. - **Refactors** - Removed passing “it” into describe; use standard describe/it imports. - Replaced .each with typed .for helpers where available for parameterized tests. - Added afterEach vi.useRealTimers in tests that use fake timers; centralized mock lifecycle by enabling clearMocks/restoreMocks in vitest.config. - Set default testTimeout and cleaned up redundant mockReset/mockRestore calls. - Minor test tidy-ups and added issue references in comments for clarity. <sup>Written for commit f0e3a6c6b2c2cae51db00e4f2fc94095c451f998. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:24:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#24514