DEV Community

Pushpendra Singh
Pushpendra Singh

Posted on

3 1

Measuring Code Coverage in React, with CodeCov Github Action

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

Enter fullscreen mode Exit fullscreen mode

The test:coverage script for Create React App would be

yarn test --watchAll=false --coverage
Enter fullscreen mode Exit fullscreen mode

GitHub logo dreamer01 / react-login-mock

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

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay