@terreno/test
v58.0.6
Published
Shared Bun test helpers, MongoDB preload utilities, and HTTP fixtures — part of Terreno, the batteries-included TypeScript framework for universal apps.
Maintainers
Readme
@terreno/test
Shared Bun test helpers, MongoDB preload utilities, and HTTP fixtures for Terreno packages.
Install
bun add -d @terreno/test mongoosemongoose is a peer dependency (>= 8.0.0).
Quick start
In bunfig.toml:
[test]
preload = ["./src/tests/bunSetup.ts"]
root = "./src"In src/tests/bunSetup.ts:
import {registerSimpleMongoPreload} from "@terreno/test";
process.env.TERRENO_TEST_USE_MEMORY_MONGO = "true";
registerSimpleMongoPreload({
testEnv: {
tokenIssuer: "my-package.test",
},
});Then run bun test in the package. The preload starts mongodb-memory-server when TERRENO_TEST_MONGODB_URI is unset. Set TERRENO_TEST_MONGODB_URI to use an external MongoDB. Set BUN_TEST_DISABLE_DB=true to skip database hooks.
What's included
registerSimpleMongoPreload— connect-once in-memory or external MongoregisterBackendPreload— full lifecycle with optional transactions and fixture cachesetTerrenoTestEnv— canonical auth secrets for testsgetBaseServer/authAsUser— Express + supertest helpersauthWithToken— authenticate with a pre-minted token, skipping the login round-tripwaitUntil/waitForCalls/freezeTime— poll instead of sleeping; freeze the clockexpectAPIError/assertStrictResponseProperties— error-body and field-leak assertions- Opt-in SDK mocks: Cloud Tasks, SendGrid, Twilio, Expo push, GCS, Google auth, AI SDK, notifiers
- Log silencing and Sentry mocks for quiet CI
@terreno/test/expo/*— Bun test environment for Expo / React Native appsterreno-test-shardandterreno-test-hygieneCLIs
Documentation
Full API reference: docs/reference/test.md
License and Contributing
Licensed under the MIT License. See CONTRIBUTING.md for contribution guidelines.
