react icon indicating copy to clipboard operation
react copied to clipboard

Upgrade jest to v29

Open eps1lon opened this issue 4 years ago • 15 comments

Waiting for release of https://github.com/facebook/jest/pull/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

  • [x] CI green

eps1lon avatar May 27 '21 10:05 eps1lon

Comparing: 9c3de25e1ce52066c0518b3ca0803b69e684edd6...8d0a41db541d261b1a57274868da9ec3a2b22bd2

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 :no_entry_sign: dangerJS against 8d0a41db541d261b1a57274868da9ec3a2b22bd2

sizebot avatar May 27 '21 10:05 sizebot

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

eps1lon avatar Mar 08 '22 08:03 eps1lon

Anything blocking this?

gaearon avatar Apr 03 '22 18:04 gaearon

Anything blocking this?

I noticed an issue when running updateSnapshot on useId tests (running --updateSnashot without https://github.com/facebook/react/pull/21575/commits/e44ea790c98e79804c40619ffd8a6b7ef3869f40). So I'd like to check if this is already broken on main or new with Jest 27.

eps1lon avatar Apr 03 '22 19:04 eps1lon

@gaearon https://github.com/facebook/jest/issues/11561 is blocking this update. Jest without --updateSnapshot would be quite boring.

eps1lon avatar Apr 04 '22 17:04 eps1lon

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

SimenB avatar Aug 19 '22 14:08 SimenB

@SimenB Currently stuck on 28. Seems like Jest now requires file extensions in the imports?

ENOENT: no such file or directory, open '/home/eps1lon/Development/forks/react/packages/react/src/ReactSharedInternals'

      146 | // the React package itself.
      147 | jest.mock('shared/ReactSharedInternals', () =>
    > 148 |   jest.requireActual('react/src/ReactSharedInternals')
          |          ^
      149 | );
      150 |
      151 | jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));

eps1lon avatar Sep 10 '22 13:09 eps1lon

I'd guess it's somehow some weird moduleNameMapper: https://github.com/facebook/react/blob/3613284dceac38de4ef5a7c93c4897600ee6923b/scripts/jest/config.build.js#L57

Not 100% sure tho - I can take a look

SimenB avatar Sep 10 '22 13:09 SimenB

Ah, it's https://github.com/facebook/react/blob/3613284dceac38de4ef5a7c93c4897600ee6923b/packages/react/package.json#L22-L31

Should improve the error to specify it's due to no exports entry


EDIT: huh, the "./src/*": "./src/*" should work, shouldn't it? 😅

EDIT2: ah, it's because jest doesn't try to resolve after getting the path back after looking at exports: https://github.com/facebook/jest/blob/1a767e0f1fc21c008ce77a69eda914c152cc067b/packages/jest-resolve/src/defaultResolver.ts#L114-L118

I'll fix in Jest 29, but if you wanna land v28 you'll need patch-package or something (or add the extension).


After that, there are two more errors:

image image

First is easy to fix

diff --git i/scripts/jest/ReactDOMServerIntegrationEnvironment.js w/scripts/jest/ReactDOMServerIntegrationEnvironment.js
index d880e5b1c..a59268379 100644
--- i/scripts/jest/ReactDOMServerIntegrationEnvironment.js
+++ w/scripts/jest/ReactDOMServerIntegrationEnvironment.js
@@ -1,7 +1,7 @@
 'use strict';
 
-const JSDOMEnvironment = require('jest-environment-jsdom');
-const NodeEnvironment = require('jest-environment-node');
+const {default: JSDOMEnvironment} = require('jest-environment-jsdom');
+const {default: NodeEnvironment} = require('jest-environment-node');
 
 /**
  * Test environment for testing integration of react-dom (browser) with react-dom/server (node)

Second is a bit more work as https://github.com/facebook/react/blob/3613284dceac38de4ef5a7c93c4897600ee6923b/scripts/jest/matchers/toThrow.js#L9 tries to load internal stuff. Not sure about best solution there

SimenB avatar Sep 10 '22 13:09 SimenB

I'll fix in Jest 29, but if you wanna land v28 you'll need patch-package or something (or add the extension).

We need 29 for the JSX inline-snapshot fix so we can just wait for 29 (I hope)

eps1lon avatar Sep 10 '22 14:09 eps1lon

Release of fix for the resolver issue will come today 🙂 But the toThrowMatchers thing needs a resolution

SimenB avatar Sep 10 '22 14:09 SimenB

https://github.com/facebook/jest/releases/tag/v29.0.3

SimenB avatar Sep 10 '22 14:09 SimenB

@SimenB https://github.com/facebook/jest/pull/13328 seems to be the last blocker. Full test suite was green now locally with https://github.com/facebook/jest/pull/13328 applied.

eps1lon avatar Sep 27 '22 18:09 eps1lon

🟢 🥳

SimenB avatar Sep 28 '22 16:09 SimenB

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

SimenB avatar Oct 19 '22 06:10 SimenB

@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. https://github.com/facebook/react/pull/26041

ymqy avatar Jan 30 '23 23:01 ymqy

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

eps1lon avatar Jan 31 '23 03:01 eps1lon

Landed in https://github.com/facebook/react/pull/26088

eps1lon avatar Feb 09 '23 17:02 eps1lon