Setting up with Bun
The Bun plugin works as a preload script — it runs before your tests and wraps bun:test to intercept every failure.
Installation
Section titled “Installation”-
Install the plugin and a store
Terminal window bun add -D @flaky-tests/plugin-bun @flaky-tests/store-sqlite -
Add the preload to
bunfig.toml[test]preload = ["@flaky-tests/plugin-bun/preload"] -
Run your tests as normal
Terminal window bun testEvery failure is written to
node_modules/.cache/flaky-tests/failures.dbautomatically.
How it works
Section titled “How it works”The preload script uses mock.module('bun:test', ...) to wrap the test, it, and describe globals with a thin proxy. When a test fails, the failure is written to the store. When all tests finish, the run is closed.
The proxy preserves all sub-APIs: .skip, .only, .each, .todo, .if, and .skipIf all work exactly as before.
Writes are fire-and-forget during the run, but the preload drains any outstanding writes at process exit so remote-store failures don’t get lost between the last test and shutdown.
Choosing a different store
Section titled “Choosing a different store”By default the preload resolves whichever store matches FLAKY_TESTS_STORE (sqlite, turso, supabase, or postgres) and calls migrate() for you before the first write. You only need a custom preload if you want to construct the store yourself:
import { createPreload } from '@flaky-tests/plugin-bun'import { TursoStore } from '@flaky-tests/store-turso'
const store = new TursoStore({ url: process.env.TURSO_URL!, authToken: process.env.TURSO_AUTH_TOKEN,})await store.migrate()
createPreload(store)Then point bunfig.toml at your file:
[test]preload = ["./preload.ts"]Environment variables
Section titled “Environment variables”| Variable | Description | Default |
|---|---|---|
FLAKY_TESTS_DISABLE | Set to 1 or true to skip all capture | — |
FLAKY_TESTS_DB | Override the SQLite file path | node_modules/.cache/flaky-tests/failures.db |
Disabling capture
Section titled “Disabling capture”To skip capture for a single run:
FLAKY_TESTS_DISABLE=1 bun test