Send data to Coveralls only with Travis, not local testing

I have an application ( https://github.com/idmillington/dendry ) that uses Travis CI to monitor build status. I use a general coverage report in Istanbul, and I would like to send it to Coveralls to create a coverage button for README.

All this I can get. But...

When I run npm test locally, I do not want to send coveralls coverage data. I usually do npm test dozens of times for each commit. But when I click and Travis does everything, I would like Travis to update the cover for me.

There might be something like this in my package.json package:

 "scripts": { "test": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha", } 

This is normal for the local user and does not update Coveralls, but Travis will also not update Coveralls. Or I could do:

 "scripts": { "test": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha && ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info", } 

This is ideal for Travis, but every time I run npm test locally, it tries to transfer data to Coveralls.

As far as I can tell, I can't ask Travis to run something other than npm test .

I do not want to ask potential users or contributors so that they cannot verify using

 $ npm run-script test-local 

or some of them, especially since running npm test will result in a loading error without the correct private key for coveralls.

Is there a way to get the right behavior here?

+6
source share
1 answer

The answer, it turned out, was frighteningly simple. Travis allows you to call any script you like when it runs, so I added it 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 is working fine.

+6
source

Source: https://habr.com/ru/post/973290/


All Articles