Testing
The integration-test toolkit — an in-process Eden client, auth-backed fixtures, and a hermetic test-database lifecycle.
@halostack/testing is the monorepo's integration-test toolkit. It bundles an in-process Eden Treaty client that talks to the real @halostack/elysia app, better-auth-backed user and organization fixtures, and a hermetic lifecycle for the test database. Packages that run bun test — @halostack/elysia, for example — build their suites on top of it.
Importing
The package exposes three entry points: the main toolkit, the Bun test preload, and the lower-level database helpers.
The preload
The preload is the critical piece. Wire it into each package through a bunfig.toml with preload = ["@halostack/testing/preload"]. It runs once per test process, before any test module loads, and does three things:
- Bridges
TEST_DATABASE_URLtoDATABASE_URL, forcing tests onto thehalostack_testdatabase. - Mocks
@halostack/notifications/email(viamock.module) so signups never reach SMTP. - Dynamically imports
./dbto ensure the test database exists and is migrated.
Ordering matters here. @halostack/env snapshots process.env the first time it's imported, so the preload mutates the environment using only bun:test static imports, and only then reaches the db and env modules through a dynamic import().
Conventions
Fixtures register their own teardown, and drainCleanup runs them in a global afterAll. To keep tests isolated from one another, generate row identifiers with uniqueEmail() and uniqueSlug() rather than hard-coding values.