I have an app (https://github.com/idmillington/dendry) that uses Travis CI to monitor build status. I use Istanbul to general a coverage report, and I'd like to send this to Coveralls, to generate a coverage button for the README.
All of this I can get working. But...
When I run npm test
locally, I don't want to send coveralls the coverage data. I'm typically running npm test
dozens of times for each commit. But when I push and Travis does its thing, I'd like Travis to update the coverage for me.
I could have something like this in my package.json:
"scripts": {
"test": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha",
}
Which is fine for locally, and doesn't update Coveralls, but Travis won't update Coveralls either. Or I could do:
"scripts": {
"test": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha && ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
}
Which is perfect for Travis, but tries to push data to Coveralls every time I run npm test
locally.
As far as I can tell, I can't ask Travis to run something other than npm test
.
I am unwilling to ask any potential users or contributors to remember to test using
$ npm run-script test-local
or some such, especially as running npm test
would generate an upload error without the correct private key for coveralls.
Is there a way to get the right behavior here?
The answer, as it turns out, was frighteningly simple. Travis does allow you to call whatever script you like as it runs, so I added this to my .travis.yml
file:
script: npm run-script test-on-travis
so in package.json
I could define:
"scripts": {
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha",
"test-on-travis": "./node_modules/.bin/istanbul cover --report lcovonly ./node_modules/.bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
}
and everything works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With