---
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 IntegrationLogo from "../../../../components/IntegrationLogo.astro"
import CIInsightsSetupNote from "../../../../components/CIInsightsSetupNote.astro"

<IntegrationLogo src={vitestLogo} alt="Vitest logo" />

This guide explains how to integrate [Vitest](https://vitest.dev/) with CI
Insights using the `@mergifyio/vitest` reporter. Once installed, test results
are automatically uploaded to CI Insights without any extra workflow changes.

## Installation

You need to install the
[`@mergifyio/vitest`](https://www.npmjs.com/package/@mergifyio/vitest) package
to automatically upload your test results to **CI Insights**.

### npm

```bash
npm install --save-dev @mergifyio/vitest
```

### yarn

```bash
yarn add --dev @mergifyio/vitest
```

### pnpm

```bash
pnpm add --save-dev @mergifyio/vitest
```

## Configuration

Add the Mergify reporter to your `vitest.config.ts` (or `vite.config.ts`):

```typescript
import { defineConfig } from 'vitest/config';
import MergifyReporter from '@mergifyio/vitest';

export default defineConfig({
  test: {
    reporters: ['default', new MergifyReporter()],
  },
});
```

The `'default'` reporter keeps the standard console output alongside the
Mergify reporter.

## Modify Your Workflow

<CIInsightsSetupNote />

Your workflow should run your tests as usual while exporting the secret
`MERGIFY_TOKEN` as an environment variable. You'll need to add the following
code to the GitHub Actions step running your tests:

```yaml
env:
  MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}
```

For example:

```yaml
- name: Run Tests 🧪
  env:
    MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}
  run: npm test
```

The reporter automatically collects your test results and sends them to CI
Insights.

Check the CI Insights dashboard afterward to view execution metrics, detect
flaky tests, and gather actionable feedback.

## Environment Variables

| Variable | Purpose | Default |
|----------|---------|---------|
| `MERGIFY_TOKEN` | API authentication token | **Required** |
| `MERGIFY_API_URL` | API endpoint location | `https://api.mergify.com` |
| `VITEST_MERGIFY_ENABLE` | Force-enable outside CI | `false` |
| `VITEST_MERGIFY_DEBUG` | Print spans to console | `false` |
| `MERGIFY_TRACEPARENT` | W3C distributed trace context | Optional |
| `MERGIFY_TEST_JOB_NAME` | Test job name identifier | Optional |

:::tip
  The reporter auto-activates in CI environments (detected via the `CI`
  environment variable). To enable it outside CI, set
  `VITEST_MERGIFY_ENABLE=true`.
:::

:::tip
  Use `MERGIFY_TEST_JOB_NAME` to make reports clearer in CI Insights,
  especially when running multiple test suites or using a matrix strategy.
:::
