# Reporting from CI with Jest

> Create the app token the Probara Jest reporter signs in with, add the reporter to your Jest configuration, and see what it sends.

The **Jest** app sends your Jest test results to Probara from any CI pipeline, with the Probara
reporter for Jest. Each Jest run becomes an automated test run with its results, the test cases it
names and their attachments.

The reporter signs in with an **app token**: a token that belongs to the organization, not to a
person. It uses no seat, and it keeps working when the person who created it leaves. This guide
covers the card in Probara and the setup; the
[reporter's documentation](https://docs.probara.net/en/developers/ci-integrations/jest/) covers every
[reporter option](https://docs.probara.net/en/developers/ci-integrations/jest/configuration/) and test helper.

## Before you start

| You need                                              | Why                                                                                                                         |
| ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| A paid plan (**Pro** or **Enterprise**, or any trial) | Reporting from CI is not part of the Free plan. On Free, its dialog shows **See plans** instead of **Create an app token**. |
| A Probara **owner** or **admin**                      | Only owners and admins can create and manage app tokens. Other members see the card without its tokens.                     |
| A Jest project (Jest 29.6 or later) that runs in CI   | The reporter runs with your tests, in the same `npx jest` command.                                                          |

## Set it up

1. In **Workspace › Integrations**, select the **Jest** card. The dialog lists what the app can do
   and links to this guide.
2. Open the **Access tokens** tab and select **Create an app token**.
3. Enter a **Token name** and select **Create token**. Name it after what uses it — the repository
   or the pipeline — so you know which one to revoke later.
4. Select **Copy token** in **Copy your new token**. This is the only time Probara shows it: store it
   in your CI as a secret named `PROBARA_API_TOKEN` before you select **Done**.
5. Install the reporter in your Jest project:

   ```bash
   npm install --save-dev @probara/jest-reporter
   ```

6. Add it to the reporters of `jest.config.js`, after `default` (the one you read in the terminal),
   and replace `<PROJECT_CODE>` with your project's Project ID, such as `SHOP`:

   ```js
   // jest.config.js
   module.exports = {
     reporters: ['default', ['@probara/jest-reporter', { projectId: '<PROJECT_CODE>' }]],
   };
   ```

   If your configuration is an ES module — `jest.config.mjs`, or `jest.config.js` in a package
   with `"type": "module"` — export the same entry with `export default`:

   ```js
   // jest.config.mjs
   export default {
     reporters: ['default', ['@probara/jest-reporter', { projectId: '<PROJECT_CODE>' }]],
   };
   ```

7. Pass the secret to your tests as the `PROBARA_API_TOKEN` environment variable and run them. For
   example, in GitHub Actions:

   ```yaml
   - name: Run Jest tests
     run: npx jest
     env:
       PROBARA_API_TOKEN: ${{ secrets.PROBARA_API_TOKEN }}
   ```

The token never goes in `jest.config.js`: the reporter reads it from the environment. The card on
the Integrations page shows how many active tokens the app has.

## What the reporter sends

| What                        | How Probara records it                                                                                                                                                                                                                                    |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Results                     | One result per attempt: a test retried with `jest.retryTimes` sends each attempt, in order, and the run case keeps the last outcome. Every attempt stays in the case's history.                                                                           |
| Skipped tests               | Skipped tests and `test.todo` tests are recorded as skipped. When you [run only the tests of a run](#run-only-the-tests-of-a-run), those that match none of its cases are not reported.                                                                   |
| Errors                      | The error of a failed attempt, in the notes of its result.                                                                                                                                                                                                |
| Steps                       | The steps an attempt ran with `probara.step()`, as a tree with their status, duration and error, shown under the result.                                                                                                                                  |
| Attachments                 | The files an attempt attached with `probara.attach()`, on its result — or on the step they were attached in.                                                                                                                                              |
| Links                       | The links an attempt added with `probara.link()`, shown with the result. The issues it named with `probara.issue()` become links only when the reporter's `issueUrlTemplate` option, a URL with `%s` where the issue id goes, turns their ids into links. |
| Parameters                  | The parameters an attempt set with `probara.parameters()`, such as the user or the locale. A name the case declares selects its run case; any other name is shown with the result only.                                                                   |
| New test cases              | A test with no case yet creates one, in a suite named after its test file — with `keyIncludesFile: false`, after its outermost `describe` block, when it has one — unless `probara.suite()` names another.                                                |
| Existing test cases         | An archived case the test reports to is restored. A case found by its automation key moves to the suite the test is in now; a case linked by its ID keeps its suite. Its title, steps and fields are never changed.                                       |
| Fields of a new case        | Its description, tags, steps and fields — system fields such as priority or severity, and custom fields by name. Only when the report creates the case: an existing case is never changed.                                                                |
| Assignees of failed results | With the reporter's `assignFailedTo` option, a failed result is assigned to the people it names, in turn — only when its run case has no assignee yet, and only to members who can work in the project. An existing assignee is never replaced.           |

A field or option Probara does not know, or one deleted while the report runs, is skipped and
answered as a warning, never a failure: the report still records every result. A field with an
empty value is skipped without a warning. An email in `assignFailedTo` that matches no member who
can work in the project is skipped too, with a warning that says only how many were skipped. The
[reporter's documentation](https://docs.probara.net/en/developers/ci-integrations/jest/metadata/) shows how a test sets its
parameters, tags, fields, steps and links.

## Same cases as a JUnit import

If you already send Jest results with `probara import junit` on the report of `jest-junit`, the
reporter finds the same test cases: its automation keys equal those of the import when `jest-junit`
wrote its report with `JEST_JUNIT_ADD_FILE_ATTRIBUTE=true`. If the report had no file attribute, set
the reporter option `keyIncludesFile: false`. Either way, switching to the reporter keeps each test
linked to its case and its history.

## Run only the tests of a run

To run only the tests of a run created in Probara, add the reporter's setup file to your
configuration once:

```js
// jest.config.js
module.exports = {
  reporters: ['default', ['@probara/jest-reporter', { projectId: '<PROJECT_CODE>' }]],
  setupFilesAfterEnv: ['@probara/jest-reporter/setup'],
};
```

Then, only in the job that runs that run's tests, set `PROBARA_RUN_CASES_ONLY` to `true` and
`PROBARA_RUN_ULID` to the run's ULID. For example, in a GitHub Actions workflow you start by hand
with a `run_ulid` input:

```yaml
- name: Run the tests of a Probara run
  run: npx jest
  env:
    PROBARA_API_TOKEN: ${{ secrets.PROBARA_API_TOKEN }}
    PROBARA_RUN_CASES_ONLY: 'true'
    PROBARA_RUN_ULID: ${{ inputs.run_ulid }}
```

The reporter sends the results into that run and leaves it open.

To get the ULID, open the run, select **Run actions** (the menu in the run's header), and choose
**Copy run ULID**; the same item is in each run's menu in the runs list. The reporter option
`runCasesOnly: true` in `jest.config.js` turns on the same selection, but for every job: while it
reports, each job without a ULID then warns and runs every test.

Before the tests start, the reporter reads the run's cases. A test belongs to the run when its
automation key is the key of one of the run's cases, or when its title or one of its `describe`
blocks names one of the run's cases, such as `SHOP-12`. A `probara.id()` call does not count: it
runs with the test, after the selection. Reading the case keys is the one read an app token can
make.

Jest skips every other test, and the reporter does not report it: Jest's summary counts it as
skipped. A test of the run that the file itself skips, with `test.skip` or `test.todo`, is still
reported as skipped.

When the run's cases cannot be read, when no ULID is set, or in a test file the setup file did not
run in, every test runs and is reported, with one warning. The same setup file is what the reporter
option `captureOutput` needs to attach each test's console output to its result.

## Manage tokens

Under **App tokens**, the **Access tokens** tab lists each active token with who created it (or
**Created by a removed user**), when, and when it was last used (**Never** until its first report).

**Revoke** a token, and confirm, when it may have leaked or when someone who could read it leaves
your team: pipelines that use it stop reporting at once, and it cannot be undone. Create a new token
for them first. Because an app token outlives the person who created it, rotating it is your call:
Probara never revokes it on its own.

## What an app token can do

Only what the reporter does: create automated runs, send reports (which can create the test cases
and suites they name), add attachments to their results, close runs, and read the case keys of a
run. It cannot read anything else, cannot remove attachments, and cannot be used with
[Probara MCP](https://docs.probara.net/en/developers/mcp/) or for any other API call. For scripts and other API clients, use
a personal [API token](https://docs.probara.net/en/developers/authentication/).

Runs, activity entries and attachments that an app token created show the app's logo and name beside
the token name — for example **Jest · unit-ci** — in the runs list, the run and milestone summaries,
[Workspace activity](https://docs.probara.net/en/guides/workspace/activity/) and the attachments list.

## When the plan changes

If your organization moves to the Free plan, its app tokens are kept but Probara refuses them, so
pipelines stop reporting; its dialog says so and offers **See plans**. You can still see and revoke the
tokens. They work again as soon as the organization is back on a paid plan, with nothing to set up
again. Manual test runs are not affected.

## Next step

- [Reporter documentation](https://docs.probara.net/en/developers/ci-integrations/jest/) —
  [options](https://docs.probara.net/en/developers/ci-integrations/jest/configuration/),
  [test helpers](https://docs.probara.net/en/developers/ci-integrations/jest/metadata/), links and
  [run selection](https://docs.probara.net/en/developers/ci-integrations/jest/run-selection/).
- [Run cases API](https://docs.probara.net/en/developers/api/run-cases/#list-a-runs-case-keys) — the case keys the reporter
  reads to run only a run's tests.
- [Reports API](https://docs.probara.net/en/developers/api-reference/#reports) — the endpoint the reporter calls, for
  your own tools.
