istanbul-coverage-enforcer
Advanced tools
Comparing version 1.0.1 to 1.0.2
const { enforce } = require('./src/enforce-coverage'); | ||
// Accept input threshold file path | ||
// Accept input coverage file path | ||
// execute enforce and return result | ||
// E.g. node index.js --coverage-path="./coverage.json" --threshold-path="threshold.json" | ||
/** | ||
@@ -9,0 +4,0 @@ * Enforce coverage based on threshold, or fail the process |
{ | ||
"name": "istanbul-coverage-enforcer", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A Nodejs package and cli tool to enforce code coverage", | ||
@@ -17,2 +17,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"colors": "^1.1.2", | ||
"commander": "2.14.1", | ||
"istanbul": "0.4.5", | ||
"istanbul-threshold-checker": "0.2.1" | ||
@@ -29,3 +32,5 @@ }, | ||
"prettier": "1.10.2" | ||
} | ||
}, | ||
"preferGlobal": true, | ||
"bin": "./enforce.js" | ||
} |
@@ -34,10 +34,51 @@ # istanbul-coverage-enforcer | ||
# API | ||
# Prerequisite | ||
istanbul stable (`0.4.5` or below) is needed to get the correct format of the `coverage.json` | ||
# Examples | ||
# Usage | ||
You can use the istanbul-coverage-enforcer both as a node package and as a CLI tool | ||
- Usage as a CLI tool | ||
- Usage as a node package | ||
refer the `examples`folder for some basic use case examples | ||
#### As a CLI tool: | ||
These are the options available currently with the CLI tool | ||
``` | ||
enforce --help | ||
Usage: enforce [options] | ||
Options: | ||
-c, --coverage-path The path to coverage JSON file | ||
-t, --threshold-path The path to the threshold JSON file | ||
-h, --help output usage information | ||
``` | ||
1. Add a npm script in `package.json` to call the package with the path to the code-coverage file. By default this is at `coverage/coverage.json` | ||
```javascript | ||
"enforce-coverage": "enforce -c=coverage/coverage.json -t=coverage-threshold.json", | ||
``` | ||
2. Now you can run this script as part of your build to ensure that code coverage is maintained above threshold | ||
``` | ||
npm run enforce-covergage | ||
``` | ||
***Output*** | ||
```bash | ||
[SUCCESS]: Coverage above threshold | ||
``` | ||
#### As a node package | ||
1. Create a `coverage-threshold.json` in the root of your project. Optionally this can be also passed as the second parameter to the function | ||
2. In your script *import* and *call* the `enforce` function as below: | ||
``` | ||
const enforce = require('../index'); | ||
enforce('./examples/coverage.json', './examples/coverage-threshold.json'); | ||
``` | ||
Refer the `examples`folder for some basic use case examples | ||
# Reference and Credits |
@@ -52,3 +52,3 @@ const istanbul = require('istanbul'); | ||
const enforce = (coveragePath, thresholdPath) => { | ||
const enforce = (coveragePath, thresholdPath = 'coverage-threshold.json') => { | ||
const coverageDetails = readParsedJSONP(coveragePath, { encoding: 'utf-8' }); | ||
@@ -55,0 +55,0 @@ const thresholdDetails = readParsedJSONP(thresholdPath, { |
Sorry, the diff of this file is not supported yet
16
1958
84
145433
4
+ Addedcolors@^1.1.2
+ Addedcommander@2.14.1
+ Addedistanbul@0.4.5
+ Addedcolors@1.4.0(transitive)
+ Addedcommander@2.14.1(transitive)