directus-main — testing strategy

Seven workspaces, seven real Vitest suites — plus one thing no coverage number catches.

Every workspace runs its own real vitest run, with coverage checked per package rather than one monorepo-wide blended number. See Auth & Request Flow for a real bug this same testing discipline caught later, in a different package.

Seven Layers, Leaf to Server

packages/constants · 2 tests The zero-dependency leaf. Pure value assertions — PERMISSION_ACTIONS, LOCAL_AUTH_DRIVER — nothing to mock because there's no behavior, only constants.
packages/errors · 10 tests Every error class tested for code, status, message, and toString(), plus isDirectusError identification — including a real regression test for an empty-string reason that used to silently fall through ?? instead of falling back.
packages/system-data · 30 tests The real types.ts type surface — filters, permissions, collection/field/relation metadata. All type-only (expectTypeOf), checked only by yarn typecheck; vitest run treats these assertions as inert no-ops at runtime, so 0/0 coverage here is correct, not a gap.
packages/utils · 27 tests, 100% Real runtime behavior this time, not types — toBoolean/toArray done so far, 2 of a real 61-function scope. The first package in this repo to depend on another real package (constants + system-data).
packages/stores · 20 tests, 100% Pinia stores tested in isolation (environment: 'node' — no DOM needed). 100% coverage was already true before a completeness audit found 4 real gaps it hadn't caught anyway.
app/ · 28 tests Component tests via @vue/test-utils + happy-dom, plus real headless-browser verification (Playwright) for anything a unit test can't prove — the actual rendered login page, and the live GitHub Pages deploy's routing end to end.
api/ · 4 tests A real Express server tested with supertest against the exported app, so no real port gets bound. One disclosed gap: app.listen's own callback body is genuinely unreachable under NODE_ENV=test, by design — not hidden behind a coverage-ignore pragma.

Per-Workspace Gates, Same Order Every Time

Local, before every commit

format → build → lint → lint:style → test

build runs before lint/test deliberately — see System Architecture for the real CI failure that ordering fixed.

CI, on every push

The same five gates, plus CodeQL

Never assumed green from a local run alone — every push is watched through to a real gh run watch --exit-status before being called done.

!

100% coverage still let 4 real gaps through: a completeness audit — prompted by comparing packages/stores's own file count against the real source — found that auth.test.ts/user.test.ts only ever asserted derived values (loggedIn, fullName), never the raw stored state; a bug that swapped two stored fields would still have passed every existing test. Every line was already executing — coverage just can't tell you the right value ended up in the right place. Fixed with explicit toEqual assertions on the actual stored objects, alongside two smaller gaps in the same pass (a missing type export, a package.json exports map blocking the package's own package.json resolution).