Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to work behind corporate proxy and configuration for low and high coverage values #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ Currently just reads from Istanbul's JSON summary reporter and downloads a badge
"test:badges": "npm run test:coverage && jest-coverage-badges"
}
```
3. Configure proxy

If you are behind a corporate proxy, you will need to set the ```HTTP_PROXY``` environment variable to work properly..

```
## Linux user's
HTTP_PROXY=http://yourproxy.com:yourProxyPort

2. Run `npm test -- --coverage`
## Windows user's
SET HTTP_PROXY=http://yourproxy.com:yourProxyPort
```

3. Run `jest-coverage-badges` (or just run: `npm run test:badges`)
4. Run `npm test -- --coverage`

5. Run `jest-coverage-badges` (or just run: `npm run test:badges`)

Resulting in badges:
- `./coverage/badge-statements.svg`
Expand All @@ -80,9 +90,11 @@ Currently just reads from Istanbul's JSON summary reporter and downloads a badge
#### CLI Options
* **input** [default: ./coverage/coverage-summary.json] - the file (and its path) of the summary json that contains the coverage data
* **output** [default: ./coverage] - the path to the directory where the svg files will be placed after download. If path doesn't exist it will be created.
* **low** [default: 80] - the minimum of coverage to be considerated as medium coverage (yellow), bellow this value, always will be flagged as low coverage (red).
* **high** [default: 90] - the minimum of coverage to be conssiderated as high coverage (green), above this will be flagged as high coverage (green).

**Example**:
```$ jest-coverage-badges --input "./cov" --output "./badges"```
```$ jest-coverage-badges --input "./cov" --output "./badges" --low 85 --high 95```


After this you can add into Github readme (for example) :smiley:
Expand Down
20 changes: 16 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

require('global-tunnel-ng').initialize()

/* eslint-disable semi */
const mkdirp = require('mkdirp');
const { get } = require('https');
Expand All @@ -13,7 +15,7 @@ const { readFile, writeFile } = require('fs');
* @param defaultOutput - default value to return if could not find argument in cli command
* @private
*/
const findArgument = (argName, defaultOutput) => {
const findArgument = (argName, defaultOutput, parseValue) => {
if (!argName) {
return defaultOutput;
}
Expand All @@ -24,7 +26,12 @@ const findArgument = (argName, defaultOutput) => {
}

try {
return process.argv[index + 1];

let argument = process.argv[index + 1];
if(parseValue){
argument = parseValue(argument);
}
return argument;
} catch (e) {
return defaultOutput;
}
Expand All @@ -33,12 +40,17 @@ const findArgument = (argName, defaultOutput) => {
const outputPath = findArgument('output', './coverage');
const inputPath = findArgument('input', './coverage/coverage-summary.json');

const parseArgumentToInt = (argument) => parseInt(argument);

const lowCoverage = findArgument('low', 80, parseArgumentToInt)
const highCoverage = findArgument('high', 90, parseArgumentToInt)

const getColour = (coverage) => {
if (coverage < 80) {
if (coverage < lowCoverage) {
return 'red';
}

if (coverage < 90) {
if (coverage < highCoverage) {
return 'yellow';
}

Expand Down
49 changes: 41 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-coverage-badges",
"version": "1.1.3",
"version": "1.2.0",
"description": "Create a group of coverage badges from jest",
"main": "cli.js",
"bin": "cli.js",
Expand All @@ -15,6 +15,9 @@
"istanbul"
],
"author": "Pamela Peixinho <[email protected]> (https://pamepeixinho.github.io)",
"contributors": [
"Maike Mota <[email protected]>"
],
"engines": {
"node": ">=6.11",
"npm": ">=5.3"
Expand All @@ -27,6 +30,7 @@
"lint": "eslint --fix -- ."
},
"dependencies": {
"global-tunnel-ng": "2.7.1",
"mkdirp": "0.5.1"
},
"devDependencies": {
Expand Down