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
Code coverage option is not returning correct coverage #40
Comments
Firstly, you should definitely be on version 0.4.11 or higher. Even if the output is unexpected for now. The bug fixed in 0.4.11 is needed for expected results. Looking into your sample project after bumping to lwc-jest to version 0.4.12, I noticed both your LWC javascript files are essentially empty classes. Once you add more code into the classes you'll see it starting to behave as expected. This is why you get the I agree, however, that even with a skeleton class file for a component it should still show up on the coverage report as having 0% coverage. Let me dig in to this more and get back to you. For now though I don't think there's any bug at the lwc-jest configuration level. |
This is fixed in Jest 24+.
For the next major release we can upgrade Jest to fix this issue. Components with logic in their js classes should still report coverage as expected. |
Both classes have the same pretty much empty .js file. If all three lwc-jest versions are built against Jest v23, why does the one with a test show up in 0.4.10, but not in 0.4.11 or 0.4.12? Why does the one file with a test show up as a ".html.compiled" file in 0.4.10 instead of a .js file (even though **/.js files are the only ones being added to the lwc-jest collectCoverageFrom classpath in https://github.com/salesforce/lwc-jest/blob/master/src/config.js for getCoveragePaths()? Is getCoveragePaths() actually returning the correct file filter? Is code coverage actually being compiled against .js instead of .html.compiled files?) |
The bug present in 0.4.10 returns undefined for Coverage should be calculated against the javascript, not the html or html.compiled files. I really don't think it's worth trying to figure out what exactly is wrong in 0.4.10 because we're on a higher version and remember, we get the LWC core version from this package so using an older version of |
The only code-coverage-related difference between 0.4.10 and 0.4.12 is the return path for collectCoverageFrom, so I assume any underlying coverage issues in 0.4.10 will still be present in 0.4.12. It sounds like what you're saying is --coverage is not completely functional in the current version of lwc-jest, and should be fixed in the next major release (with the upgrade to Jest 24+ compliance). Is that accurate? |
Yes. Not fully functional for empty component classes. I have verified locally the empty classes are properly reported in coverage reports with Jest version 24. |
Awesome, thank you so much Trevor! |
I'm seeing some strange behavior with the reported coverage of a component. I'm on lwc-jest version 0.5.1. The lines that are highlighted red are marked as "uncovered", yet I don't see how that could be given the surrounding lines being covered. For example, how could I tried exposing the I tried adding a comment, and that line now appeared as uncovered, so it seems as though the uncovered lines are always the same lines, regardless of what the file looks like. Additionally, my file is only 61 lines long, but the "uncovered lines" section of the coverage output in the terminal shows line 80 as being uncovered. |
@BatemanVO Can you share a repository with some reproduction steps? |
@pmdartus I've created a shareable repo. If you clone it down, run Everything should run just fine if you deploy the classes in the classes folder, and you may need one custom label called "Alphabetize_Batch_Explanation" in the Org. |
@BatemanVO I pulled down the repo you shared and I'm seeing coverage numbers on both Mac and Windows. Here's a screenshot of my results running Are these not the results you are expecting? |
@trevor-bliss That's the same result I get - except those uncovered line numbers don't make any sense. I opened up the I imagine that somehow |
Also pulled down the repository, at this commit. That being said running
I realized that the imported module is With that out of the issue out of the way here is a screenshot of the reported coverage which looks right to me. @BatemanVO what is the OS of the machine? |
@pmdartus Changing the import statement to correctly reference the lowercased I am on Windows 10, Version 1803 (OS Build 17134.885). |
This is really interesting. I also see coverage change on a Mac by changing the case. I've seen cases locally and on Jest issues about case-sensitivity, but they usually lead to hard failures on non-Mac environments, not just slightly different results like this. Would love to know what the root cause is if anyone has time to dig into the sub-packages. |
Hi all!
I'm trying to get code coverage numbers for all LWC .js files (not just the ones with tests). I'm seeing some weird / probably unexpected behaviour with lwc-jest in versions 0.4.10, 0.4.11, and 0.4.12, and also cannot override the codeCoverageFrom attribute in jest.config.js in a way that would pick up the results. There seems to be some strange interaction between lwc-jest and basic jest which is causing this issue.
Setup:
I have a SFDX project with 2 LWC components:
When I run:
lwc-jest --coverage
I'm hoping to see a result for all my LWC components (including those without tests).
(where "blah" represents a made-up value)
What I actually see is:
In 0.4.10:
In 0.4.11 and 0.4.12:
If I try to override codeCoverageFrom at either the CLI (--codeCoverageFrom) or extending jest.config.js , then lwc-jest does not pick up ANY results from the /lwc/ directory.
This is configured with
**/*.js
, which picks up all other .js files - but no results from /lwc (not even the element with a test). This happens in 0.4.10 - 12.Running with --verbose does not give any additional information or error messages :(
Is there some way to configure lwc-jest code coverage to return results for all LWC elements please? Thanks in advance!
The text was updated successfully, but these errors were encountered: