Quick Start
Pick your test runner. Both paths use the default SQLite store and capture failures locally in under two minutes.
-
Install the plugin and a store
Terminal window bun add -D @flaky-tests/plugin-bun @flaky-tests/store-sqliteStore adapters ship as
optionalDependenciesof the plugin, so you install only the one you use. The default preload resolvesFLAKY_TESTS_STORE(defaults tosqlite) at startup. -
Add the preload to
bunfig.toml[test]preload = ["@flaky-tests/plugin-bun/preload"]That’s it. The next time you run
bun test, failures are captured automatically. -
Run your tests
Terminal window bun testFailures are written to
node_modules/.cache/flaky-tests/failures.db. Nothing else changes — tests still pass and fail as normal. -
Check for flaky patterns
After a few runs (or in CI after a few days):
Terminal window bunx @flaky-tests/coreIf new patterns are detected you’ll see something like:
✗ 1 new flaky test pattern detected1. auth > login > should redirect on successtests/auth.test.ts · timeout · 8 fails in 7dExpected redirect within 2000msRun with --prompt to print investigation prompts -
Generate an investigation prompt
Terminal window bunx @flaky-tests/core --promptCopy the output into Claude, Cursor, or Copilot to investigate.
-
Install the reporter and a store
Terminal window npm i -D @flaky-tests/plugin-vitest @flaky-tests/store-sqliteTerminal window pnpm add -D @flaky-tests/plugin-vitest @flaky-tests/store-sqliteTerminal window yarn add -D @flaky-tests/plugin-vitest @flaky-tests/store-sqlite -
Add the reporter to
vitest.config.tsvitest.config.ts import { defineConfig } from 'vitest/config'import { FlakyTestsReporter } from '@flaky-tests/plugin-vitest'import { SqliteStore } from '@flaky-tests/store-sqlite'export default defineConfig({test: {reporters: ['default', new FlakyTestsReporter(new SqliteStore())],},})Works with Vitest v1, v2, and v3 — the reporter only uses the stable
onInit/onFinishedhooks. -
Run your tests
Terminal window npx vitest runTerminal window pnpm vitest runTerminal window yarn vitest runFailures are written to
node_modules/.cache/flaky-tests/failures.db. Nothing else changes — tests still pass and fail as normal. -
Check for flaky patterns
After a few runs (or in CI after a few days):
Terminal window npx @flaky-tests/coreTerminal window pnpm @flaky-tests/coreTerminal window yarn @flaky-tests/coreIf new patterns are detected you’ll see something like:
✗ 1 new flaky test pattern detected1. auth > login > should redirect on successtests/auth.test.ts · timeout · 8 fails in 7dExpected redirect within 2000msRun with --prompt to print investigation prompts -
Generate an investigation prompt
Terminal window npx @flaky-tests/core --promptTerminal window pnpm @flaky-tests/core --promptTerminal window yarn @flaky-tests/core --promptCopy the output into Claude, Cursor, or Copilot to investigate.
Wire it into package.json
Section titled “Wire it into package.json”Typing bunx / npx each time gets old. Install the CLI as a dev
dependency and add scripts so the whole team runs the same invocation:
npm i -D @flaky-tests/corepnpm add -D @flaky-tests/coreyarn add -D @flaky-tests/core{ "scripts": { "flaky": "flaky-tests", "flaky:prompt": "flaky-tests --prompt", "flaky:report": "flaky-tests --html" }}Now anyone on the project can run bun run flaky (or npm run flaky /
pnpm flaky / yarn flaky) without reaching for the full package
name, and CI workflows get a single stable command to call.
What’s next?
Section titled “What’s next?”- Working in a team? → Choosing a store — SQLite is local only
- Want automatic detection in CI? → Scheduled detection
- Need deeper Vitest config? → Setting up with Vitest
- Bun-specific options? → Setting up with Bun