HaloStack Docs
Open App
Tools

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:

  1. Bridges TEST_DATABASE_URL to DATABASE_URL, forcing tests onto the halostack_test database.
  2. Mocks @halostack/notifications/email (via mock.module) so signups never reach SMTP.
  3. Dynamically imports ./db to 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.