Others (JUnit XML)

Reporting your JUnit XML tests to Currents in CI

Unit tests are usually executed in CI environments and can be reported to Currents by currents upload command in @currents/cmd package.

The process is the same for all the JUnit XML files that will be reported to Currents:

  1. Generate test results into JUnit XML file/files

  2. Merge all result XML files into a single JUnit XML report file called currents.results.xml

  3. Generate Instance files from currents.results.xml

  4. Call currents upload command and report the results.

We have included currents convert command that allows Postman results.

This example repository has a vitest test suite executed in a sharded CI environment.

name: Vitest Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

jobs:
  test:
    runs-on: ubuntu-latest
    environment: test
    strategy:
      matrix:
        shard: [1, 2]
        total-shards: [2]

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "18"
          cache: "npm"

      - name: Install dependencies
        run: npm i

      - name: Run Vitest Tests (Shard ${{ matrix.shard }}/${{ matrix.total-shards }})
        continue-on-error: true
        run: npx vitest --run --shard=${{ matrix.shard }}/${{ matrix.total-shards }} vitest-sharded-example/tests/** --reporter=junit --outputFile=./vitest-sharded-example/results-${{ matrix.shard }}.xml

      - name: Combine Vitest Sharded results
        run: node ./scripts/combineResults.js --reports-dir vitest-sharded-example --output-file vitest-sharded-example/currents.results.xml

      - name: Generate Instance files
        run:  node scripts/junitXmlToInstanceJson.js --input vitest-sharded-example/currents.results.xml --output vitest-sharded-example/instances

      - name: Report Vitest Sharded results
        env:
          CURRENTS_KEY: ${{ secrets.CURRENTS_KEY }}
          CURRENTS_PROJECT_ID: ${{ secrets.CURRENTS_PROJECT_ID }}
          CURRENTS_CI_BUILD_ID: ${{ github.run_id }}-${{ github.run_number }}
        run: node scripts/uploadResults.js --report-dir vitest-sharded-example

CI Build ID

See CI Build ID guide for details.

Git Information

In a CI environment, some variables are collected by the currents upload command. The ci-build-id will be automatically generated using the collected CI data.

The Git information will also be retrieved from the CI environment

Last updated