Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

IIIMPACT/jest-cypress-coverage-action

Repository files navigation

Get Diff Action

CI Status codecov CodeFactor License: MIT

GitHub action to merge jest and cypress test coverages.

Table of Contents

Details

Screenshots

  1. Example workflow

    Example workflow

  2. Coverage result

    Coverage result

  3. Coverage diff

    Coverage diff

Usage

Basic Usage

on:
  pull_request:
  push:
    branches:
      - master
      - development

jobs:
  coverage:
    name: coverage
    strategy:
      matrix:
        node-version: [14.x]
        platform: [ubuntu-latest]
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      - name: Cache node modules
        uses: actions/cache@v1
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-${{ env.cache-name }}
            ${{ runner.os }}-node-
            ${{ runner.os }}-

      - name: Install Dependencies
        run: npm ci

      - name: Run Tests and display coverage
        id: coverage
        uses: IIIMPACT/jest-cypress-coverage-action@main
        with:
          accessToken: ${{secrets.GITHUB_TOKEN}}
          fullCoverageDiff: false
          prCoverageThreshold: '{"global":{"branches":45,"functions":50,"lines":50,"statements":70}}'
          checkForDuplicateMessages: false
          prNumber: ${{ github.event.pull_request.number }}

Behavior

  1. Run tests and get combined pr test coverage

    npm run test:all
    npm run test:cypress:staging
    

    => e.g. (default output)

    .nyc_output/out.json
    jest-coverage-full/coverage-final.json
    

    => Merge coverage reports merge will first Normalise jest coverage reports, removing an enclosing data property on *.d.ts and *.js files and then merging the coverages

    npm run merge  -- --report ./jest-coverage-full/coverage-final.json --report ./.nyc_output/out.json
    
  2. Test pr coverage against thresholds Get list of files that have changed in the pr

    git fetch origin ${branchNameBase}:${branchNameBase}
    git fetch origin ${branchNameHead}:${branchNameHead}
    

    => Merge coverage reports merge will first Normalise jest coverage reports, removing an enclosing data property on *.d.ts and *.js files and then merging the coverages

    npm run merge  -- --report ./jest-coverage-full/coverage-final.json --report ./.nyc_output/out.json
    

    => Test coverage report summary against the set thresholds

Author

GitHub (Jabulani Mpofu)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors