-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage: Source file path in lcov coverage report isn't correct #542
Comments
cc/ @mischah |
I have exactly the same issue in my project. I tried to run jest on your minimal repo. In So far I haven't figured out where this problem comes from. Any idea? |
Possibly related: jestjs/jest#3753 |
After further investigation, I came up with a solution. It appears that the problem comes from your TypeScript configs. In your Hope it can help 😉 |
@benoitdemaegdt I've tried your solution in the https://github.com/nicolaisueper/jest-ts-lcov-demo bare repo, as well as in that same repo with updated dependencies, but it doesn't seem to work, the path in the coverage is still wrong:
I wanted to upload a screenshot with configs and such but sounds like github upload has issues just right now... |
@benoitdemaegdt was right about the You also have to had According to official doc i've tried it in here https://github.com/nicolaisueper/jest-ts-lcov-demo and it works like a charm. here is the SF line in Hope it can help 😉 |
Well, you're right. It only changes the path in Before removing "sourceRoot": "./src" After removing "sourceRoot": "./src" However, in one of my other projects, removing |
@benoitdemaegdt oh I did not notice the path was wrong in that way in Anyway, yeah the |
Thanks @pierreneveu. Yeah it sounds like lcov is building relative paths using the whole set of files, and not using (or wrongly) the path given in sourcemap data nor the root dir of jest. |
closing this since it's a lcov bug (if it's a bug), feel free to re-open after testing with latest version if you think it should remain open |
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: const path = require('path')
const {readFileSync, writeFileSync} = require('fs')
(() => {
const lcovFile = path.resolve(__dirname, './coverage/lcov.info')
const rawFile = readFileSync(lcovFile, 'utf8')
const rebuiltPaths = rawFile.split('\n').map( singleLine => {
if (singleLine.startsWith('SF:')) {
return singleLine.replace('SF:', `SF:${__dirname}/`)
}
return singleLine
}).join('\n')
console.log(rebuiltPaths)
writeFileSync(lcovFile, rebuiltPaths, 'utf8')
})() This should sit in the same directory as your |
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.
The
SF
paths inside thelcov.info
file match the source file location.[ ~~~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 ]
https://github.com/nicolaisueper/jest-ts-lcov-demo
npm test
coverage/lcov.info
fileThe text was updated successfully, but these errors were encountered: