[No QA] Fix import of setUpTests from Reanimated#36526
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
setUpTests from Reanimated
|
I have read the CLA Document and I hereby sign the CLA |
3.7.0 isn't the current version in Also is there a GH associated with this change? |
|
Hi @amyevans. I was simply asked to help with bumping Reanimated by @BartoszGrajdek since it was a blocker for him. I believe this should be opened against main since it fixes the issue of misusing that import. However, after diving into what goes on in the CI and why Jest tests are breaking I see that the problem is a bit more complicated (and I don't understand what is exactly happening). I will move it back into a draft to try and figure it out. Also, what is GH? |
|
Okay all good, thanks for digging into it further. And sorry, GH = GitHub. Typically each PR opened against this repo has an associated GitHub issue with further context of the problem being fixed and assigned team members/reviewers. |
setUpTests from ReanimatedsetUpTests from Reanimated
amyevans
left a comment
There was a problem hiding this comment.
Thanks for adding the extra detail. LGTM, but I also wouldn't mind if @roryabraham put 👀 on this.
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
roryabraham
left a comment
There was a problem hiding this comment.
Tests are passing, so LGTM 👍
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 1.4.43-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.43-20 🚀
|
Details
What
Currently Expensify uses a legacy way of acquiring
setUpTests()for Jest from Reanimated which is no longer valid. Using it the old way causes type leakage from Reanimated to TypeScript in Expensify even thoughskipLibCheckis on and breaks type checking.Correct way of doing it is described in Reanimated docs.
Why
Keeping this import unchanged and upgrading Reanimated causes TypeScript typechecking to fail. It's due to a leakage of types from Reanimated via the import from
react-native-reanimated/src/reanimated2/jestUtils.ts, which obviously is a TypeScript source file. I'm not exactly sure how the leak happen there. The correct import should be justreact-native-reanimated. However, this change causes the Jest test suite to break.Jest
After a long struggle understanding what's happening and why, here's the summary of it:
The test suite is breaking because ESModule imports from
react-nativeare improperly resolved in Reanimated. The file that fails islib/module/createAnimatedComponent/createAnimatedComponent.tsx, as it's the entry point for animated components. All the ESModuleimportsfromreact-nativeturn out to beundefinedthere. However, commonJS imports viarequireyield correct results.To investigate further, I simplified the test to only render a single animated component and reduced
jest.config.jsto only invokesetUpTests. Issue persisted.Eventually I narrowed down the culprit of this behavior to your mocks, namely
__mocks__/react-native.js. After I removed the mock, ESModule imports were working properly once again.I dived into the
react-native.jsmock to understand what's causing the issue.I'm not a Jest expert, but Jest documentation suggests to use
jest.requireActual- you useObject.setPrototypeOfwith an ES imported module instead. However, it didn't seem to cause any trouble. Also I'm not sure why there's nomodule.exportsin that file.For comparison, I created a bare React Native App, where I:
setUpTests()there fromreact-native-reanimated.react-nativeinside the test file, the way it's done in Jest documentation. Test passed.react-nativeinside the test file as in your repo. Test passed.react-nativeinside__mocks__. Test passed.Then in Expensify I:
jest.config.js.package.json, removed.lockfile andnode_modules, then reinstalled dependencies via npm.It seems that something is wrong with how/when the mocks are loaded, but I couldn't find the culprit of that and decided not to investigate further.
I came up with two solutions to this problem:
requirevia patch-package in troublesome places.setUpTests(it loads new matchers to check styles of animated components), you can just drop it.The latter here seems obviously superior to me - the patch for now would be just a few line in a single file, but it's definitely not a scalable solution and requires maintenance, had something changed in Reanimated repo. Therefore removing that function call sounds like a smart move.
I'd suggest investigating what's wrong with the mocks evaluation, had you wanted to extend your Jest tests significantly.
Results
npm run typecheckcommand will work properly now, it fails on CI (and locally) in #36404.npm run testpasses on Reanimated 3.6.1 (current) and on 3.7.0.Side note
I'm not sure that
tsconfig.jsonis flawless. When I was debugging this problem I was fiddling with theincludeandexcludesection there, and even though I'd put for e.g.srcfromincludetoexcludeit was still type checked (and with errors). However, I don't know the structure of your repo that well, so I might be mistaken. On the other hand, I know thattsconfig.jsonis a pain to set-up correctly and that probably nobody in the world can do it 100% right, so I'm not judging.Fixed Issues
$ #36187
Tests
npm run test- pass.npm run typecheck- pass.npm install react-native-reanimated@3.7.0npm run test- pass.npm run typecheck- pass.🥳
Offline tests
Same as tests.
QA Steps
Irrelevant AFAIK.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel so the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Irrelevant.