Page MenuHomePhabricator

[RN72][skip-ci] Update Jest to 29
ClosedPublic

Authored by ashoat on Jan 4 2024, 12:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 31, 5:22 AM
Unknown Object (File)
Oct 5 2024, 9:33 PM
Unknown Object (File)
Oct 3 2024, 1:24 PM
Unknown Object (File)
Oct 3 2024, 1:24 PM
Unknown Object (File)
Oct 3 2024, 1:24 PM
Unknown Object (File)
Oct 3 2024, 1:24 PM
Unknown Object (File)
Sep 3 2024, 9:13 PM
Unknown Object (File)
Aug 29 2024, 7:05 AM
Subscribers

Details

Summary

As part of upgrading to React Native 0.72, react-native-upgrade-helper prompts us to update Jest
to 29.

To separate this work out into its own independently-landable stack, I decided to make the Jest update BEFORE making the React Native update. Later in this stack I'll be updating versions of
ESLint, Prettier, and Babel as well.

Test Plan

yarn jest-all from the repo root

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

keyserver/package.json
44 ↗(On Diff #35209)

react-native-upgrade-helper sets us to ^29.2.1 here, but that should result in the same version anyways, so I figured I'd set the higher value here

lib/package.json
30 ↗(On Diff #35209)

Since we use jest from within lib, I figured it would be good to add this for completeness. It turns out to not actually be necessary because multiple other workspaces use this package, which results it in being hoisted to the workspace root

web/database/utils/worker-crypto-utils.test.js
1–3 ↗(On Diff #35209)

Jest 27 changes the default "Jest environment" from "jsdom" to "node" – see here.

In general, we want to use jsdom in the web workspace, since we depend on things like the window global in other tests. For that reason, our Jest config is updated in web/package.json below to default to jsdom.

However, using jsdom breaks this test and the next one. The issue is that jsdom doesn't yet support webcrypto.

We'd been getting around this in web/jest-setup.js by utilizing a polyfill built into recent versions of Node's crypto module (crypto.webcrypto). However, that doesn't seem to work with the jsdom environment.

Since we don't actually need any of the jsdom features, I was able to get around that by swapping this test and the next one to use the node environment. This should be fine as long as we don't have any tests that need BOTH the jsdom and node features. If we ever do, we can swap to using the external polyfill suggested here.

web/package.json
35 ↗(On Diff #35209)

Jest 28 no longer includes jest-environment-jsdom, so we must install it separately ourselves

118 ↗(On Diff #35209)

Jest 27 changes the default "Jest environment" from "jsdom" to "node" – see here.

In general, we want to use jsdom in the web workspace, since we depend on things like the window global in some tests.

Should we also update "eslint-plugin-jest" and flow-typed/npm/jest_v26.x.x.js?

Maybe those changes were planned for later in the stack?

This revision is now accepted and ready to land.Jan 4 2024, 12:18 PM

eslint-plugin-jest is updated in D10538. Thanks for calling out the flow-typed file; will rename that file before landing to reflect the newer version number

Actually, ended up updating the libdefs in a separate diff since it touched 4 files: D10545