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.
Installation
Section titled InstallationYou need to install the
@mergifyio/vitest package
to automatically upload your test results to Test Insights.
npm install --save-dev @mergifyio/vitestyarn add --dev @mergifyio/vitestpnpm add --save-dev @mergifyio/vitestConfiguration
Section titled ConfigurationAdd 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.
Update Your CI Workflow
Section titled Update Your CI WorkflowYour workflow should run your tests as usual while exporting the secret
MERGIFY_TOKEN as an environment variable.
GitHub Actions
Section titled GitHub ActionsAdd 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 testBuildkite
Section titled BuildkiteSet 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 testThe reporter automatically collects your test results and sends them to Test Insights.
Quarantine and Crashed Runs
Section titled Quarantine and Crashed RunsThe 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 themergifyio/gha-mergify-ciaction 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
idto set and notest_step_outcometo 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 InsightsAfter 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.
Environment Variables
Section titled 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 |
Was this page helpful?
Thanks for your feedback!