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 as an environment variable in your pipeline step:

steps:
- label: "Run Tests 🧪"
command: npm test
env:
MERGIFY_TOKEN: "${MERGIFY_TOKEN}"

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

Check the Test Insights dashboard afterward to view execution metrics, detect flaky tests, and review test trends.

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?