View as Markdown

Vitest Integration with Mergify

Report your test results from Vitest to Mergify


This guide explains how to integrate Vitest with Test Insights using the @mergifyio/vitest reporter. Once installed, test results are automatically uploaded to Test Insights without any extra workflow changes.

You need to install the @mergifyio/vitest package to automatically upload your test results to Test Insights.

Terminal window
npm install --save-dev @mergifyio/vitest
Terminal window
yarn add --dev @mergifyio/vitest
Terminal window
pnpm add --save-dev @mergifyio/vitest

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

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.

Your workflow should run your tests as usual while exporting the secret MERGIFY_TOKEN as an environment variable.

Add the following to the GitHub Actions step running your tests:

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

For example:

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

Set MERGIFY_TOKEN in the environment of the agents running your tests. The step itself then needs no Mergify-specific configuration:

steps:
- label: "Run Tests 🧪"
command: npm test

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

The reporter applies quarantine through a test runner it installs for you. When a quarantined test fails, that runner records it as passed, so it does not change Vitest’s exit code. The exit code of your test step already accounts for quarantine, so the step needs nothing more:

  • Do not add continue-on-error: true. The recipes that upload a JUnit report with the mergifyio/gha-mergify-ci action need it because the action decides the job’s result after the tests. Here nothing does, so it would let every real failure through.

  • There is no step id to set and no test_step_outcome to pass: both belong to that action, which this setup does not use.

A crash cannot pass for a green run either. Quarantine only covers failing tests. Errors that Vitest reports outside a test result, such as an unhandled error or a test file that fails to load, still make it exit non-zero and fail the step, and so does Vitest dying mid-run. The reporter uploads results when the test run ends, so a process killed outright before then, such as by the out-of-memory killer, sends nothing to Test Insights.

If the reporter cannot fetch the quarantine list, it quarantines nothing for that run, and a quarantined test that fails makes the step fail as usual.

Verify and Review in Test Insights

Section titled Verify and Review in Test Insights

After pushing these changes, your next CI run reports its Vitest results automatically.

You can then review your test results, including any failures or flaky tests, directly in the Test Insights dashboard.

VariablePurposeDefault
MERGIFY_TOKENAPI authentication tokenRequired
MERGIFY_API_URLAPI endpoint locationhttps://api.mergify.com
VITEST_MERGIFY_ENABLEForce-enable outside CIfalse
VITEST_MERGIFY_DEBUGPrint spans to consolefalse
MERGIFY_TRACEPARENTW3C distributed trace contextOptional
MERGIFY_TEST_JOB_NAMETest job name identifierOptional

Was this page helpful?