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

Add support for testing with react@17 #1115

Merged
merged 5 commits into from
Sep 16, 2022

Conversation

AugustinLF
Copy link
Collaborator

Summary

Follow-up on the discussion that happened in #1093 (comment). If we want to change the way we work with act and be more aligned with RTL, we either need to drop support to react@17 (which I'd like to avoid doing), or we need to increase our confidence that we're not breaking older versions.

I don't think we really need to cover for react@<=16 because tests mostly behave the same way, but when trying to work on bumping react in the codebase I work on, a lot of tests break for subtle reasons.

Approach

I went with a fairly simple approach where I copy the whole test/code base to be able to run any PR changes on both platforms (which prevents us from using the examples/ approach that reaches to a published version of RNTL).

Since different versions of react also implies different versions of react-native, we have a problem where some tests can't work in both cases. Currently the issue seems to be only with snapshots. I don't have any brilliant idea, a solution would be to do runtime check for React.version and have a snapshot by version. We could replace those specific snapshots with something that works in both versions, but I think we'll run in this problem regardless.

yarn.lock Outdated
version "9.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-9.0.0.tgz#c21b26f456c568687c0e58a6e42ba8b11b607b8a"
integrity sha512-4Rp5OUZW/7Qc9hyCd+ZEikuu2k9dW3ssu6KzWygbVc9wY80i4GQmvjfsiUi21o3uPDvL4KUMANmnQqoTOIcVMA==
"@react-native-community/cli-platform-android@^9.0.0", "@react-native-community/cli-platform-android@^9.1.0":
Copy link
Member

Choose a reason for hiding this comment

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

Are these upgrades related to the PR, if no, them let's exclude them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(left overs from initial debugging, will remove)

@mdjastrzebski
Copy link
Member

@AugustinLF I like the idea of this PR, so that we are able to test our compatibility with React 17/older React Native.

I wonder however if copying files is the right approach, maybe we could have a (shell/sed/etc) script that would update react + rest-test-renderder + react-native to specified version in place, then run yarn install & yarn test. Not sure how feasible is that but if so, we could even have a list of of supported R/RTR/RN versions.

Also can we use the latest Jest with older versions of R/RN? I think yes, but we'll need to check that.

@AugustinLF AugustinLF marked this pull request as ready for review September 14, 2022 13:56
@AugustinLF
Copy link
Collaborator Author

@mdjastrzebski went with your suggestion, let me know how you feel about this solution :)

cp yarn.lock tmp.yarn.lock
cp package.json tmp.package.json

yarn add react@17.0.2 react-test-renderer@17.0.2 react-native@0.68.1 --ignore-scripts
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I hardcoded dependencies, but I assume we should be able to test other combination if we want, like different jest versions

Copy link
Member

Choose a reason for hiding this comment

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

Will this overwrite existing versions of react?

BTW these should be devDeps as currently we put them as such

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will this overwrite existing versions of react?

Yes.

BTW these should be devDeps as currently we put them as such

Will fix that

@@ -49,6 +49,13 @@ jobs:
at: ~/react-native-testing-library
- run: |
yarn flow
test:react:17:
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest running this after the normal tests

Comment on lines 3 to 4
cp yarn.lock tmp.yarn.lock
cp package.json tmp.package.json
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cp yarn.lock tmp.yarn.lock
cp package.json tmp.package.json
cp yarn.lock yarn.lock.backup
cp package.json package.json.backup

@@ -0,0 +1,10 @@
#!/bin/sh -e
Copy link
Member

Choose a reason for hiding this comment

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

env seems to be recommended approach

Suggested change
#!/bin/sh -e
#!/usr/bin/env bash

package.json Outdated
@@ -82,7 +82,8 @@
"build:ts": "tsc --build tsconfig.release.json",
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
"prepare": "yarn build"
"prepare": "yarn build",
"test:react:17": "scripts/test_react_17"
Copy link
Member

Choose a reason for hiding this comment

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

Since we are RN TL maybe we should rather name our test script with React Native version, e.g. test-react-native-0.68.3, @AugustinLF wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

BTW since we're invoking test:ci underneath, so maybe test:ci:react-native-0.68.3? Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are RN TL, but I would argue that here we are actually testing the react differences, not as much the react-native ones (and we're still using react, I'd argue the problem is that @testing-library/react should be renamed @testing-library/react-dom^^')

cp yarn.lock tmp.yarn.lock
cp package.json tmp.package.json

yarn add react@17.0.2 react-test-renderer@17.0.2 react-native@0.68.1 --ignore-scripts
Copy link
Member

Choose a reason for hiding this comment

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

lets use the latest patch release from 0.68.x

Suggested change
yarn add react@17.0.2 react-test-renderer@17.0.2 react-native@0.68.1 --ignore-scripts
yarn add react@17.0.2 react-test-renderer@17.0.2 react-native@0.68.3 --ignore-scripts

Copy link
Member

@mdjastrzebski mdjastrzebski left a comment

Choose a reason for hiding this comment

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

I like the current approach with modifying package.json and restoring changes afterwards. The current solution looks pretty solid. I've added some suggestions for improvint the reliability

package.json Outdated
@@ -82,7 +82,8 @@
"build:ts": "tsc --build tsconfig.release.json",
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
"prepare": "yarn build"
"prepare": "yarn build",
"test:react:17": "scripts/test_react_17"
Copy link
Member

Choose a reason for hiding this comment

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

Let's put this test:xx next to other test:xx scripts

yarn test:ci

mv tmp.package.json package.json
mv tmp.yarn.lock yarn.lock
Copy link
Member

Choose a reason for hiding this comment

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

BTW shouldn't we call yarn install again to restore node modules to match yarn.lock?

@AugustinLF
Copy link
Collaborator Author

@mdjastrzebski I implemented all your suggestions (or answered in the comments), let me know if you need anything else. If not I think we can merge this so I can start working on the act related changes for react@18 :)

@mdjastrzebski mdjastrzebski merged commit 10e69c5 into callstack:main Sep 16, 2022
@AugustinLF AugustinLF deleted the execute-tests-on-react-17 branch September 18, 2022 14:18
@mdjastrzebski
Copy link
Member

🎉 This PR is included in version 11.2.0 🎉

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

2 participants