Vitest is pre-configured. Run npm run test to execute the baseline suite and any tests you add.
| Runner | Vitest |
| Environment | node (default) |
| Config | vitest.config.ts |
| Test files | tests/*.test.ts |
| Run | npm run test |
tests/health.test.tsGET /api/health — verifies the health endpoint returns 200 + status ok
tests/zod.test.tsZod validation — confirms the input validation pattern works as expected
tests/auth.test.tsAuth setup — verifies Better Auth initialises without errors (when auth is active)
| Target | Why |
|---|---|
| API routes | Test input validation, auth guards, and response shape |
| Utility functions in lib/ | Pure functions are easy to test and high-value |
| Zod schemas | Confirm edge cases (invalid email, missing fields, etc.) |
| Integration clients | Mock fetch and verify headers / request structure |
import { describe, it, expect } from 'vitest'
import { z } from 'zod'
const CreateUserSchema = z.object({
name: z.string().min(1),
email: z.string().email(),
})
describe('CreateUserSchema', () => {
it('accepts valid input', () => {
const result = CreateUserSchema.safeParse({ name: 'Alice', email: 'alice@example.com' })
expect(result.success).toBe(true)
})
it('rejects invalid email', () => {
const result = CreateUserSchema.safeParse({ name: 'Alice', email: 'not-an-email' })
expect(result.success).toBe(false)
})
})