Skip to content

Commit

Permalink
Add codecov as coverage tool in TravisCI
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Dec 13, 2019
1 parent 3238445 commit 25dd060
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 60 deletions.
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ os:
- linux
- windows
node_js:
- '6'
- '8'
- '10'
- "6"
- "8"
- "10"
jobs:
include:
- name: 'Coverage'
node_js: stable
os: linux
script:
- npm run test-unit
- bash <(curl -s https://codecov.io/bash) -c -Z -f .coverage/coverage.json -F unit
notifications:
slack:
secure: PuYBCkRXgUKxoFMyTZdYcxplpgW+T/hxq54gsFOcAxN079i7PTD/GmGIgKM1RviCocvroUst5bW3ULk3haYUb8gQSCyAeHzRl00DaoOXshTRjFzJyU6m5wbT/R45dh6ZO2BT6uwlVU95KznieCC+yjlbppPOis8bwxra08ODnsA1L7OeI7fVlKjyh+lPA4qnmuYpNtMfTO5mmHroHBS5nWoB1WctWuZQGSfDYLUr/XrhKkJOBbv7FI7setTroIRF4Rs9nIFEF3mzTuUK5VV6lQAZRzNHKmgD9DmGVeaB5Y4fWEznocV1d6cInsjMr4EyMYziyOFnnPZAk8GZapMDwD0/5E9L5+Q8uXhFhVHYurpZnP+wylqZmnfb4UaFcP96BBaavhfF/ai+LWlLbHiL5b1HX4dlauNfHdq1W1YCILI2Atfr+36rqu3102S6HHkOssoTw09ftLfQHuF6CNYnVE5cS40pupwFZj3o0h9yQnCFDPxlq2ls+hon+PKL9wCHL5MlG+jQZDDL8eZC8F9CoZUyVIxNhoh0fnZ+t4bIlGW5eB8f8oMCxcnjocxZpichfAsmuaPh/e2KfdoF/B7ce6+Tb3/YXqo5QVTsJ1Vzi4I7c3jx1Q0DAyZODsBKyE0y7NfmeVNap0WIgajiJBoKji8Fjw+tDfa3hSb4yyPSG6w=
24 changes: 24 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
coverage:
range: 70..100 # green if 100+, red if 70-

status:
patch:
# coverage status for pull request diff
default:
target: 100 # any patch should be 100% covered
threshold: 1% # allow a little drop

project:
# coverage status for whole project
default:
target: auto # use coverage of base commit as target
threshold: 1% # allow a little drop

# coverage status for unit tests
unit:
flags: unit
target: 50

parsers:
javascript:
enable_partials: yes # use partial line coverage
44 changes: 31 additions & 13 deletions npm/test-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ var path = require('path'),

IS_WINDOWS = (/^win/).test(process.platform),
COV_REPORT_PATH = '.coverage',
COV_REPORT_FILE = path.join(COV_REPORT_PATH, 'coverage.json'),
REPORT_PATH = path.join('.tmp', 'report.xml'),
SPEC_SOURCES = path.join('test', 'unit');

module.exports = function (exit) {
var specPattern = (process.argv[2] || '.*'),
mochaReporter = 'spec',
istanbulReport = '';
istanbulReport = '',

istanbulBinary = './node_modules/.bin/istanbul',
mochaBinary = './node_modules/.bin/_mocha',

targetCoverage = {
statements: 50,
branches: 40,
functions: 40,
lines: 55
};

// for CI, we use simple xunit reporter (not on Travis since it does not parse results)
// if (process.env.CI) {
Expand All @@ -38,19 +49,26 @@ module.exports = function (exit) {

// windows istanbul and mocha commands need some special attention.
if (IS_WINDOWS) {
// sample command in case you're confused
// node_modules\.bin\istanbul.cmd cover --dir .coverage --color --print both
// node_modules\mocha\bin\_mocha -- --reporter spec --reporter-options output=
// .tmp\report.xml test\unit --recursive --prof --colors --grep=.*
exec(`node_modules\\.bin\\istanbul.cmd cover ${istanbulReport} --dir ${COV_REPORT_PATH} --colors ` +
`--print both node_modules\\mocha\\bin\\_mocha -- ${SPEC_SOURCES} --reporter ${mochaReporter} ` +
`--reporter-options output=${REPORT_PATH} --recursive --prof --colors --grep=${specPattern}`, exit);
}
else {
exec(`./node_modules/.bin/istanbul cover ${istanbulReport} --dir ${COV_REPORT_PATH} --colors ` +
`--print both node_modules/mocha/bin/_mocha -- ${SPEC_SOURCES} --reporter ${mochaReporter} ` +
`--reporter-options output=${REPORT_PATH} --recursive --prof --colors --grep=${specPattern}`, exit);
istanbulBinary = 'node_modules\\.bin\\istanbul.cmd';
mochaBinary = 'node_modules\\mocha\\bin\\_mocha';
}

// sample command in case you're confused
// node_modules/.bin/istanbul cover --dir .coverage --color --print both
// node_modules/mocha/bin/_mocha -- --reporter spec --reporter-options output=
// .tmp/report.xml test/unit --recursive --prof --colors --grep=.*
// && node_modules/.bin/istanbul check-coverage
// --statements xx --branches xx --functions xx --lines xx
exec(`${istanbulBinary} cover ${istanbulReport} --dir ${COV_REPORT_PATH} --colors ` +
`--print both ${mochaBinary} -- ${SPEC_SOURCES} --reporter ${mochaReporter} ` +
`--reporter-options output=${REPORT_PATH} --recursive --prof --colors --grep=${specPattern} ` +

`&& ${istanbulBinary} check-coverage ` +
`--statements ${targetCoverage.statements} ` +
`--branches ${targetCoverage.branches} ` +
`--functions ${targetCoverage.functions} ` +
`--lines ${targetCoverage.lines} ` +
`${COV_REPORT_FILE}`, exit);
};

// ensure we run this script exports if this is a direct stdin.tty run
Expand Down
19 changes: 0 additions & 19 deletions npm/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test-lint": "node npm/test-lint.js",
"test-unit": "node npm/test-unit.js",
"test-vm": "node npm/test-vm.js",
"test": "node npm/test.js",
"test": "npm run test-lint && npm run cache && npm run test-system && npm run test-unit && npm run test-vm && npm run test-integration && npm run test-browser",
"prepublish": "node npm/prepublish.js"
},
"keywords": [
Expand Down
24 changes: 0 additions & 24 deletions test/system/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ describe('project repository', function () {
});
});

describe('script definitions', function () {
it('should be present', function () {
expect(json.scripts).to.be.ok;
});

describe('element', function () {
json.scripts && Object.keys(json.scripts).forEach(function (scriptName) {
describe(scriptName, function () {
it('should point to a file', function () {
expect(json.scripts[scriptName]).to.match(/^node\snpm\/.+\.js(\s\$1)?$/);
expect(fs.statSync('npm/' + scriptName + '.js')).to.be.ok;
});
});
});
});

it('should have the hashbang defined', function () {
json.scripts && Object.keys(json.scripts).forEach(function (scriptName) {
var fileContent = fs.readFileSync('npm/' + scriptName + '.js').toString();
expect(fileContent).to.match(/^#!\/(bin\/bash|usr\/bin\/env\snode)[\r\n][\W\w]*$/g);
});
});
});

describe('devDependencies', function () {
it('should exist', function () {
expect(json.devDependencies).to.be.an('object');
Expand Down

0 comments on commit 25dd060

Please sign in to comment.