danger-plugin-istanbul-coverage
Danger.js plugin for monitoring code coverage on changed files.
Usage
Install:
yarn add danger-plugin-istanbul-coverage --dev
At a glance:
import { schedule } from "danger"
import { istanbulCoverage } from "danger-plugin-istanbul-coverage"
schedule(istanbulCoverage())
schedule(istanbulCoverage({
customSuccessMessage: "Congrats, coverage is good",
customFailureMessage: "Coverage is a little low, take a look",
entrySortMethod: "alphabetical"
numberOfEntries: 10,
coveragePath: "./coverage/coverage-summary.json",
coveragePaths: ["./dir1/coverage-summary.json", "./dir2/coverage-summary.json"]
coveragePath: { path: "./coverage/lcov.info", type: "lcov" }
reportFileSet: "all",
reportMode: "message",
threshold: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
}
}))
This plugin requires the 'json-summary' or 'lcov' report modes be enabled with Istanbul. Make sure Danger runs after your unit tests in your CI workflow.
FAQ
What test runners does this work with?
Anything that integrates with Istanbul, or produces output in the (lcov)[https://linux.die.net/man/1/lcov] format. Istanbul is test runner agnostic, and can be integrated with anything written in node. Some test runners already integrate Istanbul, for instance Jest bundles it internally. Helper integrations exists for Jasmine and other libraries.
Why should my team see code coverage stats in their PRs?
It is important to note that test coverage and test quality aren't the same thing. However, low test coverage, particularly on new or modified code, is usually sympomatic of poor test culture on a team. Surfacing test coverage statistics on your PRs can helps increase accountability on the team, and encourages discussion on why certain things were or weren't tested. Tests still need to be reviewed and held up to the same standards as any piece of code. Focusing too much on increasing code coverage, while ignoring test quality can create technical debt in the form of junk tests. So use these stats as a jumping off point for conversations, not a rubber stamp.
Changelog
See the GitHub release history.
Contributing
See CONTRIBUTING.md.