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 StartedJest

Jest Setup

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

Prerequisites

  • Node.js 18 or later
  • Jest 29 or later
  • A Spekra account with an API key

Installation

Install the Spekra Jest reporter:

npm install @spekra/jest

Configuration

Add the reporter to your jest.config.js or jest.config.ts:

module.exports = {
  reporters: [
    'default',
    ['@spekra/jest', {
      apiKey: process.env.SPEKRA_API_KEY,
      source: 'my-unit-tests', // Required: identifies your test suite
    }],
  ],
  // ... rest of your config
};

Or if you're using TypeScript configuration:

import type { Config } from 'jest';

const config: Config = {
  reporters: [
    'default',
    ['@spekra/jest', {
      apiKey: process.env.SPEKRA_API_KEY,
      source: 'my-unit-tests', // Required: identifies your test suite
    }],
  ],
};

export default config;

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:

npm test

Your test results will appear in your Spekra dashboard.

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
Git infoBranch, commit SHA, author
CI infoJob URL, workflow name

Detecting Flaky Tests

Unlike Playwright's built-in retry mechanism, Jest doesn't retry tests by default. To enable flaky test detection, you have two options:

Option 1: Use jest-retry

npm install jest-retry
module.exports = {
  // Enable retries
  testRetries: 2,
};

Option 2: Run tests multiple times in CI

You can run your test suite multiple times in CI to detect flaky tests:

- name: Run tests (attempt 1)
  run: npm test
  
- name: Run tests (attempt 2)
  run: npm test
  if: always()

Spekra will analyze results across runs to identify tests that pass and fail inconsistently.

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

Playwright

Next

Vitest