Spekra
Docs

Getting Started

  • Overview
  • Playwright
  • Jest
  • Vitest

Core Concepts

  • Flaky Tests
  • Stability Metrics
  • Test Identity

Reporters

  • Playwright
  • Playwright Config
  • Jest
  • Jest Config
  • Vitest
  • Vitest Config

Platform

  • Dashboard
  • Flaky Tests View
  • Test Runs
  • API Keys
  • Rate Limits

CI/CD

  • Overview
  • GitHub Actions
  • GitLab CI

Security

  • Overview
  • Data Handling
  • Compliance

Troubleshooting

  • Overview
  • Connection Issues
  • Missing Data
DocsGetting StartedVitest

Vitest Setup

Integrate Spekra with your Vitest test suite to track test stability and identify flaky tests.

Prerequisites

  • Node.js 20 or later
  • Vitest 1.x
  • A Spekra account with an API key

Installation

Install the Spekra Vitest reporter:

npm install @spekra/vitest

Configuration

Add the reporter to your vitest.config.ts:

import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    reporters: [
      'default',
      ['@spekra/vitest', {
        apiKey: process.env.SPEKRA_API_KEY,
        source: 'my-unit-tests', // Required: identifies your test suite
      }],
    ],
  },
});

Set Your API Key

Add your API key to your environment:

export SPEKRA_API_KEY=sk_your_api_key_here

Secure your API key

Never commit your API key to source control. Use environment variables or a secrets manager in CI.

Run Your Tests

Run your tests as usual:

npx vitest run

Your test results will appear in your Spekra dashboard.

Watch mode

The reporter only sends results when running vitest run. Watch mode (vitest without run) does not report results to avoid noise from continuous reruns.

What Gets Captured

The reporter automatically captures:

DataDescription
Test resultsPass, fail, skip status
DurationHow long each test took
Suite pathDescribe block hierarchy
Test filePath to the test file
ProjectVitest workspace name (if using workspaces)
Git infoBranch, commit SHA
CI infoJob URL, workflow name

Workspace Support

If you're using Vitest Workspaces, the reporter automatically captures the workspace name:

// vitest.workspace.ts
export default [
  'packages/*',
];

Each test result will include the workspace/project name, allowing you to filter by project in the Spekra dashboard.

Detecting Flaky Tests

Vitest supports test retries which helps with flaky test detection:

export default defineConfig({
  test: {
    retry: 2, // Retry failed tests up to 2 times
    reporters: [
      'default',
      ['@spekra/vitest', {
        apiKey: process.env.SPEKRA_API_KEY,
        source: 'my-unit-tests',
      }],
    ],
  },
});

Spekra tracks retry attempts and identifies tests that pass after retrying as potentially flaky.

Next Steps

  • Configuration options - All available reporter options
  • CI/CD integration - Set up reporting in your CI pipeline
  • Understanding flaky tests - Learn how Spekra detects flaky tests

Previous

Jest

Next

Flaky Tests