---
title: Jest Integration with CI Insights
description: Report your test results from Jest tests to CI Insights
---

import jestLogo from "../../../images/ci-insights/jest/logo.svg"
import CommonTroubleshootingTips from "./_common-troubleshooting-tips.mdx"
import GhaMergifyCiQuarantineSetup from "./_gha_mergify_ci_quarantine_setup.mdx"
import IntegrationLogo from "../../../../components/IntegrationLogo.astro"
import MergifyCIUploadStep from "../../../../components/MergifyCIUploadStep.astro"
import CIInsightsSetupNote from "../../../../components/CIInsightsSetupNote.astro"
import MergifyCIUploadStepMatrix from "../../../../components/MergifyCIUploadStepMatrix.astro"

<IntegrationLogo src={jestLogo} alt="Jest logo" />

This guide shows how to generate JUnit reports from your Jest tests and upload
them to **CI Insights** using a GitHub Actions workflow.

## Generate a JUnit Report with Jest

Jest has built-in support for JUnit XML reports. You can configure Jest to
output JUnit reports by updating your Jest configuration or using command-line
options.

### Using Jest Configuration

Add the following to your `jest.config.js` or `package.json`:

```javascript
// jest.config.js
module.exports = {
  reporters: [
    'default',
    ['jest-junit', {
      outputDirectory: '.',
      outputName: 'junit.xml'
    }]
  ]
};
```

First, install the `jest-junit` reporter:

```bash
npm install --save-dev jest-junit
```

### Using Command Line Options

```bash
npx jest --reporters=default --reporters=jest-junit
```

You can also set the output file location:

```bash
JEST_JUNIT_OUTPUT_DIR=. JEST_JUNIT_OUTPUT_NAME=junit.xml npx jest --reporters=default --reporters=jest-junit
```

## Update Your GitHub Actions Workflow

<CIInsightsSetupNote />

After generating the JUnit report, add a step to upload the results to CI
Insights using the mergifyio/gha-mergify-ci action.

For example, in your workflow file:

```yaml
- name: Run Jest Tests and Generate JUnit Report
  continue-on-error: true
  env:
    JEST_JUNIT_OUTPUT_DIR: .
    JEST_JUNIT_OUTPUT_NAME: junit.xml
  run: npx jest --reporters=default --reporters=jest-junit
```

<MergifyCIUploadStep reportPath="junit.xml" />
<MergifyCIUploadStepMatrix reportPath="junit.xml" />

<GhaMergifyCiQuarantineSetup />

## Verify and Review in CI Insights

After pushing these changes:

1. Your GitHub Actions workflow will execute your Jest tests.
2. A JUnit report (`junit.xml`) is generated.
3. The Mergify CI action uploads the report to CI Insights.

You can then review your test results, including any failures or flaky tests,
directly in the [CI Insights
dashboard](https://dashboard.mergify.com/ci-insights/jobs).

## Troubleshooting Tips

<ul>
  <li>Jest Configuration: Ensure `jest-junit` is properly installed and configured in your Jest setup.</li>

  <CommonTroubleshootingTips />
</ul>
