--- paths: - "**/__tests__/**/*.ts" - "**/__tests__/**/*.tsx" - "**/*.test.ts" - "**/*.test.tsx" - "e2e/**/*.spec.ts" --- # Testing Rules ## Jest environment - Global mocks are set up in `jest.setup.ts` — do NOT re-mock `matchMedia`, `IntersectionObserver`, or `NextResponse` in individual tests - Test env vars are pre-set: `DIRECTUS_URL`, `NEXT_PUBLIC_SITE_URL` - Always mock external API calls (Directus, n8n, PostgreSQL) — tests must work without running services ## ESM modules If a new import causes "Must use import to load ES Module" errors, add the package to `transformIgnorePatterns` in `jest.config.ts`. ## Server component tests ```typescript // Server components return JSX, not a promise in React 19, but async ones need await const resolved = await MyServerComponent({ locale: 'en', ...props }) render(resolved) ``` ## next/image in tests Replace `next/image` with a plain `` in test renders: ```tsx // eslint-disable-next-line @next/next/no-img-element {alt} ``` ## Run commands - Single file: `npx jest path/to/test.tsx` - All unit tests: `npm run test` - Watch mode: `npm run test:watch` - Specific E2E: `npm run test:critical`, `npm run test:hydration`, `npm run test:accessibility`