Skip to content

Repository files navigation

danger-plugin-code-coverage

Build Statusnpm versionsemantic-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.jsimport{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: 2jobs:
build:
steps:
- run: ... YOUR OTHER STEPS ...
- run:
name: Run Dangercommand: yarn danger cienvironment:
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:

constdefaultPluginOptions: PluginOptions[]=[{title: "# Coverage",ignoreCoveragePattern: [".test.",".snap"],coverageFilesPath: "coverage/coverage-final.json",},];codeCoverage(defaultPluginOptions),
Name TypeDefaultDescription
 title string "# Coverage"title of the coverage message
ignoreCoveragePattern string[ ] [".test.", ".snap"] strings included into file path you want ignore of the coverage message
coverageFilesPathstring "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.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

15 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages