Testare
Suite de teste pe mai multe straturi: logică pură, API handlers, componente Vue și smoke E2E.
Stack
| Strat | Tool | Locație |
|---|---|---|
| Unit | Vitest (node) | tests/unit/** |
| API | Vitest + h3 mocks | tests/api/** |
| Component | Vitest + @nuxt/test-utils | tests/components/** |
| E2E | Playwright | tests/e2e/** |
Configurare
vitest.config.ts— environment defaultnuxt; fișiere server folosesc@vitest-environment nodeplaywright.config.ts— webServer cunpm run build:e2e- Fixtures:
tests/fixtures/—poem.ts,lexicon.ts - Helpers:
tests/helpers/nitro.ts
Comenzi
npm test # Toate testele Vitest
npm run test:watch # Watch mode
npx vitest run tests/api/home.get.test.ts # Un fișier
npm run test:e2e # Playwright (build + browser)
npm run test:all # Vitest + E2EPattern-uri
Unit (logică pură)
// @vitest-environment node
import { describe, expect, it } from 'vitest'
import { myFn } from '~/utils/myFn'API handler
vi.mockprisma / utils la granița modululuicreateEventdin h3 cu query string- Dynamic
import()handler după mocks - Exemplu:
tests/api/words.get.test.ts
Component
mountSuspendeddin@nuxt/test-utils/runtime- Selectori
data-testidcând există - Exemplu:
tests/components/PaginationNav.test.ts
E2E
tests/e2e/smoke.spec.ts— încărcare pagini + API JSON- Rulează pe build producție (
NITRO_PRESET=node-server)
CI
GitHub Actions rulează npm test apoi npm run test:e2e cu Postgres și env de test.
Ce testăm
- Auth, roluri, validare input
- Motor rime, diacritice românești, normalizare
- Contracte API publice (home, poems, tags, carousel)
- Componente DS și carduri poem