-
Notifications
You must be signed in to change notification settings - Fork 110
Code Coverage report doesn't reflect reality coverage of hits and misses - highlighting random lines #587
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
Comments
I'm having a very similar issue to this where like half of a function name is highlighted as a coverage miss. My gut reaction was that it had something to do with a miss match between source maps/transpiled code and the position of code in the report but honestly not 100% sure where to start looking. @Dj-Viking Did you ever figure out the problem and resolve it? |
Hey @Scott-Fischer I haven't been able to figure this out for a very long time, I'm just getting around to opening an issue on it because I am honestly completely lost why this happens. But you might be on to something with transpilation and sourcemapping - I just can't find any way to know how to pinpoint why it happens unless I dedicate a lot of spare time that I cant dedicate to reading tons of source code on this repo. Hoping any Subject Matter Experts who works on this repo to chime in their ideas or input if I'm using this in a non-intended way or if theres missing configuration on my part. |
@Dj-Viking @Scott-Fischer Same here. Spent a lot of time trying to sync the source map with the coverage and I had the same conclusion: sourcemap isn't in sync with the coverage. And when you try to merge code generate by webpack (with ts-loader) + babel (ts preset) + jest, you see again that it is not aligned. I was just able to reduce a bit the differences by building the app without any optimization, in dev mode and then it was ok |
I had a little time today to read through some of the source code. There is a function called code-coverage/support-utils.js Line 137 in 16ef891
|
and the function is called here which doesn't return anything my guess is the coverage object is passed by reference and modified in place...but I just dont quite understand it...Just a shot in the dark. Line 149 in 16ef891
|
Interesting, I had to fix this path because of this function. I am running tests on multiple machines/VM (parallel) and the absolute path of each file is an issue when you want to merge or generate reports on another machine/VM. Could it be the reason for having the wrong highlights? I don't think because IMO this is related to the generated code that is used by the instrumentation that is not inline with the source map. But the source map is present |
@jogelin When you say that you are providing absolute file paths, do you mean when identifying which files to include/exclude from tests/coverage? For example, via For what it's worth, I've only only been experimented with cypress coverage locally so I don't think it's a specific issue of running things in parallel. I was thinking though, perhaps there's some commonalities between our projects that we could use to identify where things are going wrong. My project is using both |
@Scott-Fischer I am using But I was explaining that, because of the For example, if you are generating 2 reports containing the same file, then the absolute path will be different and then they will be considered as 2 different files. Si mainly by removing the absolute path, the path to the files are equals and the merge works correctly. But I also have this issue locally concerning the highlight of the coverage using |
Another interesting development I just found. My initial discovery of this problem was occurring in a completely customized tool chain that was set up manually. So there's a lot of moving pieces/configs and it was really tough to track down the exact source of this problem. e.g. typescript, babel, webpack etc etc. However, we have a separate react frontend client that was created with CRA. It was initially just a JS app and we had code coverage through @cypress/instrument-cra + cypress-io/code-coverage which was working fine. We then converted the app to typescript and started slowly migrating .js files to typescript. However, the coverage report would only list .js files and that's likely because This ultimately worked in generating the coverage for our TS files. But to my surprise, the exact same issue started to occur where the I tried various ways of generating source maps (through TSC, through babel, through webpack, inline, external files, etc) and did not have any success in resolving the issue. So I'm wondering, is the problem in the cypress coverage plugin? Or is the issue actually in the underlying babel-plugin-istanbul module? Because when using @cypress/instrument-cra to instrument the JS code, cypress-io/code-coverage worked perfectly. |
@Scott-Fischer Hey man I think you have a point there! There could be some configuration settings that are incorrect/missing with babel-plugin-istanbul that we're not aware of I suppose. I will play with the settings a bit more, we may need to override some default values that are causing us some headache 😓 |
So I did some more digging this weekend and I looked at the sourceMapped file and it looks to me with the .vue files the actual .ts file that is being mapped to doesn't include the template part. the top of the file is right were the script tag starts, which makes sense I suppose since the whole .vue file is mostly governed by everything in the <script> tag....but there is some logic within the template as well. So I just have no clue how anything is being transformed and then source mapped. I am not sure if these plugins have been accounted for the most recent changes to vue3 apps or typescript apps in general because of the transpilation process where the code that executes in the browser are I have had decent success of getting accurate source mapping of the vue files when using jest with vue. but I found it not as intuitive for what I am really trying to test on the app (as if a user was using the application and not a fake browser environment) and have coverage resulting from this "automated test user". I am just very lost how to set up the app properly for code coverage. I can't find any up to date instructions anywhere. I found one official post by Gleb himself on instrumenting a vue app but it is using vue2 and I am using vue3 so I am not sure if the instructions apply anymore. |
Anyone have an idea how to fix this? Is it even related to the code-coverage package at all? |
We have the similar issue too, Did you manage to fix this @Dj-Viking ? |
@vishnu-exerp nope :( |
2024, I have the same problem with a angular15 application |
The issue is summarized with:
When I inspected the source instrumented code I found e2e test ignoring some lines from instrumenting causing the problem we are facing The proper fix for this issue is for the e2e tests code-coverage plugin to report all lines the same way jest does |
Logs and screenshots
I'm not sure if I understand this debug step here below. I don't know where the logs are output or if this variable is set before starting the client app or before running the cypress tests. my
npm run dev
command may be slightly different than what is expected in the README.Please provide debug logs by running Cypress from the terminal with
DEBUG=code-coverage
environment variable set, see the Debugging section of the README file.Versions
latest - v3.10.0
n/a
latest - v10.6.0
MacOS Catalina 10.15.7
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
v16.14.2
v8.5.0
window.__coverage__
object? Can you paste a screenshot? -yes
.nyc_output
folder? Is there.nyc_output/out.json
file. Is it empty? Can you paste at least part of it so we can see the keys and file paths? -folder and file is there, not empty
package.json
(nyc
object) or in other NYC config files -yes
no
Describe the bug
A clear and concise description of what the bug is.
It seems for some reason the hit and miss highlighting is not accurate at all in the .vue files, I cant really tell what I need to cover what's being missed in the .vue files. It just seems like it highlights random places and shows IF ELSE branching in random places where there is no IF ELSE branch in the line coverage report files.
Link to the repo
Bugs with a reproducible example, like an open source repo showing the bug, are the most likely to be resolved.
killall node
as the concurrent shell command running the client dev server and the headless cypress tests, will keep a background shell running of the client dev server even with a SIGTERM in the current foreground shell.Thanks for your time,
Anders a.k.a. DJViking
The text was updated successfully, but these errors were encountered: