Coverage: Source file path in lcov coverage report isn't correct
See original GitHub issue- Issue
The “Source File” inside the generated lcov reports doesn’t match the actual location.
It seems, like ts-jest does not preserve the original file location.
Because of this, my IDE (webstorm) isn’t able to visually represent the coverage for files which aren’t located at the src root.
- Expected behavior
The SF paths inside the lcov.info file match the source file location.
- Output from your debug log
[ ~
You can activate the debug logger by setting the environment variable TS_JEST_DEBUG=“true” before running yarn test. The output of the logger will be in <your_project_dir>/node_modules/ts-jest/debug.txt~ the file didn’t exist, so my terminal output ]
➜ jest-ts-lcov-demo git:(master) ✗ TS_JEST_DEBUG="true" npm test
> jest-ts-lcov-demo@0.0.0 test /Users/doge/Workspace/jest-ts-lcov-demo
> jest
PASS __tests__/application.test.ts
Application
user-util.ts
sumAges(users)
✓ should sum up the ages (7ms)
--------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
user-util.ts | 100 | 100 | 100 | 100 | |
--------------|----------|----------|----------|----------|-------------------|
=============================== Coverage summary ===============================
Statements : 100% ( 3/3 )
Branches : 100% ( 0/0 )
Functions : 100% ( 2/2 )
Lines : 100% ( 2/2 )
================================================================================
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 4.18s
Ran all test suites.
- Link to a minimal repo that reproduces this issue
https://github.com/nicolaisueper/jest-ts-lcov-demo
- Steps to Reproduce
- run
npm test - check the paths inside the
coverage/lcov.infofile
- run
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:12
Top Results From Across the Web
Coverage issues for Typescript (LCOV Could not resolve file ...
The error message is: WARN: Could not resolve xx file paths in [coverage/lcov.info], first unresolved path:
Read more >Sonar Coverage: file path in lcov coverage report isn't correct
1 Answer 1 · You need to make sure a coverage report is generated for the test. So if you are running something...
Read more >Coverage reporter is asking for `lcov.info` file if `coverage` is ...
I'm using Intellij Idea + karma plugin to run karma tests. Namely, I want to run test coverage. The issue is that when...
Read more >Ubuntu Manpage: lcovrc - lcov configuration file
The lcovrc file contains configuration information for the lcov code coverage tool (see lcov(1)). The system-wide configuration file is located at ...
Read more >Command line usage — Coverage.py 6.4.4 documentation
annotate – Annotate source files with coverage results. ... -m, --module <pyfile> is an importable Python module, not a script path, to be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue is linked very directly from the first google result for:
There’s a simple portable fix I’ve put together that I’d like to share:
This should sit in the same directory as your
package.jsonand should be run after you’ve completed your test run with coverage output, but before you report to sonar qube. All this does is take every lcovSF, or Source File, and just blindly prepends the CWD to them. This will always give an absolute path to the files themselves. Obviously a dumb hack, but portable and issue solving without having to make even more sacrifices in project config to appease sonar qube and it’s incredibly opaque runtime. As a helping hand, I have it show you the file it’s outputting to help with debugging a failure.I have exactly the same issue in my project.
I tried to run jest on your minimal repo. In
coverage/lcov.info, I get :SF:<...>/jest-ts-lcov-demo/src/user-util.tsbut it should be :SF:<...>/jest-ts-lcov-demo/src/util/user-util.tsSo far I haven’t figured out where this problem comes from. Any idea?