danger-plugin-code-coverage

Build Status npm version semantic-release

Danger.JS plugin to display the code coverage on a pull request by commenting it via the CI

Installation

You need to install Danger JS first:

yarn add -D danger

Then add this package

yarn add -D danger-plugin-code-coverage

Usage

  • Create a dangerfile (dangerfile.js or dangerfile.ts at the root of your project folder)
  • Edit it with
// dangerfile.js
import { codeCoverage } from "danger-plugin-code-coverage"

codeCoverage()
  • Generate a coverage-final.json file by editing your jest.config.js file:
  coverageReporters: ['json'],

Note: You can add other coverageReporters. Refers to the Jest doc

  • Run locally to test if it works
yarn danger local

You should see some lines in your terminal

Example for Circle CI:

version: 2
jobs:
build:
  steps:
    - run: ... YOUR OTHER STEPS ...
    - run:
        name: Run Danger
        command: yarn danger ci
        environment:
          DANGER_GITHUB_API_TOKEN: YOUR_GITHUB_TOKEN
  • Push a new PR and run the CI on it.
  • Go see your pull request with a useful comment!
  • ⭐️Add a star on this repo if you like it ;)

Available options

You can customize this plugin by providing some options to codeCoverage function:

const defaultPluginOptions: PluginOptions[] = [
    {
      title: "# Coverage",
      ignoreCoveragePattern: [".test.", ".snap"],
      coverageFilesPath: "coverage/coverage-final.json",
    },
  ];

codeCoverage(defaultPluginOptions),
Name  Type Default Description
 title  string  "# Coverage" title of the coverage message
ignoreCoveragePattern  string[ ]  [".test.", ".snap"]  strings included into file path you want ignore of the coverage message
coverageFilesPath string  "coverage/coverage-final.json" path to your coverage-final.json file generated by Jest (thanks to Istanbul)

Changelog

See the GitHub release history.

Contributing

See CONTRIBUTING.md.