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 v28 #126

Merged
merged 1 commit into from
Jun 7, 2022
Merged

Upgrade Jest to v28 #126

merged 1 commit into from
Jun 7, 2022

Conversation

nmanu1
Copy link
Contributor

@nmanu1 nmanu1 commented Jun 7, 2022

This PR upgrades Jest from v27 to v28. Most of the breaking changes don't affect us, except for two:

  • To use the JSDOM test environment, jest-environment-jsdom now has to be installed separately. But, this means a newer version of jsdom is used, which assumes there is a global TextEncoder, that is not provided by jest-environment-jsdom. This issue is fixed by re-exporting Node util's TextEncoder as global.TextEncoder in setup-env.ts
  • Jest now has full support for package exports, which can cause problems where file imports are not resolved correctly. Specifically, this is a problem for uuid. There is a discussion and proposed solution in this GitHub issue, which I used in this PR. To summarize, the fix is to add a custom resolver that forces Jest to use the CommonJS+node version of uuid, but leaves all other resolutions the same

J=SLAP-2123
TEST=auto

See that Jest tests pass.

@nmanu1 nmanu1 requested a review from a team as a code owner June 7, 2022 15:57
@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.889% when pulling e0308fe on dev/upgrade-jest into 65127b8 on develop.

@@ -1,5 +1,8 @@
import { server } from './server';
import '@testing-library/jest-dom';
import { TextEncoder } from 'util';

global.TextEncoder = TextEncoder;
Copy link
Contributor

@oshi97 oshi97 Jun 7, 2022

Choose a reason for hiding this comment

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

Is jest-environment-jsdom broken? I looked in their package.json and they have jsdom^19 as a dependency so it feels weird that wouldn't just work? They also have "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" in their engines field so we should be good in terms of node versions?
for your convenience https://github.com/facebook/jest/blob/main/packages/jest-environment-jsdom/package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a better explanation of the issue here and the solution is pretty much the same as what they used: microsoft/accessibility-insights-web#5421 (comment)
There's also this open issue for it: jsdom/jsdom#2524

Copy link
Contributor

Choose a reason for hiding this comment

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

@nmanu1 nmanu1 merged commit 9313517 into develop Jun 7, 2022
@nmanu1 nmanu1 deleted the dev/upgrade-jest branch June 7, 2022 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants