-
Notifications
You must be signed in to change notification settings - Fork 82
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
Incorrect coverage when mocked apex function and copyright placed before its import #320
Comments
Our team was on v1.3.0 and just updated to v1.4.1 today, but began encountering the same issue sporadically with any comments whatsoever before import statements. It doesn't occur on all files / tests, but after updating to the latest version, a significant number of them started reporting that line 1 was uncovered, which was just the opening to a comment block. Moving the comments beneath all import statements resolves the issue. Here is a sample file that is affected:
Moving the comment from line 1 to line 5, beneath the import statements, fixes the coverage issue. Here is a sample file that is not affected:
So as noted in the original issue, it appears to be related to files that import Apex functions. sfdx-lwc-jest v1.4.1 |
I wonder if this would be fixed with a Jest update. Currently |
Could someone who is having this issue please provide a GitHub repo that we can use to test? From the bug description, it's hard to tell where to put which files (and with which filenames) in order to reproduce the issue. Thank you! |
@nolanlawson Here is a link to a barebones repo where I can reproduce the issue. Here is the coverage reported with the comment left at the top of the file: Here is the coverage reported if I move the comment two lines down, beneath the import statements: EDIT: As an additional note, if I uninstall 1.4.1 and reinstall to the latest version, 2.2.0, I still get the same issue. |
Thanks a lot @BatemanVO! With your repo (using Unfortunately, it looks like upgrading to Jest v29 does not resolve the issue: This will require some more digging to figure out what's going on. |
Same issue is present in our sfdx project. I created also similar git repository where it can be tested https://github.com/zoranmilovanovic/jest-coverage-issue Is there any update on this issue? |
Just updated a couple of our repos to sfdx-lwc-jest 4.0.1 today and still encountering the same issue. Some files that were not affected with version 3.0.1 were affected after updating to 4.0.1, but I didn't see anything significant between the ones affected in 4.0.1, but not 3.0.1, compared to the ones that were affected in 3.0.1 - it still seems to be tied to importing apex methods. |
Still seeing the issue with sfdx-lwc-jest 5.0.0 as of today, though have noticed a slight change in behavior. The coverage tool still reports comments before import statements as uncovered, but instead of always reporting line 1 as uncovered, the line reported is the last comment using
Will report line 2 as uncovered, whereas:
will report line 3 as uncovered. EDIT, 10/16/2024: Still occurring as of 5.1.0. |
Description
First of all, my apologies if the issue description lacks enough details or it is not thorough enough as it is the first issue I report via Github. After upgrading some dependencies in the company's repo it was noticed a degradation in the function's coverage due to a new function added to the calculation that turns out to be coming from the Apex function being imported. It occurs when this function is mocked in the test class and the JS class under testing has a copyright before the import (which is mandatory in our company's policy).
Steps to Reproduce
# Command to repro npm run lwc-jest --coverage
Expected Results
Function coverage to be 100%
Actual Results
Function coverage is 66.66%
Version
Additional context/Screenshots
The text was updated successfully, but these errors were encountered: