Vitest - GitHub Actions
Running Vitest in Parallel on GitHub Actions using Matrix Workflow
Currents uses the native Vitest sharding to split the tests between multiple containers. Each shard writes its own JUnit XML report, converts it and uploads it under a shared CI Build ID.
Here's an example workflow configuration file:
name: Run Vitest
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [1, 2]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "24.x"
- name: Install dependencies
run: npm install
- name: Run tests in shard ${{ matrix.shard }}
run: npx vitest run --shard=${{ matrix.shard }}/2 --reporter=default --reporter=junit --outputFile.junit=./results.xml
# `vitest run` exits non-zero on test failures - report the results anyway
- name: Convert and upload test results to Currents.dev
if: always()
# CURRENTS_RECORD_KEY is a secret stored in the repository settings
env:
CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
run: |
npx currents run upload --project-id XXXXXX --ci-build-id ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }} --input-format=junit --input-file=./results.xml --framework=vitest --framework-version=v3.2.4Get your Record Key and set GH secret variable
CURRENTS_RECORD_KEY.Or record without a stored key: with
@currents/cmd3.1.0 or later, give the jobpermissions: id-token: write, leave outCURRENTS_RECORD_KEY, and set the project ID with--project-idorCURRENTS_PROJECT_ID, not only in the reporter config. See Record from CI with an OIDC token instead of a record key.
Update the
--project-idargument ofnpx currents run uploadto your project's id.Set
--framework-versionto the Vitest version installed in the workflow.
Explore
Last updated
Was this helpful?