New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

istanbul-coverage-enforcer

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul-coverage-enforcer - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

enforce.js

5

index.js
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

9

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc