-
Notifications
You must be signed in to change notification settings - Fork 352
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
React 18: Wrap non-RTL actions in act() #1401
Conversation
Size Change: 0 B Total Size: 948 kB ℹ️ View Unchanged
|
bab5608
to
7d5470b
Compare
## Summary: This PR is the part of a chain of PRs upgrading Perseus to React 18. 1. This PR --> #1400 2. #1401 3. #1402 4. #1403 I thought I had the React 18 (#1064) upgrade all ready (and it was even approved), but when I returned to that PR, I noticed linter and test failures. This lead me to discover that I need to upgrade testing-library. This then breaks a bunch of tests (which I'll fix in future PRs). Issue: LEMS-1802 ## Test plan: This PR will introduce many test failures. That's ok, they'll be fixed in follow-up PRs so that hopefully each step is relatively easy to review. Author: jeremywiebe Reviewers: jeresig, #perseus, jandrade, somewhatabstract Required Reviewers: Approved By: jeresig Checks: ⏭️ Upload Coverage, ✅ gerald, ⏭️ Publish npm snapshot, ❌ Jest Coverage (ubuntu-latest, 20.x), ❌ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ gerald, ⏭️ Upload Coverage, ⏭️ Publish npm snapshot, ❌ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ❌ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ⏭️ Upload Coverage, ⏭️ Publish npm snapshot, ❌ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ❌ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1400
487c943
to
5eae095
Compare
@@ -57,7 +57,7 @@ describe("<TabbarItem />", () => { | |||
onClick={() => {}} | |||
/>, | |||
); | |||
jest.runAllTimers(); | |||
act(() => jest.runOnlyPendingTimers()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React 18/RTL are much more sensitive to element updates. Most of the time when we call runOnlyPendingTimers()
in Perseus tests it's because we're waiting for scheduled async work to complete and then re-render (via setTimeout
, setState
, etc).
@@ -0,0 +1,2 @@ | |||
// eslint-disable-next-line import/no-unassigned-import | |||
import "jest-extended"; // we love the side effects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes a Typescript check issue where some of the Jest matchers we use (such as toBeTrue()
) were no longer recognized by Typescript.
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - thank you Jeremy!
## Summary: This PR is the part of a chain of PRs upgrading Perseus to React 18. 1. #1400 2. #1401 3. This PR --> #1402 4. #1403 This PR fixes a few instances where there exists an RTL API for tests instead of making direct DOM object calls. RTL recommends this approach and this fixes a few more tests. Issue: LEMS-1802 ## Test plan: `yarn test` more tests pass ### Before ```sh $ yarn test ... Test Suites: 4 failed, 1 skipped, 184 passed, 188 of 189 total Tests: 9 failed, 14 skipped, 2564 passed, 2587 total Snapshots: 4 failed, 1 file obsolete, 155 passed, 159 total Time: 24.056 s, estimated 25 s Ran all test suites. error Command failed with exit code 1. ``` ### After ```sh $ yarn test ... Test Suites: 3 failed, 1 skipped, 185 passed, 188 of 189 total Tests: 6 failed, 14 skipped, 2567 passed, 2587 total Snapshots: 4 failed, 1 file obsolete, 155 passed, 159 total Time: 20.517 s, estimated 24 s Ran all test suites. error Command failed with exit code 1. ``` Close! :) Author: jeremywiebe Reviewers: jeremywiebe, jeresig, #perseus, somewhatabstract Required Reviewers: Approved By: jeresig Checks: ⏭️ Upload Coverage, ✅ gerald, ⏭️ Publish npm snapshot, ❌ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ❌ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald, ⏭️ Upload Coverage, ⏭️ Publish npm snapshot, ❌ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ❌ Jest Coverage (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1402
## Summary: This PR is the part of a chain of PRs upgrading Perseus to React 18. 1. #1400 2. #1401 3. #1402 4. This PR --> #1403 A few tests needed larger changes than simply wrapping the actions in `act()` (see #1402). This PR covers the remaining tests that were failing for various reasons. In some cases the tests were largely re-written (sometimes for better test clarity while re-working them to pass). In the case of the Zoomable tests, we were waiting for the text to be updated in the element, but the styling changes had not yet settled as the updates caused multiple `setState()` calls to be made which all needed to be called and then resolved by a subsequent render (thus the new `waitForStyle()` helper). In the Graded Group test update, I'm not sure how it worked as written. In the test that was fixed, we were testing mobile and in that case the "Check" button reads "Try again" on the second and subsequent attempts. In the Group tests, I needed to wrap some actions in `act()` as usual, but I also took the opportunity to change the element finding logic away from the `getAll...()` functions to depend more on the aria labels. This makes these tests read more clearly (instead of accessing item at index `[0]` we get the textbox with the string `"value rounded to the nearest ten"`). Lastly, there was one outdated snapshot due to a test file being renamed. Issue: LEMS-1802 ## Test plan: `yarn test` all tests now pass! ### Before ```sh $ yarn test ... Test Suites: 3 failed, 1 skipped, 185 passed, 188 of 189 total Tests: 6 failed, 14 skipped, 2567 passed, 2587 total Snapshots: 4 failed, 1 file obsolete, 155 passed, 159 total Time: 22.175 s, estimated 27 s Ran all test suites. ``` ### After ```sh $ yarn test ... Test Suites: 1 skipped, 188 passed, 188 of 189 total Tests: 14 skipped, 2573 passed, 2587 total Snapshots: 159 passed, 159 total Time: 26.765 s Ran all test suites. ``` Author: jeremywiebe Reviewers: jeremywiebe, jeresig, #perseus, somewhatabstract Required Reviewers: Approved By: jeresig Checks: ✅ codecov/patch, ✅ codecov/project, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald, ✅ gerald, ✅ Upload Coverage (ubuntu-latest, 20.x), ⏭️ Publish npm snapshot, ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), 🚫 Upload Coverage, ✅ gerald, ⏭️ Publish npm snapshot, 🚫 Cypress (ubuntu-latest, 20.x), 🚫 Jest Coverage (ubuntu-latest, 20.x), 🚫 Check builds for changes in size (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1403
Summary:
This PR is the part of a chain of PRs upgrading Perseus to React 18.
It appears that React 18 and RTL are more sensitive to not having mutating calls wrapped in
act()
. The changes in this PR are all simple changes that wrap function calls that cause DOM changes inact()
calls. There are a few special cases that are failing yet, but this PR cleans up the straightforward ones.Issue: LEMS-1802
Test plan:
yarn test
should have many fewer test failures than PR #1400Upcoming PRs will address the remaining test failures.
Before
After