Skip to content
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

fix: Error Cannot read property converageData of null #7758 #8168

Conversation

c0d3m3nt0r
Copy link
Contributor

@c0d3m3nt0r c0d3m3nt0r commented Mar 20, 2019

Summary

This PR is meant to fix #7758. In the provided GitHub issue link there are repro steps, also an explanation of the fix applied in this PR #7758 (comment).

Test plan

A new pair of tests were added to cover these changes.

Jest Output:

➜  jest git:(fix-cannot-read-property-converageData-of-null) yarn jest-coverage -u packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js
yarn run v1.15.0
$ yarn jest --coverage -u packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js
$ node ./packages/jest-cli/bin/jest.js --coverage -u packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js
 PASS  packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js
  generateEmptyCoverage
    ✓ generates an empty coverage object for a file without running it (516ms)
    ✓ generates a null coverage result when using /* istanbul ignore file */ (53ms)
    ✓ generates a null coverage result when collectCoverage global config is false (1ms)

Coverage Output:

-----------------------------------------------|----------|----------|----------|----------|-------------------|
File                                           |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------------------------------------------|----------|----------|----------|----------|-------------------|
generateEmptyCoverage.ts                       |      100 |    83.33 |      100 |      100 |                47 |
...

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@c0d3m3nt0r c0d3m3nt0r changed the title fixFix Error Cannot read property converageData of null #7758 [WIP] fix: Error Cannot read property converageData of null #7758 Mar 20, 2019
@c0d3m3nt0r
Copy link
Contributor Author

@SimenB,

We have the same issue described in #7758 in our current application setup, with the following dependencies:

"jest": "^24.5.0",
"jest-haste-map": "^24.5.0",
"babel-jest": "^24.5.0"

Changes in this PR fix the issue. In addition I have added a couple more tests, and everything looks good from our side.

Let me know what do you think.

Thank you!

@c0d3m3nt0r c0d3m3nt0r changed the title [WIP] fix: Error Cannot read property converageData of null #7758 fix: Error Cannot read property converageData of null #7758 Mar 20, 2019
@codecov-io
Copy link

codecov-io commented Mar 20, 2019

Codecov Report

Merging #8168 into master will increase coverage by 0.02%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8168      +/-   ##
==========================================
+ Coverage   62.24%   62.26%   +0.02%     
==========================================
  Files         265      265              
  Lines       10448    10450       +2     
  Branches     2540     2541       +1     
==========================================
+ Hits         6503     6507       +4     
+ Misses       3360     3359       -1     
+ Partials      585      584       -1
Impacted Files Coverage Δ
...ckages/jest-reporters/src/generateEmptyCoverage.ts 90% <80%> (+27.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ecf7636...39b2fe0. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for tackling it!

Can you update the changelog and sign the CLA, and I can merge this 🙂

@thymikee thymikee force-pushed the fix-cannot-read-property-converageData-of-null branch from d3541e4 to 39b2fe0 Compare March 20, 2019 11:59
@thymikee thymikee merged commit abee765 into jestjs:master Mar 20, 2019
@kachkaev
Copy link
Contributor

If 24.6.0 is somewhat away, it'd be awesome to have this fix in 24.5.1 🙏 The bug is blocking us from upgrading from Jest 23 and we can't wait to do this! @c0d3m3nt0r many thanks for your your time and effort! 🙌

@c0d3m3nt0r
Copy link
Contributor Author

@thymikee, @SimenB, thank you for taking the time to review and merge these changes!, we will be waiting for them to be released.

@kachkaev, no problem!

@vicapow
Copy link

vicapow commented Mar 28, 2019

@c0d3m3nt0r Still planning on publish this with 24.5.1 ? This is also preventing us from updating :/

@SimenB
Copy link
Member

SimenB commented Mar 29, 2019

A release is coming when we land the open PRs with performance improvements :)

@kachkaev
Copy link
Contributor

kachkaev commented Apr 1, 2019

Seems like all pull requests mentioning Performance in their title have been merged 👀🙌 Well, at least the ones that were at the top of the PR list 😁

@kachkaev
Copy link
Contributor

kachkaev commented Apr 8, 2019

Can it be that because of this PR files that have zero covered lines are now totally ignored? I noticed a significantly higher coverage percentage after upgrading from 23 to 24 and then realised that uncovered files are simply removed from the reports 🤔

@SimenB
Copy link
Member

SimenB commented Apr 8, 2019

That might very well be! Would you be able to put together a reproduction?

@kachkaev
Copy link
Contributor

kachkaev commented Apr 8, 2019

Only seeing this in our team's gigantic repo for now. Will try producing an MWE and submitting an issue 😉

@kachkaev
Copy link
Contributor

kachkaev commented Apr 8, 2019

It may well be that our collectCoverageFrom RegExp simply broke after upgrading from 23 to 24 (something to do with micromatch upgrade in #6650?). At least I cannot reproduce the bug in a new test project:

## Try collecting coverage with Jest 24

# cd new-empty-folder

cat << EOF > package.json
{
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.js"
    ]
  }
}
EOF

cat << EOF > .babelrc
{ "presets": ["@babel/preset-env"] }
EOF

yarn add --dev @babel/core @babel/preset-env jest

mkdir src

cat << EOF > src/a.js
export default () => "a";
EOF

cat << EOF > src/b.js
export default () => "b";
EOF

cat << EOF > src/b.test.js
import b from "./b";
test("b works", () => {
  expect(b()).toEqual("b");
});
EOF

yarn jest --coverage

## Downgrade to Jest 23

yarn remove --dev @babel/core @babel/preset-env jest
yarn add --dev babel-core babel-preset-es2015 jest@23
cat << EOF > .babelrc
{ "presets": ["es2015"] }
EOF

yarn jest --coverage

Both source files (a.js and b.js) are included into the coverage report in Jest 24 just as in Jest 23. I'll try checking again tomorrow when I'm back at work 😉

@kachkaev
Copy link
Contributor

kachkaev commented Apr 9, 2019

Strange, but in the monorepo where I spotted the issue in the first place, collectCoverageFrom still does not work. It's defined as ["src/**/*.{js,jsx,ts,tsx}"], I tried ["<rootDir>/src/**/*.{js,jsx,ts,tsx}"] and ["**/*.{js,jsx,ts,tsx}"]. The coverage is collected, but only for the files that have at least line covered (as if collectCoverageFrom was not defined).

Related issue: #8207

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error Cannot read property converageData of null
7 participants