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
apiKeyYour Spekra API key. Get one from Settings → API Keys.
We recommend using an environment variable rather than hardcoding the key.
sourceIdentifies 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.
apiUrlhttps://spekra.dev/api/reportsThe Spekra API endpoint. Only change this if you're using a self-hosted instance.
enabledtrueWhether to send results to Spekra. Set to false to disable reporting.
Common pattern: enabled: process.env.CI === 'true' to only report in CI.
debugfalseEnable verbose logging for troubleshooting.
failOnErrorfalseFail the Jest run if reporting fails. Useful for ensuring test results are always captured in CI.
onErrorCallback invoked when reporting fails (after all retries). Useful for custom error handling or alerting.
onMetricsCallback to receive reporter metrics like requests sent, latency, and bytes transferred.
Environment Variables
The reporter respects these environment variables (Jest-specific vars take priority):
| Variable | Description |
|---|---|
SPEKRA_JEST_API_KEY | API key (Jest-specific) |
SPEKRA_API_KEY | API key (fallback) |
SPEKRA_JEST_SOURCE | Source identifier |
SPEKRA_JEST_ENABLED | Set to 'false' to disable reporting |
SPEKRA_JEST_DEBUG | Set to 'true' for verbose logging |
SPEKRA_JEST_FAIL_ON_ERROR | Set 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
- Verify
enabledistrue(or not set) - Check your API key is valid
- Enable
debug: trueto see logs - Ensure network access to
spekra.dev
Slow Test Completion
If tests seem to hang at the end:
- Check network connectivity
- Reduce
timeoutvalue - Look for firewall issues