question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'coverageData' of null when trying to generate code coverage

See original GitHub issue

šŸ› Bug Report

See reproduction repo for better understanding

When trying to generate a coverage with jest, the tests run as they should, but no coverage data is collected and there’s a ā€˜Cannot read property ā€˜coverageData’ of null’ error in the console. This is likely because jest right now can’t work with the unique folder structure that we have on our project (see the reproduction repo).

The folder where the package.json and node_modules are right next to the folder where all the source files are. When the file to test and the test itself is in the same folder as the node_modules the coverage data is collected perfectly, however when it is in the folder next to the folder with the node_modules, it display the error mentioned in the first paragraph.

Feel free to close this if it’s not a bug with jest, but at this point I cannot think of anything else that could be wrong here (other than our legacy folder structure).

To Reproduce

Steps to reproduce the behavior:

  • checkout this repo

  • run the commands in the project’s README

  • see the console for the error message

Expected behavior

Expected the coverage data to be collected and put out to the console.

Link to repl or repo (highly encouraged)

reproduction repo link

Run npx envinfo --preset jest

Paste the results here:

System:
    OS: macOS 10.14.1
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v10.15.1/bin/npm
  npmPackages:
    jest: ^24.1.0 => 24.1.0 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
apoorvkkcommented, Mar 3, 2019

@wfortin As a short term and quick solution, I rolled back to jest@23.6.0 and I am able to see coverage on all files and run tests as per normal. Once there is a fix, I will update Jest to v24. Note that if you do rollback, make sure to use setupTestFrameworkScriptFile (deprecated in v24) instead of setupFilesAfterEnv for your jest setup file location. See https://github.com/facebook/jest/issues/7758#issuecomment-459052457

2reactions
wfortincommented, Feb 27, 2019

Is there any workaround while we wait for an official fix for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

istanbuljs/nyc
Hi Guys, Im trying to implement Istanbul for code coverage of client side js (we run acceptance tests using codeceptjs).....is there any documentation...
Read more >
Fixing TypeError: Cannot read property `property` of null in ...
Recently, I ran into some problems while attempting to snapshot test my React code. TypeError: Cannot read property 'focus' of null.
Read more >
Jest Testing Coverage - Errors When Files Don't Have Tests
I have Jest tests in my React project, and I don't have coverage on all files ... ERROR: Cannot read property 'coverageData' of...
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... Indicates which provider should be used to instrument code for coverage.
Read more >
Configuring Jest compiled
If you want to use your package.json to store Jest's config, ... Test files will normally be ignored from collecting code coverage.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found