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

import vitestLogo from "../../../images/ci-insights/vitest/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={vitestLogo} alt="Vitest logo" />

This guide shows how to configure [Vitest](https://vitest.dev/) to produce
JUnit reports and upload them to CI Insights within a GitHub Actions workflow.

## Generate a JUnit Report with Vitest

By default, Vitest doesn't generate JUnit-format test results. You need to
enable it in your `vite.config.ts` or `vitest.config.ts`.

This is [documenteded on vitest
website](https://vitest.dev/guide/reporters#junit-reporter).

For example:

```javascript
export default defineConfig(({ mode }) => {
  return {
    test: {
      reporters: ['default', 'junit'],
      outputFile: './junit.xml',
      includeConsoleOutput: true,
    },
  };
});
```

Key Options:

- `reporters: ['default', 'junit']`: Tells Vitest to generate JUnit reports
  alongside the standard console output.

- `outputFile: './junit.xml'`: Sets the path where Vitest writes the test
  results (you can rename or relocate as you prefer).

- `includeConsoleOutput: true`: Ensures console logs are captured in the final
  report.

## Update Your GitHub Actions Workflow

<CIInsightsSetupNote />

Once you have the JUnit file produced by Vitest, add a step to upload these
results to **CI Insights** via the `mergifyio/gha-mergify-ci` action.

In the workflow file where vitest is launched, after running `npm run test` (or
similar), include a step like:

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

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

<GhaMergifyCiQuarantineSetup />

## Verify and Review in CI Insights

After pushing these changes:

1. Your GitHub Actions workflow will run tests with Vitest.
2. Vitest generates junit.xml.
3. The Mergify CI action uploads that file to CI Insights.

You can then see your test results, including failures and flaky tests,
directly in the CI Insights dashboard.

## Troubleshooting Tips

<ul>
  <CommonTroubleshootingTips />
</ul>
