Test your code
Goal
Run the Vitest suite and the TypeScript checks, and place new tests where the runner picks them up.
Steps
Know the runners (
package.jsonscripts):npm run test→vitest run— everything matching theincludeglobs invitest.config.ts:.framework/tests/unit/**/*.test.ts,.framework/tests/api/**/*.test.ts,.framework/tests/integration/**/*.test.ts, andcustom/tests/**/*.test.ts.npm run test:unit— the unit suite only.npm run test:integration— the integration suite (needs real env, see below).npm run test:core— the core-isolation suite.npm run typecheck→tsc -b config/tsconfig.json— frontend + CLI. Functions are not covered here: check them separately withnpx tsc --noEmit -p config/tsconfig.functions.jsonafternpm run assemble(it typechecks the assembled layout).npx spine-framework test [suite]— the CLI wrapper (--watch,--reporter,--json; see CLI reference).
- Put tests where the globs look. New project tests belong in
custom/tests/**/*.test.ts— picked up automatically, and they keep.framework/untouched. Framework-level additions go under.framework/tests/unit/. Test files insidecustom/functions/are excluded from function assembly (*-test.ts,*.test.tsare skipped byscripts/assemble-functions.sh), but naming convention is still*.test.ts. - Understand the env layering.
vitest.config.tsloads a root.env.testfile (if present) intoprocess.envbefore any module graph runs — that is how integration/API tests get real Supabase credentials beforedb.ts/principal.tscallcreateClientat import time..framework/tests/setup.tsthen stubsSUPABASE_URL,SUPABASE_ANON_KEY,SUPABASE_SERVICE_ROLE_KEYso unit tests never crash on missing env. Integration helpers additionally requireSPINE_TEST_ACCOUNT_ID; API-surface tests useSPINE_DEV_URL,SPINE_DEV_JWT,SPINE_TEST_API_KEY(see Environment variables). - Mock at module boundaries. The config sets
isolate: true— every test file gets a fresh module registry, sovi.mockon./_shared/db-style imports works per file. Existing unit suites mock the Supabase client, principal resolution, and the LLM/embedding calls rather than hitting the network (browse.framework/tests/unit/for patterns —pipeline-runner.test.ts,permissions.test.ts,principal-cache.test.ts). - Integration tests need a real project. They exercise admin-data, triggers, pipelines, and schema validation against a live Supabase project using a service-role client and a seeded test account —
custom/testsand the unit suite run with no credentials, the integration suite does not.passWithNoTests: truemeans a missing env never fails the suite outright, so check that tests actually ran.
Verify
npm run testexits 0;vitestprints per-file pass counts. A custom reporter that persists runs topublic.test_runsexists at.framework/tests/reporter.tsbut is not registered — the config usesreporters: ['default'], so opt in with--reporterif you want persisted runs.npm run typecheckandnpx tsc --noEmit -p config/tsconfig.functions.jsonare both clean.npx spine-framework doctorsanity-checks the environment when tests behave oddly (CLI reference).
Common mistakes
typecheckdoesn't cover functions.config/tsconfig.jsonexcludes the functions project by design — always run thetsconfig.functions.jsoncheck too, and only afternpm run assemble.- Assuming integration tests ran. With no
.env.test, integration files that can't build a client may skip silently — grep the output for your file's pass count. - Importing
createClientat module top-level in a unit test. Setup stubs the env, but a module that builds a client at import time beforesetupFilesruns still fails — mock the module or import lazily. - Writing repo-only paths into
custom/tests— tests there must run in an installed project too; import fromcustom/and assembled aliases, not from repo internals.
Reference
- CLI reference —
test,doctor - Environment variables —
SPINE_TEST_*,SPINE_DEV_*,SUPABASE_* - Write a function — assembled-layout imports