Dev

Testare

Suite de teste pe mai multe straturi: logică pură, API handlers, componente Vue și smoke E2E.

Stack

StratToolLocație
UnitVitest (node)tests/unit/**
APIVitest + h3 mockstests/api/**
ComponentVitest + @nuxt/test-utilstests/components/**
E2EPlaywrighttests/e2e/**

Configurare

  • vitest.config.ts — environment default nuxt; fișiere server folosesc @vitest-environment node
  • playwright.config.ts — webServer cu npm 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 + E2E

Pattern-uri

Unit (logică pură)

// @vitest-environment node
import { describe, expect, it } from 'vitest'
import { myFn } from '~/utils/myFn'

API handler

  • vi.mock prisma / utils la granița modulului
  • createEvent din h3 cu query string
  • Dynamic import() handler după mocks
  • Exemplu: tests/api/words.get.test.ts

Component

  • mountSuspended din @nuxt/test-utils/runtime
  • Selectori data-testid câ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