Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Vitest - GitHub Actions

Running Vitest in Parallel on GitHub Actions using Matrix Workflow

TL;DR Check out the example repository:

https://github.com/currents-dev/currents-junit-xml-example

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:

.github/workflows /vitest.yml
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.4
  • Get your Record Key and set GH secret variableCURRENTS_RECORD_KEY.

    • Or record without a stored key: with @currents/cmd 3.1.0 or later, give the job permissions: id-token: write, leave out CURRENTS_RECORD_KEY, and set the project ID with --project-id or CURRENTS_PROJECT_ID, not only in the reporter config. See Record from CI with an OIDC token instead of a record key.

  • Update the --project-id argument of npx currents run upload to your project's id.

  • Set --framework-version to the Vitest version installed in the workflow.

Explore

Last updated

Was this helpful?