Vitest Reporter
The @spekra/vitest reporter integrates with Vitest to capture test results and send them to Spekra for flaky test detection and stability tracking.
Installation
npm install @spekra/vitestBasic Configuration
Add the reporter to your Vitest configuration:
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
}],
],
},
});
How It Works
The reporter hooks into Vitest's test lifecycle:
- On init - Initializes when Vitest starts (skips if in watch mode)
- On task update - Captures individual test outcomes as they complete
- On finished - Batches and sends all results to Spekra
Non-Blocking Design
Like the Playwright and Jest reporters, the Vitest reporter is designed to be non-intrusive:
- Results are sent asynchronously after tests complete
- Network failures don't fail your build (unless
failOnErroris enabled) - Aggressive timeouts prevent hanging
Watch Mode
The reporter automatically disables itself in watch mode (vitest without run). This prevents noise from continuous test reruns during development. Results are only sent when running vitest run.
Data Captured
The reporter captures:
| Field | Source | Example |
|---|---|---|
testFile | Test location | src/utils/format.test.ts |
fullTitle | Suite + test name | formatCurrency > handles zero values |
suitePath | Describe hierarchy | ['formatCurrency'] |
testName | It/test title | handles zero values |
project | Workspace name | web-app |
status | Test outcome | passed, failed, skipped |
durationMs | Execution time | 12 |
retry | Retry attempt | 0, 1, 2... |
error | Failure message | Expected true, got false |
Git & CI Information
The reporter also captures:
- Git branch and commit SHA
- CI provider and job URL
- Shard information (when using
--shard)
Workspace Support
Vitest workspaces are fully supported. The workspace name is captured as the project field:
// vitest.workspace.ts
export default [
'packages/web-app',
'packages/utils',
];
Tests from different workspaces will have their respective workspace names, allowing you to filter and analyze them separately in Spekra.
Sharding Support
When using Vitest's built-in sharding, shard information is automatically captured:
vitest run --shard=1/3
The reporter captures shardIndex and totalShards to properly aggregate results across parallel shards.
Differences from Playwright and Jest
Similar to Jest
The Vitest reporter follows the same pattern as the Jest reporter:
- Requires a
sourceidentifier - Sends all results at the end of the run
- No artifact uploads (traces, screenshots)
Workspace Support
Unlike Jest, Vitest has native workspace support similar to Playwright's projects. The workspace name is captured automatically.