@probara/vitest-reporter
v0.4.0
Published
Vitest reporter that sends every test result to Probara.
Maintainers
Readme
A Vitest reporter that sends every test result of a run to
Probara: each attempt with its status, duration and errors, linked to its
Probara test case, with the steps, attachments and links your tests add. Cases that are missing get
created, and the run is closed once everything is in. Built on
@probara/core.
Features
- One result per attempt,
retryandrepeatsincluded, with Vitest's own verdict:test.fails,skip,todo(sent as skipped, with the noteTodo),context.skip(note). - The same keys as
probara import juniton Vitest's JUnit output, so switching from the JUnit import keeps every case and its history (same cases as the JUnit import). - Linking by a case id in a title or a
describe(SHOP-12 adds an item) orprobara.id(). - Test helpers with nothing to set up, in Node (
test.concurrentincluded) and in browser mode:probara.step()(nested, with expected results and data),probara.attach(),probara.link(),probara.issue(),probara.parameters(), and the title, suite, tags and fields of a new case. - Vitest's own files: the attachments of
context.annotate(), the failure screenshots of browser mode, and each attempt's console output withcaptureOutput(attachments, captured output). - Visual testing in browser mode with
probaraSnap(name): screenshots compared between commits in Probara Snap (Probara Snap). - Runs by name, with an environment, milestone, test plan, configurations and tags
(run options); one run for a sharded CI job, merged from the blobs
(sharding); one run per
--watchsession (watch mode); only the tests of a Probara run, withrunCasesOnly(run selection). - Never breaks your test run: a reporting problem is logged, never thrown, and Vitest's exit
code stays the tests' own. What could not be sent can be kept in a file and sent later with
probara import results 'probara-results*.json'.
Requirements
- Node.js 22.12 or later.
- Vitest 3.2 or a later 3.x, 4.x or 5.x (the peer range
^3.2.0 || ^4.0.0 || ^5.0.0). Browser mode needs the browser provider of the same Vitest version (browser mode). - A Probara app token, created from the Vitest card in Integrations
(get a token), and the code of the project to report into
(such as
SHOP). Reporting from CI needs a paid plan.
Install
npm install --save-dev @probara/vitest-reporterQuick start
In Probara, open Workspace › Integrations, pick the Vitest card and create a token (get a token). Store it as a CI secret named
PROBARA_API_TOKEN: the reporter reads it from the environment, never from the config.In the
testsection ofvitest.config.mts, add the reporter afterdefault(the one you read in the terminal), with your project code (or setPROBARA_PROJECTinstead):reporters: ['default', ['@probara/vitest-reporter', { projectId: 'SHOP' }]],The reporter adds its own setup file and runner to every Vitest project: there is nothing to add to
setupFilesorrunner(configuration).Run your tests with the token in the environment. In GitHub Actions (every CI guide):
- name: Run Vitest tests run: npx vitest run env: PROBARA_API_TOKEN: ${{ secrets.PROBARA_API_TOKEN }}
The reporter logs on stderr, in [probara] lines, and ends with the link to the run:
$ npx vitest run
[probara] Sending 3 results of 3 tests (3 passed, 0 failed, 0 skipped, 0 blocked)
[probara] Recorded 3 results (2 new cases, 0 unmatched) in R-1 (closed): https://app.probara.net/projects/SHOP/runs/R-1Without a token, nothing is sent and the tests run as usual: with no project either, the reporter stays quiet; with a project, it says in one line that the token is not set (what happens with each setup).
A sharded CI job writes one blob per shard, with the reporter beside blob, and one job merges
them into one run (sharding):
npx vitest run --shard=1/2 --reporter=blob --reporter=@probara/vitest-reporter
npx vitest run --shard=2/2 --reporter=blob --reporter=@probara/vitest-reporter
npx vitest --merge-reportsWhat gets reported
| Vitest | In Probara |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| A test, or a row of test.each and test.for (its title is its key) | A test case, matched by its automation key or linked by a case id |
| Each attempt (retry) and each execution (repeats) | A result in the run, with its status, duration, start time and errors |
| skip, skipIf, runIf, a test .only or -t left out, todo, context.skip() | A skipped result (Todo, or Skipped: <note>, in the notes) |
| probara.step() calls | The steps of the result, nested, with their status, duration and error |
| probara.attach(), context.annotate() files, failure screenshots, captureOutput | Files of the result, or of the step they were attached in |
| probara.link(), probara.issue() | Links of the result |
| Other probara.* calls, Vitest tags | The title, suite, tags, fields and steps of a new case; result parameters |
| A beforeAll or afterAll hook that throws, a test file that fails to load | One failed result, as Vitest's JUnit output writes it |
| The vitest run command | One automated run, named after the CI build, closed at the end |
An unhandled error (a rejection no test awaited) is no result: one warning counts them (statuses).
The project, attempt and repeat of an execution are context values: shown on its result, they never create a parameter of a new case.
A row's values are in its title, so each row is a case of its own unless the rows share one title. To
keep the rows of one test as one case, give them one title and declare each row's values with
probara.parameters() inside the test: the values are sent with the result, and Probara matches each
row to the parameter set the case declares.
A test that attaches a file sends it with its result:
// tests/attach.test.ts
import { probara } from '@probara/vitest-reporter';
import { expect, it } from 'vitest';
it('attaches the receipt', async () => {
await probara.attach({ name: 'receipt', body: 'paid 12.00', contentType: 'text/plain' });
expect(1).toBe(1);
});receipt.txt text/plainA watch session reports every re-run into one run, which stays open (watch mode):
$ npx vitest --watch
[probara] Sending 3 results of 3 tests (3 passed, 0 failed, 0 skipped, 0 blocked)
[probara] Recorded 3 results (2 new cases, 0 unmatched) in R-1 (open): https://app.probara.net/projects/SHOP/runs/R-1
[probara] Watch mode: every re-run reports into R-1 of SHOP, which stays open: close it in Probara, or with probara run close --project SHOP --run-ulid 01J9Z3K4M5N6P7Q8R9S0T1V2W3
[probara] Sending 2 results of 2 tests (2 passed, 0 failed, 0 skipped, 0 blocked)
[probara] Recorded 2 results (0 new cases, 0 unmatched) in R-1 (open): https://app.probara.net/projects/SHOP/runs/R-1Same cases as the JUnit import
The reporter gives each test the automation key probara import junit gives it on Vitest's own
JUnit output (vitest run --reporter=junit): the test file, then the describe blocks and the
title, each after > between spaces, without the case ids. For a tests/cart.test.ts whose
describe('cart') holds it('SHOP-12 adds an item') and it('removes an item'), and a
tests/login.test.ts whose describe('login') holds it('logs in with a valid password'), the
reporter sends:
[
{
"automationKey": "tests/cart.test.ts > cart > adds an item",
"status": "passed",
"caseDisplayId": "SHOP-12"
},
{
"automationKey": "tests/cart.test.ts > cart > removes an item",
"status": "passed"
},
{
"automationKey": "tests/login.test.ts > login > logs in with a valid password",
"status": "passed"
}
]Vitest's JUnit output always names the file, so the default, keyIncludesFile: true, gives the
keys of the import; keyIncludesFile: false leaves the file out, for cases whose keys were made
without it (keys without the file). A test keeps its case and
its history when you switch from the JUnit import, on Vitest 3, 4 and 5
(migrating from the JUnit import); an import by CLI 0.3.0 or
earlier keyed a file that failed to load differently
(cases made by an earlier import).
Documentation
| Page | What it covers |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Configuration | Every option, its variable, type and default; precedence; getting a token |
| Linking tests to cases | Case ids in titles and describes, probara.id(), automation keys, test.each and test.for |
| Metadata | Title, suite, comment, tags, fields, parameters, ignoring an attempt; the differences from the Jest API |
| Steps | probara.step(): nesting, status, errors, promises, the steps of a new case |
| Attachments | probara.attach(), files of steps, Vitest annotations, failure screenshots, limits |
| Captured output | captureOutput: each attempt's console output, silent and onConsoleLog |
| Links | probara.link(), probara.issue() and issueUrlTemplate |
| Statuses | How attempts become statuses; todo, test.fails, hooks, --bail; mapping and filter |
| Retries and repeats | Every attempt and every repeat is a result |
| Run options | Name, description, environment, milestone, plan, configurations, tags, an existing run, closing |
| Sharding and CI | One run for every shard: blob reports merged, or one run shared by the shards |
| GitHub Actions | The secret, the test step, sharded jobs merged from their blobs, fork pull requests |
| GitLab CI | The variable, the test job, parallel: shards merged from their blobs, fork merge requests |
| CircleCI | A context, parallelism shards reporting into one run, forks |
| Azure Pipelines | The secret variable, parallel jobs reporting into one run, forks |
| Jenkins | withCredentials, parallel stages reporting into one run, fork pull requests |
| Bitbucket Pipelines | A secured variable, parallel steps reporting into one run, forks |
| Buildkite | The agents' secrets, parallelism jobs reporting into one run, fork pull requests |
| Vitest projects and Probara projects | Vitest projects, the project parameter, results that go to other Probara projects |
| Watch mode | One run per --watch session |
| Run selection | runCasesOnly: run only the tests of a Probara run |
| Assign failed results | assignFailedTo: who looks into failures |
| Results file | Keep what could not be sent, send it later |
| Browser mode | The providers, the helpers in a browser, probara.attach() and Vite's file rules |
| Probara Snap | probaraSnap(): screenshots compared between commits, masking, shards |
| Migrating from the JUnit import | From --reporter=junit and probara import junit, keeping every case |
| Migrating from Qase | Option by option and call by call, what is different, what is not ported |
| Coming from other tools | Allure, ReportPortal and TestRail, mapped, and what is not supported |
| Troubleshooting | Problems and their solutions; every line the reporter logs |
| Debugging | PROBARA_DEBUG, the logs, checking what would be sent |
| Network | Requests, timeouts, retries, rate limits, proxies and certificates |
| Upgrading | Versioning policy, the automation key contract, Vitest versions |
| Changelog | What changed in each version |
On the Probara side, the Vitest integration guide covers the card, its app tokens and what Probara shows.
Reporting never breaks your test run
The reporter never throws into Vitest and never changes its exit code: a failed test fails the
command, a reporting problem does not. Every problem (a wrong setting, Probara unreachable, a
refused token) is logged on stderr, never with the token, and the tests keep their outcome.
probara.* calls never throw into a test either: a call Probara cannot use is left out with a
warning. There is no option to fail the command on a reporting error; to keep what could not be
sent, set a results file (resultsFile).
