Add unit, integration and e2e test suites

tests/{unit,integration,e2e}/, at the repo root (not under frontend/,
since e2e exercises the frontend and PocketBase together) — all
against real code rather than mocks:

- unit/: Vitest (nuxt environment) — pure functions in server/utils
  and shared/utils, plus components/composables via
  @nuxt/test-utils/runtime's mountSuspended.
- integration/: Vitest (node environment) — @nuxt/test-utils/e2e's
  setup() builds and runs the real Nitro server against a real
  ephemeral PocketBase instance, exercising the actual /content/* and
  /admin routes end to end.
- e2e/: Playwright, a real browser against the built app and another
  ephemeral PocketBase, covering the user-facing flows (home, blog
  archive, article detail incl. JSON-LD, category filter, 404s, the
  /admin redirect).

The Vitest/Playwright tooling (and node_modules) stays in frontend/,
the repo's only npm project; its configs just point at ../tests/.
Playwright resolves packages from the node_modules nearest each spec
file, so `npm run test:e2e` first symlinks tests/node_modules to
frontend/node_modules (pretest:e2e, idempotent, gitignored).

tests/support/pocketbase.ts is the shared piece behind integration
and e2e: it downloads the same pinned PocketBase binary
pocketbase/Dockerfile uses, starts it against the real
pocketbase/pb_migrations/ (not a copy), and seeds it from
tests/support/fixtures.ts — so these tests run against the exact
schema and API rules that ship to production, catching the class of
bug that only shows up when PocketBase actually enforces them (e.g. a
wrong filter/fields query string silently returning nothing, or too
much).

CLAUDE.md and docs/frontend.md document the new npm scripts and the
single-test commands for each layer.
This commit is contained in:
2026-09-11 11:48:43 +02:00
parent 6609e3ae28
commit 91181f2170
23 changed files with 1767 additions and 75 deletions
+23 -4
View File
@@ -10,8 +10,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Stato
Struttura, content type, pagine blog, Docker e Caddy sono in piedi. Restano da fare:
sitemap e `robots.txt` dinamici, ricerca, e i test (nessun framework ancora configurato).
Struttura, content type, pagine blog, Docker, Caddy e i test (unit/integration/e2e) sono in
piedi. Restano da fare: sitemap e `robots.txt` dinamici, ricerca.
## Architettura
@@ -67,6 +67,16 @@ npm run build # build produzione
npm run typecheck # nuxi typecheck — obbligatorio prima di dichiarare fatto
npm run lint
npm run test:unit # Vitest, ambiente Nuxt: funzioni pure + componenti/composable
npm run test:integration # Vitest, server Nitro reale + PocketBase effimero reale
npm run test:e2e # Playwright, browser reale contro build + PocketBase effimero reale
npm run test # i tre, in sequenza
# singolo test:
npx vitest run --config vitest.unit.config.ts tests/unit/queries.utils.test.ts
npx vitest run --config vitest.integration.config.ts -t "lists only published articles"
npx playwright test tests/e2e/home.spec.ts
# pocketbase/ (nessun npm script: binario singolo, le migration si applicano da sole all'avvio)
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build pocketbase frontend
@@ -81,8 +91,17 @@ docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build poc
`docker-compose.dev.yml` va passato **sempre esplicitamente**: non è un `override.yml` proprio
per non finire per sbaglio in produzione esponendo le porte.
Nessun test framework è ancora configurato. Se ne aggiungi uno, documenta qui il comando per
lanciare **un singolo test**.
`tests/` sta nella root del repo (non sotto `frontend/`), perché l'e2e esercita frontend e
PocketBase insieme — gli strumenti (config Vitest/Playwright, `node_modules`) restano comunque in
`frontend/`, l'unico progetto npm del repo, e puntano a `../tests/`. Playwright risolve i pacchetti
dal `node_modules` più vicino al file di test: per questo `npm run test:e2e` crea prima (script
`pretest:e2e`, idempotente) il symlink `tests/node_modules → ../frontend/node_modules`.
I test di integration/e2e avviano un vero binario PocketBase effimero (scaricato una volta in
`.cache/pocketbase/` nella root, versione allineata a `pocketbase/Dockerfile`) contro le vere
migration in `pocketbase/pb_migrations/` — niente PocketBase mockato. `npm run test:e2e` richiede
Chromium installato una tantum: `npx playwright install chromium` (senza `--with-deps`, che
richiede `sudo`; se mancano librerie di sistema per il browser, installarle a parte).
## Modelli di contenuto