Conversation
| import '@testing-library/jest-dom'; | ||
| import { TextEncoder } from 'util'; | ||
|
|
||
| global.TextEncoder = TextEncoder; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Ah ok got it! I read up on it and it seems pretty common https://stackoverflow.com/questions/57712235/referenceerror-textencoder-is-not-defined-when-running-react-scripts-test
This PR upgrades Jest from v27 to v28. Most of the breaking changes don't affect us, except for two:
jest-environment-jsdomnow has to be installed separately. But, this means a newer version ofjsdomis used, which assumes there is a globalTextEncoder, that is not provided byjest-environment-jsdom. This issue is fixed by re-exporting Nodeutil'sTextEncoderasglobal.TextEncoderinsetup-env.tsuuid. 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 ofuuid, but leaves all other resolutions the sameJ=SLAP-2123
TEST=auto
See that Jest tests pass.