Coveralls report 0% coverage for NodeJS project
jozefizso opened this issue · 3 comments
Report: https://coveralls.io/builds/57532375
Repository: https://github.com/jozefizso/generator-license/tree/coveralls
Build run: https://github.com/jozefizso/generator-license/actions/runs/4331090549
I have NodeJS project with coveralls v3.1.1 and I use jest to run tests.
Running npm test
will report the code coverage correctly:
jest --coverage
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
PASS __tests__/test-creation.js
PASS __tests__/test-app.js
PASS __tests__/test-license-files.js
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 88.24 | 100 | 100 |
index.js | 100 | 88.24 | 100 | 100 | 137-141
----------|---------|----------|---------|---------|-------------------
Test Suites: 3 passed, 3 total
Tests: 30 passed, 30 total
Snapshots: 0 total
Time: 6.003 s
Ran all test suites.
Coverage is reported using coverallsapp/github-action@v1
:
Run coverallsapp/github-action@v1
with:
flag-name: node-14
parallel: true
github-token: ***
path-to-lcov: ./coverage/lcov.info
coveralls-endpoint: https://coveralls.io/
env:
NODE_COVERALLS_DEBUG: 1
Using lcov file: ./coverage/lcov.info
The coveralls.io report COVERAGE: 0.0% for these builds. How can I troubleshoot the issue?
Hi @jozefizso. In your verbose build log, when you look at the JSON the integration is sending to Coverall.io, do you see source_files: []
?
If so, the integration is not finding files from your LCOV
at the filepaths listed there, so you'll need to use the base-path
input option to correct for the difference in location.
Check the README for more on that. Good luck.
@afinetooth thanks a lot for the hint, I was able to pinpoint the issue to Jest.
The jest is generating incorrect path in lcov.info
when run in GitHub Actions. I tested the code on Windows, Ubuntu in WSL and macOS and I get correct path SF:app/index.js
when run locally. On GHA the path is SF:../../home/runner/work/generator-license/generator-license/app/index.js
for unknown reason.
I add step to fix the lcov.info
with sed
:
- name: fix lcov.info
run: |
sed -i -E 's/SF:(\.\.\/\.\.(.+))/SF:\2/' coverage/lcov.info
Action is now sending source code and other data to Coveralls service:
sending this to coveralls.io: ' `{"source_files":[{"name":"app/index.js","source":"'use strict'; ... "}]}`
Coveralls.io now shows the coverage correctly: https://coveralls.io/builds/57533472
PS: I tried several settings for base-path
but it changed SF
value unpredictably so I used sed
.
@jozefizso Great. Nicely done. Yeah, sometimes the base-path option is not granular enough to handle all cases, in which case we recommend the step you took and point users to the regex replace they'll probably want to replicate in sed
.