@probara/jest-reporter
v0.3.3
Published
Jest reporter that sends every test result to Probara.
Maintainers
Readme
A Jest reporter that sends every test result of a run to
Probara: each attempt with its status, duration and error, 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,
jest.retryTimesretries included, with Jest's own verdict:test.failing,test.skip,test.todo(sent as skipped, with the noteTodo). - The same keys as
probara import juniton jest-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 that work in every worker,
nodeandjsdomalike: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. - Console output of each test attached with
captureOutput(attachments), and run selection: only the tests of a Probara run, withrunCasesOnly(run selection). - Runs by name, with an environment, milestone, test plan, configurations and tags
(run options); one run for every shard of a sharded CI job
(sharding); one run per
--watchsession (watch mode). - Never breaks your test run: a reporting problem is logged, never thrown, and Jest'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'.
More framework reporters are on the way. Until then, any tool that writes JUnit XML reports through the CLI.
Requirements
- Node.js 22.12 or later.
- Jest 29.6 or later. The
probara.*helpers and the setup file need jest-circus, Jest's default test runner (nottestRunner: 'jest-jasmine2'). - A Probara app token, created from the Jest 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/jest-reporterQuick start
In Probara, open Workspace › Integrations, pick the Jest 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.Add the reporter after
default(the one you read in the terminal), with your project code (or setPROBARA_PROJECTinstead):// jest.config.js module.exports = { reporters: ['default', ['@probara/jest-reporter', { projectId: 'SHOP' }]], };A config that is an ES module (
jest.config.mjs, orjest.config.jsin a package with"type": "module") exports the same entry:// jest.config.mjs export default { reporters: ['default', ['@probara/jest-reporter', { projectId: 'SHOP' }]], };Run your tests with the token in the environment. In GitHub Actions:
- name: Run Jest tests run: npx jest env: PROBARA_API_TOKEN: ${{ secrets.PROBARA_API_TOKEN }}
Without a token and a project the reporter stays off and quiet, so local runs send nothing. In CI
it logs on stderr, in [probara] lines, and ends with the link to the run:
$ npx jest
[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-1What gets reported
| Jest | In Probara |
| ---------------------------------------------------- | ------------------------------------------------------------------------- |
| A test | A test case, matched by its automation key or linked by a case id |
| Each attempt (jest.retryTimes retries too) | A result in the run, with its status, duration, start time and error |
| test.skip, test.todo, a skipped describe | A skipped result (Todo in the notes of a todo) |
| probara.step() calls | The steps of the result, nested, with their status, duration and error |
| probara.attach(), the console with captureOutput | Files of the result, or of the step they were attached in |
| probara.link(), probara.issue() | Links of the result |
| Other probara.* calls in the test | The title, suite, tags, fields and steps of a new case; result parameters |
| A test file whose afterAll hook throws | One more failed result, as jest-junit writes it |
| The jest command | One automated run, named after the CI build, closed at the end |
A test file Jest cannot run (a syntax error, a failing import) has no tests to report: the reporter names it in one warning (statuses).
The title of a test.each row holds its values, 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.
Same cases as the JUnit import
The reporter gives each test the automation key probara import junit gives it on the report of
jest-junit written with
JEST_JUNIT_ADD_FILE_ATTRIBUTE=true: the test file, then > between spaces, then the describe
blocks and the title joined by spaces, without the case ids. For these two test files:
// tests/cart.test.js
describe('cart', () => {
test('SHOP-12 adds an item', () => {
expect([1, 2]).toHaveLength(2);
});
test('removes an item', () => {
expect([1].filter((item) => item !== 1)).toEqual([]);
});
});// tests/login.test.js
describe('login', () => {
test('logs in with a valid password', () => {
expect('secret').toHaveLength(6);
});
});the reporter sends:
[
{
"automationKey": "tests/cart.test.js > cart adds an item",
"caseDisplayId": "SHOP-12",
"status": "passed"
},
{ "automationKey": "tests/cart.test.js > cart removes an item", "status": "passed" },
{
"automationKey": "tests/login.test.js > login logs in with a valid password",
"status": "passed"
}
]If your jest-junit reports had no file attribute (its default), set keyIncludesFile: false: the
keys then leave the file out, like those reports (configuration).
Either way, a test keeps its case and its history when you switch from the JUnit 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 |
| Metadata | Title, suite, comment, tags, fields, parameters, ignoring an attempt; where helpers work |
| Steps | probara.step(): nesting, status, errors, promises, the steps of a new case |
| Attachments | probara.attach(), files of steps, console output, limits |
| Links | probara.link(), probara.issue() and issueUrlTemplate |
| Statuses | How attempts become statuses; todo, test.failing, afterAll; mapping and filter |
| Retries and flaky tests | Every attempt is a result |
| Run options | Name, description, environment, milestone, plan, configurations, tags, an existing run, closing |
| Sharding and CI | One run for every shard |
| Jest and Probara projects | Jest projects, {displayName}, 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 |
| Migrating from the JUnit import | From jest-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 | Test IT, ReportPortal, Allure and TestRail, mapped, and what is not ported |
| 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, Jest versions |
| Changelog | What changed in each version |
CI guides: GitHub Actions, GitLab CI, CircleCI, Azure Pipelines, Jenkins, Bitbucket Pipelines and Buildkite.
On the Probara side, the Jest integration guide covers the card, its app tokens and what Probara shows.
Reporting never breaks your test run
The reporter never throws into Jest 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, 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).
