jest
jest copied to clipboard
Missing coverage information in random lines
🐛 Bug Report
Since update jest to version 27 (27.0.6) we have the problem that on random lines no coverage information are collected. Our project is using Angular. So maybe thats an problem in that combination. I made a minimal angular project with that behaviour. When I run all tests with jest --coverage I got this result: https://biga-software.de/assets/dummy.page.ts.html The method cardMessageText is tested but according to the report there is no coverage availible.
To Reproduce
Don't know just took our project and remove sources.
Expected behavior
Having correctly coverage information. Method is tested.
Link to repl or repo (highly encouraged)
https://github.com/MoritzOtto/jest_coverage_bug
envinfo
System: OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa) CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz Binaries: Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node npm: 7.7.6 - ~/.nvm/versions/node/v15.14.0/bin/npm
Hitting this in react, in my case, somehow:
if (company.logoUrl == null || company.logoUrl == "" || imageLoadFailed) {
- return <BusinessName variant="body1">{company?.name || ""}</BusinessName>;
- }
-
- return (
- <BusinessImage
- onError={() => setImageLoadFailed(true)}
- src={company.logoUrl}
- alt={company.name || ""}
height={40}
/>
);
lines marked with -
are not covered.
Running tests one by one produces result tables that indicate that those lines are covered, but running all tests mark those lines as not covered.
Jest: 27.3.0
Here's a minimal reproduction: https://github.com/CharlesStover/monorepo-template/runs/4734914005?check_suite_focus=true 100% coverage in Jest 26. By simply upgrading to Jest 27, you get uncovered empty lines in a file that only exports.
@CharlesStover It could be that in your case ts-jest
is the issue. Here is what I get:
-
using
jest
27 andbabel
-
using
jest
27 andts-jest
27
@mrazauskas Nice debugging. What configuration did you use for Babel to get those results?
What configuration did you use for Babel to get those results?
Here is the whole babel.config.json
:
{
"presets": [
["@babel/preset-env", { "targets": { "node": "current" } }],
["@babel/preset-react", { "runtime": "automatic" }],
"@babel/preset-typescript"
]
}
To be honest, I have no experience with React. The line with @babel/preset-react
is just a guess.
@CharlesStover Found it. Including "sourceMap": true
in tsconfig.json
makes the jest
v27 and ts-jest
v27 duo work just like you would expect. Seems like ts-jest
changed its defaults: https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md#breaking-changes
using jest 27 and babel
@mrazauskas I am also having the same issue where index.ts
is coming up 0. do you know of a config that would resolve that? also, does it effect reporting overall test coverage?
actually, even with babel, i'm seeing something similar to your ts-jest
example as well
The same issue.
Reproducible repo here - just clone & run npm i && npm test
In my case coverage for single file works correct.
When files were 5...6 - it was ok.
But now when files a lot it's wrong and different time to time (just try to run npm test
several times and compare)
Facing this same problem, but with Jest 26.6.3 in a Node server
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
Ping