Skip to content

Example project of using Test Analytics from Codecov with Vitest Browser Mode.

Notifications You must be signed in to change notification settings

kettanaito/test-analytics-vitest

Repository files navigation

Test Analytics in Vitest

Example project of using Test Analytics from Codecov with Vitest Browser Mode.

Getting started

1. Configure Vitest

In vitest.config.ts, make sure to add juint to the list of test reporters and provide the outputFile option to emit the report to the file system:

// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    // ...other options
    reporters: ['default', 'junit'],
    outputFile: './test-report.junit.xml',
  },
})

See full vitest.config.ts for reference.

2. Install Codecov GitHub app

Click here to install the Codecov GitHub app in your project.

3. Upload test report

Create a GitHub Actions workflow that will continuously run your tests and upload the test report to Codecov. Here's an example workflow:

# .github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      # ...other steps

      - name: Upload test results
        if: ${{ !cancelled() }}
        uses: codecov/test-results-action@v1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

See full ci.yml workflow for reference.

Use the "Repository upload token" as the value for the CODECOV_TOKEN environment variable. You can find that value in the "Configuration > General" section of your project on Codecov:

Codecov upload token

Put that value as a new secret for GitHub Actions by going to your GitHub repository, "Settings > Secrets and variables > Actions" and click the "New repository secret" button.

Resources

About

Example project of using Test Analytics from Codecov with Vitest Browser Mode.

Topics

Resources

Stars

Watchers

Forks