diff --git a/README.md b/README.md index fcc107a..a67a00f 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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: diff --git a/cli.js b/cli.js index 4be1d27..01e90ff 100755 --- a/cli.js +++ b/cli.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +require('global-tunnel-ng').initialize() + /* eslint-disable semi */ const mkdirp = require('mkdirp'); const { get } = require('https'); @@ -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; } @@ -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; } @@ -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'; } diff --git a/package-lock.json b/package-lock.json index d52c603..4d33af1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jest-coverage-badges", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -589,7 +589,6 @@ "version": "1.1.12", "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz", "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==", - "dev": true, "requires": { "ini": "1.3.5", "proto-list": "1.2.4" @@ -822,6 +821,11 @@ "integrity": "sha512-PAHp6TxrCy7MGMFidro8uikr+zlJJKJ/Q6mm2ExZ7HwkyR9lSVFfE3kt36qcwa24BQL7y0G9axycGjK1A/0uNQ==", "dev": true }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1639,6 +1643,17 @@ "path-is-absolute": "1.0.1" } }, + "global-tunnel-ng": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/global-tunnel-ng/-/global-tunnel-ng-2.7.1.tgz", + "integrity": "sha512-4s+DyciWBV0eK148wqXxcmVAbFVPqtc3sEtUE/GTQfuU80rySLcMhUmHKSHI7/LDj8q0gDYI1lIhRRB7ieRAqg==", + "requires": { + "encodeurl": "1.0.2", + "lodash": "4.17.11", + "npm-conf": "1.1.3", + "tunnel": "0.0.6" + } + }, "globals": { "version": "11.9.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.9.0.tgz", @@ -1792,8 +1807,7 @@ "ini": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, "inquirer": { "version": "6.2.1", @@ -2180,8 +2194,7 @@ "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, "lodash._baseassign": { "version": "3.2.0", @@ -2468,6 +2481,22 @@ "integrity": "sha1-MtDkcvkf80VwHBWoMRAY07CpA3k=", "dev": true }, + "npm-conf": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/npm-conf/-/npm-conf-1.1.3.tgz", + "integrity": "sha512-Yic4bZHJOt9RCFbRP3GgpqhScOY4HH3V2P8yBj6CeYq118Qr+BLXqT2JvpJ00mryLESpgOxf5XlFv4ZjXxLScw==", + "requires": { + "config-chain": "1.1.12", + "pify": "3.0.0" + }, + "dependencies": { + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=" + } + } + }, "npm-package-arg": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-4.2.1.tgz", @@ -2904,8 +2933,7 @@ "proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", - "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=", - "dev": true + "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=" }, "psl": { "version": "1.1.31", @@ -3929,6 +3957,11 @@ "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "dev": true }, + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", diff --git a/package.json b/package.json index 9c330b3..c2a4679 100644 --- a/package.json +++ b/package.json @@ -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", @@ -15,6 +15,9 @@ "istanbul" ], "author": "Pamela Peixinho (https://pamepeixinho.github.io)", + "contributors": [ + "Maike Mota " + ], "engines": { "node": ">=6.11", "npm": ">=5.3" @@ -27,6 +30,7 @@ "lint": "eslint --fix -- ." }, "dependencies": { + "global-tunnel-ng": "2.7.1", "mkdirp": "0.5.1" }, "devDependencies": {