Setting up with Vitest
The Vitest plugin is a reporter — it hooks into Vitest’s lifecycle using the standard reporter API and writes failures to your chosen store.
Installation
Section titled “Installation”-
Install the plugin 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())],},})The reporter requires an
IStoreinstance — swapSqliteStorefor any other adapter (Turso, Supabase, Postgres) with the same shape. -
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.
Using a custom store
Section titled “Using a custom store”Pass any store that implements IStore as the reporter’s positional
argument:
import { defineConfig } from 'vitest/config'import { FlakyTestsReporter } from '@flaky-tests/plugin-vitest'import { TursoStore } from '@flaky-tests/store-turso'
const store = new TursoStore({ url: process.env.FLAKY_TESTS_CONNECTION_STRING!, authToken: process.env.FLAKY_TESTS_AUTH_TOKEN,})// The reporter calls migrate() for you on `onInit`, so manually// migrating here is optional.
export default defineConfig({ test: { reporters: ['default', new FlakyTestsReporter(store)], },})Compatibility
Section titled “Compatibility”The reporter is duck-typed and works with Vitest v1, v2, and v3 without any peer dependency version pinning. It only uses the subset of the reporter API that has been stable since v1: onInit and onFinished.
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 |