@zweer/coverage-badge-readme
v1.2.2
Published
A small utility to apply your coverage badge on the README file
Readme
@zweer/coverage-badge-readme
A simple CLI tool to automatically read your test coverage summary and inject an up-to-date Shields.io badge into your README.md.
Never manually update your coverage percentage again!
🤔 Why?
Keeping the coverage badge in your README synchronized with your latest test run can be a manual and error-prone task. This tool automates the process by reading the coverage-summary.json file generated by popular testing frameworks and updating a placeholder in your README.
⚙️ Prerequisites
Your testing framework must be configured to generate a coverage summary report in json-summary format.
For Jest, Vitest, or Istanbul/nyc, add json-summary to your coverageReporters configuration.
Example for jest.config.js or vite.config.ts:
// jest.config.js
module.exports = {
// ... other configs
coverageReporters: ['json-summary', 'text', 'lcov'],
};This will generate the required coverage/coverage-summary.json file when you run your tests with the --coverage flag.
📦 Installation
You can install the package globally:
npm install -g @zweer/coverage-badge-readmeOr use it directly with npx without a global installation (recommended for CI environments):
npx @zweer/coverage-badge-readme --help🚀 Usage
Add your template badge in the README.md file, for example:
# @zweer/utils Run the CLI command after your tests have completed:
npx coverage-badge-readme
Your README.md will be automatically updated:
🛠️ Options
| Option | Alias | Description | Default | Required |
| :--- | :--- | :--- |:--- |:--- |
| --readme-path | | Path to the README.md file. | ./README.md | No |
| --coverage-path | | Path to the coverage-summary.json file. | ./coverage/coverage-summary.json | No |
| --help | -h | Show the help menu. | | |
📄 License
Licensed under the MIT License.
