mirror of
https://github.com/f/awesome-chatgpt-prompts.git
synced 2026-03-03 03:07:00 +00:00
feat(testing): implement vitest test suite
Add comprehensive testing infrastructure with vitest, React Testing Library, and jsdom. Includes tests for: - Utility functions (cn, isChromeBrowser, date formatting, JSON utils) - Variable detection module (7 pattern types, conversion, false positives) - API routes (health check, user registration with validation/auth) 127 tests passing covering critical functionality.
This commit is contained in:
89
vitest.setup.ts
Normal file
89
vitest.setup.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Mock environment variables
|
||||
process.env.NEXTAUTH_SECRET = "test-secret";
|
||||
process.env.NEXTAUTH_URL = "http://localhost:3000";
|
||||
process.env.DATABASE_URL = "postgresql://test:test@localhost:5432/test";
|
||||
|
||||
// Mock next/navigation
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
back: vi.fn(),
|
||||
forward: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
}),
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
usePathname: () => "/",
|
||||
useParams: () => ({}),
|
||||
redirect: vi.fn(),
|
||||
notFound: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock next/headers
|
||||
vi.mock("next/headers", () => ({
|
||||
cookies: () => ({
|
||||
get: vi.fn(),
|
||||
set: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
}),
|
||||
headers: () => new Headers(),
|
||||
}));
|
||||
|
||||
// Mock next-intl
|
||||
vi.mock("next-intl", () => ({
|
||||
useTranslations: () => (key: string) => key,
|
||||
useLocale: () => "en",
|
||||
getTranslations: () => Promise.resolve((key: string) => key),
|
||||
}));
|
||||
|
||||
// Mock Prisma client
|
||||
vi.mock("@/lib/db", () => ({
|
||||
db: {
|
||||
user: {
|
||||
findUnique: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
count: vi.fn(),
|
||||
},
|
||||
prompt: {
|
||||
findUnique: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
count: vi.fn(),
|
||||
},
|
||||
category: {
|
||||
findUnique: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
$queryRaw: vi.fn(),
|
||||
$executeRaw: vi.fn(),
|
||||
$transaction: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock config
|
||||
vi.mock("@/lib/config", () => ({
|
||||
getConfig: vi.fn(() =>
|
||||
Promise.resolve({
|
||||
auth: {
|
||||
allowRegistration: true,
|
||||
providers: [],
|
||||
},
|
||||
features: {},
|
||||
})
|
||||
),
|
||||
}));
|
||||
Reference in New Issue
Block a user