Skip to content

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.

  1. Install the plugin and a store

    Terminal window
    npm i -D @flaky-tests/plugin-vitest @flaky-tests/store-sqlite
  2. Add the reporter to vitest.config.ts

    vitest.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 IStore instance — swap SqliteStore for any other adapter (Turso, Supabase, Postgres) with the same shape.

  3. Run your tests

    Terminal window
    npx vitest run

    Failures are written to node_modules/.cache/flaky-tests/failures.db.

Pass any store that implements IStore as the reporter’s positional argument:

vitest.config.ts
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)],
},
})

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.

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