DEV Community

loading...

Measuring Code Coverage in React, with CodeCov Github Action

stud2design profile image Pushpendra Singh ・1 min read

In my previous post I added Github Workflow to run test on every commit and PR request. It was something promising for moving in direaction automation. Also adding test cases helps the code grow without bugs and updates to project are easy.

My Workflow

To the available workflow of a test run through Github Action, I added another action by CodeCov to measure my test coverage and upload it to CodeCov for better understanding and of course charts.

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code


name: Unit/Integration Test Run

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - run: yarn install
      - run: yarn test:coverage
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v1

The test:coverage script for Create React App would be

yarn test --watchAll=false --coverage

GitHub logo dreamer01 / react-login-mock

A React login mock page with input validation and unit test cases.

Discussion (0)

pic
Editor guide