node-coveralls
node-coveralls copied to clipboard
Jest --coverage : help
Hi everyone,
is anyway i can setup this with Jest?
many thanks
Just add: && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
"test": "node --harmony_proxies node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
Thanks @jseminck would be good to add this to the README, I think?
I followed @jseminck approach, but now Im getting the following error:
[error] "2016-11-04T14:51:39.503Z" 'error from lcovParse: ' 'Failed to parse string'
[error] "2016-11-04T14:51:39.505Z" 'input: ' ''
[error] "2016-11-04T14:51:39.506Z" 'error from convertLcovToCoveralls'
Any ideas? Thanks in advanced.
@ndelvalle, most likely, your coverage/lcov.info
is empty
yep @cdaringe that was the problem 👍
:+1:
@jseminck @seeliang worth noting that Jest's coverage implementation outputs a .JSON report that is compatible with nyc and Istanbul in the coverage/
folder. So this would totally work:
nyc report --temp-directory=coverage --reporter=text-lcov | coveralls
Thanks, guys. I will give a go later :)
Can this be added to the README?
👍 For adding to readme.
Is there any advantage to any specific coverage format? Which file in coverage
should we pipe into coveralls
if we add it to the readme?
-rw-r--r-- 1 nick staff 10945 Sep 7 15:15 clover.xml
-rw-r--r-- 1 nick staff 28542 Sep 7 15:15 coverage-final.json
-rw-r--r-- 1 nick staff 23445 Sep 6 21:46 coverage.json
-rw-r--r-- 1 nick staff 25730 Sep 6 03:59 coverage.raw.json
drwxr-xr-x 9 nick staff 306 Sep 7 13:36 lcov-report
-rw-r--r-- 1 nick staff 4024 Sep 7 15:15 lcov.info
Why not use a script like this?
jest --coverage && cat ./coverage/lcov.info | coveralls
Personally I like to set "jest": { "collectCoverage": true }
in package.json
to enable coverage reporting everywhere, add coveralls as a devDependency
, and have CI run coveralls < coverage/lcov.info
.
😮 now I got it, so most people don't have coveralls
as a devDependency
that's way ./node_modules/coveralls/bin/coveralls.js
appears in their configurations.
I was asking about that part specially.
By the way I think this is the best approach to maintain configurations clearer. As a side effect you had clarify my doubt 😆, thanks man
I don't think that's the case. Assuming that the other technique is to npm install coveralls
in CI after a build, it would still install the package to node_modules
with a binary in that location. Whether or not you install as a saved devDependency
, it will only be executable directly via coveralls
if you have it in your $PATH
(some CI services like Travis do this automatically) or if you're calling it in an npm script (which does something similar).
@nickmccurdy Your solution isnot supported by create-react-app It gives the warning below: Out of the box, Create React App only supports overriding these Jest options: • collectCoverageFrom • coverageReporters • coverageThreshold • snapshotSerializers. These options in your package.json Jest configuration are not currently supported by Create React App: • collectCoverage
Yes, but you can still use jest --coverage
in your build script even though the config option isn't supported.
Yeah,
I solved it by run yarn test --coverage
which later runs jest --coverage
This is how I got it to work
node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
@jseminck, @tizmagik: sorry to bother in this thread. I'm using jest + enzyme, and hoping to pipe the coverage results to coveralls. So, I implemented test:coveralls
, a script
from my package.json
:
"scripts": {
"build:browserify": "browserify -t [ babelify --presets env,stage-2,react ] content.jsx > ../../interface/static/js/content.js",
"prebuild:dos2unix": "find . -type f -print0 | xargs -0 dos2unix",
"watch:jsx": "onchange 'src/jsx/**/*.jsx' 'src/jsx/**/*.js' -- npm run build:browserify",
"test": "NODE_ENV=test jest --config jest.config.js",
"test:coveralls": "npm run test --coverage --coverageReporters=lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
I've verified both coveralls.js
, and lcov.info
are nonempty. However, my travis build, seems to error:
[error] "2018-05-31T16:37:12.946Z" 'error from convertLcovToCoveralls'
/home/travis/build/jeff1evesque/machine-learning/src/jsx/node_modules/coveralls/bin/coveralls.js:18
throw err;
^
Failed to parse string
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:coveralls: `npm run test --coverage --coverageReporters=lcov.info | ./node_modules/coveralls/bin/coveralls.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test:coveralls script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/travis/.npm/_logs/2018-05-31T16_37_12_965Z-debug.log
The command "npm run test:coveralls" exited with 1.
@jseminck, @tizmagik: nevermind, I think I've fixed it. The corresponding travis build, seems to have run the following without erroring:
cat lcov.info | ./node_modules/coveralls/bin/coveralls.js
I guess I'll merge my corresponding pull request, and see if my webhook
updates coveralls.
Ah, didn't have to wait for PR to be merged. Seems like the configurations worked. Thank you everyone, pretty much recycled different aspects from various comments in this issue.
@nickmccurdy's solution worked for me. Thanks Nick!
Based on @jeff1evesque and @nickmccurdy answer:
package.json
"scripts": {
"ci-process-cover": "cat coverage/lcov.info | coveralls"
}
jest.config.js
module.exports = {
"collectCoverage": true
// ...
}
.travis.yml
script:
- npm run test
after_script:
- npm run ci-process-cover
Or have tests run twice:
package.json
`cover`: `jest --coverage --coverageReporters=text-lcov | coveralls`
.travis.yml
script:
- npm run test
after_script:
- npm run cover
If you replace npm run test
by npm run cover
, coverage will work, but your CI will not fail if one test fail.
I've faced a similar problem, hope this post might help you a little bit.
Hi all am facing
[error] "2021-01-11T05:26:15.227Z" 'error from lcovParse: ' 'Failed to parse string'
[error] "2021-01-11T05:26:15.230Z" 'input: ' ''
[error] "2021-01-11T05:26:15.230Z" 'error from convertLcovToCoveralls'
when running it locally and in my Github action. How do I generate .lcov so the file won't be empty? @nickmccurdy @jseminck @tizmagik
@adefemi171 if you are using Angular --code-coverage
will generate a coverage report for you.
Am using Node and Jest and I ran jest --coverage
which created a coverage folder but with an empty lcov.info
@zdrawku
Why not use a script like this?
jest --coverage && cat ./coverage/lcov.info | coveralls
Because it doesn't work on Windows.
Do we have any cross-platform solution ?
I figured only following:
jest --coverage && coveralls < coverage\\lcov.info
Ordinary pipe jest --coverage --coverageReporters=text-lcov | coveralls
somehow doesn't work with NodeJS 14.15.*