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
DocsReportersJest Config

Jest Configuration

Complete reference for all configuration options available in the @spekra/jest reporter.

Full Example

module.exports = {
  reporters: [
    'default',
    ['@spekra/jest', {
      // Required
      apiKey: process.env.SPEKRA_API_KEY,
      source: 'my-unit-tests',
      
      // Optional
      apiUrl: 'https://spekra.dev/api/reports',
      enabled: process.env.CI === 'true',
      debug: false,
      failOnError: false,
    }],
  ],
};

Options Reference

apiKey
string
required

Your Spekra API key. Get one from Settings → API Keys.

We recommend using an environment variable rather than hardcoding the key.

source
string
required

Identifies your test suite in Spekra. Use a descriptive, stable name like 'frontend-unit-tests' or 'api-integration'.

Changing the source creates a new grouping in Spekra, so keep it stable.

apiUrl
string
optional
Default: https://spekra.dev/api/reports

The Spekra API endpoint. Only change this if you're using a self-hosted instance.

enabled
boolean
optional
Default: true

Whether to send results to Spekra. Set to false to disable reporting.

Common pattern: enabled: process.env.CI === 'true' to only report in CI.

debug
boolean
optional
Default: false

Enable verbose logging for troubleshooting.

failOnError
boolean
optional
Default: false

Fail the Jest run if reporting fails. Useful for ensuring test results are always captured in CI.

onError
(error: SpekraError) => void
optional

Callback invoked when reporting fails (after all retries). Useful for custom error handling or alerting.

onMetrics
(metrics: SpekraMetrics) => void
optional

Callback to receive reporter metrics like requests sent, latency, and bytes transferred.

Environment Variables

The reporter respects these environment variables (Jest-specific vars take priority):

VariableDescription
SPEKRA_JEST_API_KEYAPI key (Jest-specific)
SPEKRA_API_KEYAPI key (fallback)
SPEKRA_JEST_SOURCESource identifier
SPEKRA_JEST_ENABLEDSet to 'false' to disable reporting
SPEKRA_JEST_DEBUGSet to 'true' for verbose logging
SPEKRA_JEST_FAIL_ON_ERRORSet to 'true' to fail on reporting errors

CI-Only Reporting

['@spekra/jest', {
  apiKey: process.env.SPEKRA_API_KEY,
  enabled: !!process.env.CI,
}]

With setupFilesAfterEnv

If you need to configure the reporter dynamically:

module.exports = {
  reporters: [
    'default',
    ['@spekra/jest', {
      apiKey: process.env.SPEKRA_API_KEY,
    }],
  ],
  setupFilesAfterEnv: ['./jest.setup.js'],
};

Using with Jest Projects

If you use Jest's projects feature:

module.exports = {
  projects: [
    {
      displayName: 'unit',
      testMatch: ['<rootDir>/src/**/*.test.ts'],
      reporters: [
        'default',
        ['@spekra/jest', {
          apiKey: process.env.SPEKRA_API_KEY,
        }],
      ],
    },
    {
      displayName: 'integration',
      testMatch: ['<rootDir>/integration/**/*.test.ts'],
      reporters: [
        'default',
        ['@spekra/jest', {
          apiKey: process.env.SPEKRA_API_KEY,
        }],
      ],
    },
  ],
};

Each project will send results with its displayName as metadata, helping you distinguish results in Spekra.

Troubleshooting

Results Not Appearing

  1. Verify enabled is true (or not set)
  2. Check your API key is valid
  3. Enable debug: true to see logs
  4. Ensure network access to spekra.dev

Slow Test Completion

If tests seem to hang at the end:

  1. Check network connectivity
  2. Reduce timeout value
  3. Look for firewall issues

Previous

Jest

Next

Vitest