Error when merging Jest coverage using nyc
See original GitHub issueš Bug Report
Iām using nrwlās nx with angular, jest and cypress. For unit test code coverage reports I execute npm run test -- --code-coverage and the report looks good when opening. Now Iād like to use nyc to merge this report with the one generated from cypress. Running nyc merge runs fine on the cypress coverage json, but on Jestās I get Invalid file coverage object, missing keys, found:data When I look in the coverage-final.json file from Jest, I do see html objects containing data properties, while the .ts objects have keys properties. The cypress coverage-final.json output has html objects containing keys properties, which leads me to believe the problem is with the way Jest outputs coverage under certain circumstances. Possibly itās an Istanbul issue, but Iām posting it here as it seems Istanbulās nyc, that uses the same version of Istanbul as Jest is not able to process the coverage files.
Also worth mentioning, with Jest 24 the coverage-final.json didnāt contain data properties in html entries.
To Reproduce
Not able to reproduce using a minimal setup.
Expected behavior
No data properties to be present on file objects in coverage-final.json.
Link to repl or repo (highly encouraged)
I created a small setup but there the data properties on the .html files somehow were not present. So at the moment I am unable to reproduce outside of the environment this is happening.
envinfo
System:
OS: Windows 10 10.0.18363
CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Binaries:
Node: 13.6.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.0 - C:\Program Files\nodejs\yarn.CMD
npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
npmPackages:
jest: 25.2.4 => 25.2.4
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7

Top Related StackOverflow Question
@postmodernistx thanks, with your comment I got it fixed! In my case HTML files were the troublemakers and I could fix it by adding this to
jest.config.js:If it might help anyone, hereās what I ended up doing (probably not a great solution, though š ):
The code coverage report generated by Jest, when utilizing
vue-cli-service test:unitadded thedatakey to all files that were (in my case).png,.stories.jsand.(spec|test).(js|ts).In my
jest.config.jsI could remove some of those troublemakers by adding thecoveragePathIgnorePatternsproperty:But this didnāt cover all cases, so I ended up writing a tiny script that stripped the
coverage-final.jsonfile of the remaining items with the data property. Some mad regex skills could probably have covered those cases in the coveragePathIgnorePatterns array.Screenshot example below (coverage-final.json),
pngfiles have thedataproperty but regularvuecomponents donāt: