Skip to content

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.

  1. Install the plugin and a store

    Terminal window
    bun add -D @flaky-tests/plugin-bun @flaky-tests/store-sqlite
  2. Add the preload to bunfig.toml

    [test]
    preload = ["@flaky-tests/plugin-bun/preload"]
  3. Run your tests as normal

    Terminal window
    bun test

    Every failure is written to node_modules/.cache/flaky-tests/failures.db automatically.

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.

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:

preload.ts
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"]
VariableDescriptionDefault
FLAKY_TESTS_DISABLESet to 1 or true to skip all capture
FLAKY_TESTS_DBOverride the SQLite file pathnode_modules/.cache/flaky-tests/failures.db

To skip capture for a single run:

Terminal window
FLAKY_TESTS_DISABLE=1 bun test