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

Upgrade jest to v29 #21575

Closed
wants to merge 23 commits into from
Closed

Upgrade jest to v29 #21575

wants to merge 23 commits into from

Conversation

eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented May 27, 2021

Waiting for release of jestjs/jest#13328

Summary

  • unhandled errors from JSDOM are now proper errors instead of strings
  • no more abortSignal.reason = ... hack in JSDOM environments
  • JSDOM environment by default now

Test Plan

  • CI green

@sizebot
Copy link

sizebot commented May 27, 2021

Comparing: 9c3de25...8d0a41d

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 135.47 kB 135.47 kB = 43.41 kB 43.41 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 147.73 kB 147.73 kB = 47.17 kB 47.17 kB
facebook-www/ReactDOM-prod.classic.js = 491.70 kB 491.70 kB = 87.49 kB 87.49 kB
facebook-www/ReactDOM-prod.modern.js = 477.00 kB 477.00 kB = 85.24 kB 85.24 kB
facebook-www/ReactDOMForked-prod.classic.js = 491.70 kB 491.70 kB = 87.49 kB 87.49 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/jest-react/cjs/jest-react.production.min.js +1.07% 2.42 kB 2.45 kB +1.11% 1.17 kB 1.18 kB
oss-stable-semver/jest-react/cjs/jest-react.production.min.js +1.07% 2.42 kB 2.45 kB +1.11% 1.17 kB 1.18 kB
oss-stable/jest-react/cjs/jest-react.production.min.js +1.07% 2.42 kB 2.45 kB +1.11% 1.17 kB 1.18 kB
oss-experimental/jest-react/cjs/jest-react.development.js +0.25% 10.61 kB 10.64 kB +0.40% 3.75 kB 3.76 kB
oss-stable-semver/jest-react/cjs/jest-react.development.js +0.25% 10.61 kB 10.64 kB +0.40% 3.75 kB 3.76 kB
oss-stable/jest-react/cjs/jest-react.development.js +0.25% 10.61 kB 10.64 kB +0.40% 3.75 kB 3.76 kB

Generated by 🚫 dangerJS against 8d0a41d

@eps1lon eps1lon changed the base branch from master to main June 30, 2021 12:14
@@ -7,7 +7,7 @@

'use strict';

describe('ReactDOMEventListener', () => {
describe('ReactDOMEventPropagation', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drive-by change. The suite name now matches the file name.

Comment on lines -19 to +24
React = require('react');
jest.isolateModules(() => {
OuterReactDOM = require('react-dom');
InnerReactDOM = require('react-dom');
});
jest.isolateModules(() => {
InnerReactDOM = require('react-dom');
React = require('react');
OuterReactDOM = require('react-dom');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes https://app.circleci.com/pipelines/github/facebook/react/21294/workflows/b23b2fbb-9d67-447c-b395-21591b60ebf1/jobs/411166.

Probably required due to jestjs/jest#10963. Though it's unclear why this test passed without this change using scripts/jest/config.source-www.js but failed using scripts/jest/config.build.js.

@SimenB Any idea if this is intended?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds odd that changing config impacts module loading. My only guess is

// Map packages to bundles
packages.forEach(name => {
// Root entry point
moduleNameMapper[`^${name}$`] = `<rootDir>/build/${NODE_MODULES_DIR}/${name}`;
// Named entry points
moduleNameMapper[
`^${name}\/([^\/]+)$`
] = `<rootDir>/build/${NODE_MODULES_DIR}/${name}/$1`;
});
makes it resolve to differing modules somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The modules were all coming from the mapped paths.
To be clear: It makes sense that the used React needs to be the same one that's used by OuterReactDOM and therefore needs to be in the same isolatedModules callback. What's odd is, that this isn't the case with scripts/jest/config.source-www.js.

So ideally we'd have two isolated copies of react-dom that somehow share the same react copy. This no longer seems possible with Jest 27

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems you've worked around this, but a solution might be a new API which lets you selectively evict specific modules from the cache? jest.resetModule('react-dom') or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't thought about this for a while but if I remember correctly, I came to the conclusiong that the old code should never have worked to begin with. Not sure if it's worth revisiting since this testing pattern is very specific.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds very reasonable 👍 It does sound like a weird edge case, but happy to revisit it if proves to actually guard against some regression 🙂

@eps1lon eps1lon marked this pull request as draft March 7, 2022 19:48
@eps1lon eps1lon force-pushed the chore/jest-27 branch 3 times, most recently from 45bac8e to 0166dd3 Compare March 8, 2022 08:34
@eps1lon
Copy link
Collaborator Author

eps1lon commented Mar 8, 2022

Some CI shards are failing with out-of-memory errors. Going to take a while identifying the memory leaks.

@eps1lon eps1lon changed the title Update jest to v27 Upgrade jest to v27 Mar 19, 2022
@eps1lon eps1lon force-pushed the chore/jest-27 branch 2 times, most recently from a86d1ea to e44ea79 Compare March 20, 2022 12:41
@gaearon
Copy link
Collaborator

gaearon commented Apr 3, 2022

Anything blocking this?

@eps1lon
Copy link
Collaborator Author

eps1lon commented Apr 3, 2022

Anything blocking this?

I noticed an issue when running updateSnapshot on useId tests (running --updateSnashot without e44ea79). So I'd like to check if this is already broken on main or new with Jest 27.

@eps1lon
Copy link
Collaborator Author

eps1lon commented Apr 4, 2022

@gaearon jestjs/jest#11561 is blocking this update. Jest without --updateSnapshot would be quite boring.

@SimenB
Copy link
Contributor

SimenB commented Aug 19, 2022

Easiest to unblock is probably to float a patch (e.g. patch-package) just removing https://www.runpkg.com/[email protected]/build/InlineSnapshots.js#222. The fix for the above issue will be in Jest 29, but going from 26 straight to 29 sounds like a lot 😀

At least as long as babel config is available to babel's own way of looking it up. If not, straight to 29 might be needed

@eps1lon eps1lon changed the title Upgrade jest to v27 Upgrade jest to v28 Sep 10, 2022
@eps1lon

This comment was marked as resolved.

@SimenB

This comment was marked as resolved.

@@ -470,7 +484,6 @@ describe('ReactDOMFloat', () => {
<head />
<body>
foo
<link rel="preload" as="style" href="foo" />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to the test, its actions should be run on the server. But as far as I can tell, there's only a client dispatcher (ReactDOMClientDispatcher).

@gnoff Do you have a e2e test for this scenario so that we can verify where the test environment might not be setup properly?

Jest has become a lot stricter with mixing environments and these sort of tests break due to strict environment separation. IMO this is ok behavior from Jest since it makes it more obvious where particular code is running.

@SimenB
Copy link
Contributor

SimenB commented Oct 19, 2022

React Native and Metro have both upgraded to v29. Would be great if React could as well! 😀

@ymqy
Copy link
Contributor

ymqy commented Jan 30, 2023

@eps1lon Why hasn't this pr been merged yet? I submitted a pr and all the ci tests have passed. It includes more optimization upgrades. #26041

@eps1lon
Copy link
Collaborator Author

eps1lon commented Jan 31, 2023

Because it has merge conflicts and was not reviewed in its latest state

@ymqy ymqy mentioned this pull request Feb 1, 2023
@eps1lon
Copy link
Collaborator Author

eps1lon commented Feb 9, 2023

Landed in #26088

@eps1lon eps1lon closed this Feb 9, 2023
@eps1lon eps1lon deleted the chore/jest-27 branch February 9, 2023 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants