Skip to content

Build your personal knowledge base with Trilium Notes

chore(claude): mention where to write unit tests

Elian Doranbf6255831cc4
diff --git a/.claude/skills/writing-unit-tests/server-and-core.md b/.claude/skills/writing-unit-tests/server-and-core.md
index 86692efd73..9d5fda58ea 100644
--- a/.claude/skills/writing-unit-tests/server-and-core.md
+++ b/.claude/skills/writing-unit-tests/server-and-core.md
@@ -14,6 +14,8 @@ There are **two distinct HTTP code paths** — testing one does not cover the ot
- **ETAPI** (`apps/server/src/etapi/*`): basic-auth token, helpers in `spec/etapi/utils.ts`.
- **Internal API**: the `apps/server/src/routes/api/*` Express wrappers, plus the **shared core handlers** in `packages/trilium-core/src/routes/api/*` (registered by `buildSharedApiRoutes`). The shared core handlers are driven cross-runtime by `CoreApiTester` (Pattern 0); the thin Express transport on top is covered by supertest (Pattern 1).
+**Where spec files live:** internal-API and core route tests are **co-located with their module** — `apps/server/src/routes/api/<module>.spec.ts` for the thin Express transport, `packages/trilium-core/src/routes/api/<module>.spec.ts` for the shared core handler. **ETAPI is the exception**: its specs live under `apps/server/spec/etapi/` (with the `spec/etapi/utils.ts` helpers). Don't park internal `/api/*` tests in `spec/` — e.g. the metrics endpoint test belongs at `src/routes/api/metrics.spec.ts`, next to `metrics.ts`, not in `spec/etapi/`.
+
## Pattern 0 — the cross-runtime core route driver (`CoreApiTester`) — PREFER THIS for core routes
For specs under `packages/trilium-core/src/routes/api/*.spec.ts`, use the in-process, transport-agnostic driver `packages/trilium-core/src/test/api_tester.ts`. It registers the exact handlers from `routes.buildSharedApiRoutes` and runs them **without Express/HTTP**, so the same spec runs under **both** the node (better-sqlite3) and standalone (sql.js WASM) suites. It exercises the real lifecycle: param/query parsing, cls + SQL transaction wrapping, `convertEntitiesToPojo`, the `[status, body]`/`undefined→204` conventions, `HttpError`→status mapping, and JSON round-tripping. It deliberately skips platform middleware (auth/CSRF/rate-limit/multipart) — those are server concerns (Pattern 1).