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

Run tests with React 19 RC.1 and adjust tests accordingly #12140

Merged
merged 60 commits into from
Dec 4, 2024

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Nov 18, 2024

If we are not in a render-streaming test

  • replace render to renderAsync for suspense tests
  • replace act with actAsync for suspense tests
  • adjust in counting tests for additional sibling prerendering in React 19 (these really should move over to committed-render streaming tests!)

If we are in a render-streaming test

  • various render calls now return promises -> add await
  • enforce calling disableActEnvironment on a per-test basis
  • remove act calls in these tests

Before we merge this, we should review testing-library/react-render-stream-testing-library#10 and release it as 2.0 (released as 2.0 alpha for now)


This currently builds on top of a PR in RRSTL and inlines actAsync, and renderAyncHook from testing-library/react-testing-library#1365 while providing a simple wrapper as renderAsync.

Please also review testing-library/react-render-stream-testing-library#10


I will still investigate using https://github.com/eps1lon/codemod-missing-await-act, but do so in a separate PR

@svc-apollo-docs
Copy link

svc-apollo-docs commented Nov 18, 2024

✅ Docs Preview Ready

No new or changed pages found.

Copy link

changeset-bot bot commented Nov 18, 2024

⚠️ No Changeset found

Latest commit: 1507630

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

pkg-pr-new bot commented Nov 18, 2024

npm i https://pkg.pr.new/@apollo/client@12140

commit: 1507630

Copy link
Contributor

github-actions bot commented Nov 18, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 39.33 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 48.01 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 45.59 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 34.4 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 32.29 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.26 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.24 KB (0%)
import { useQuery } from "dist/react/index.js" 5.21 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.3 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.69 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.77 KB (0%)
import { useMutation } from "dist/react/index.js" 3.62 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.84 KB (0%)
import { useSubscription } from "dist/react/index.js" 4.42 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 3.48 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.51 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.17 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5.01 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.66 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.09 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.73 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.41 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.35 KB (0%)
import { useFragment } from "dist/react/index.js" 2.28 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.23 KB (0%)

() =>
useQuery(query, {
onCompleted,
notifyOnNetworkStatusChange: true,
pollInterval: 110,
pollInterval: 200,
Copy link
Member Author

Choose a reason for hiding this comment

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

Interweaving things that are not part of the renderStream (expect(onCompleted).toHaveBeenCalledTimes(1)) with the timing of the renderStream can make up for a flaky test.
In the long run, this should probably be refactored and the call count should become part of the snapshot.
In the meantime, I'm raising the interval here to prevent this test from being flaky.

@phryneas phryneas requested a review from jerelmiller December 3, 2024 14:41
@phryneas phryneas changed the title bump react to 19 rc.1 Run tests with React 19 RC.1 and adjust tests accordingly Dec 3, 2024
@phryneas phryneas marked this pull request as ready for review December 3, 2024 14:41
@@ -85,7 +85,6 @@ const standardReact17Config = {
"^react-dom$": "react-dom-17",
"^react-dom/server$": "react-dom-17/server",
"^react-dom/test-utils$": "react-dom-17/test-utils",
"^@testing-library/react$": "@testing-library/react-12",
Copy link
Member

Choose a reason for hiding this comment

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

🎉

Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Thanks for updating all those!

src/testing/internal/scenarios/index.ts Outdated Show resolved Hide resolved
@@ -63,6 +63,13 @@ export function setupVariablesCase() {
return { mocks, query };
}

export function slowDownMocks<T extends MockedResponse<unknown>[]>(
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
export function slowDownMocks<T extends MockedResponse<unknown>[]>(
export function addDelayToMocks<T extends MockedResponse<unknown>[]>(

It took me a bit to realize what this helper did since "slow down" is not generally something you want in your tests if you can help it. Could you name this addDelayToMocks instead so that it makes it a bit more obvious its intent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call :)

src/testing/internal/rtl/actAsync.ts Outdated Show resolved Hide resolved
src/testing/internal/rtl/renderAsync.ts Outdated Show resolved Hide resolved
useTrackRenders,
} from "@testing-library/react-render-stream";

const IS_REACT_19 = React.version.startsWith("19");

afterEach(() => wait(10));
Copy link
Member

Choose a reason for hiding this comment

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

any chance you could add a comment here to explain why this is needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

That comment would be // ooops ^^ I think that's not necessary.

@github-actions github-actions bot added the auto-cleanup 🤖 label Dec 4, 2024
@phryneas phryneas merged commit a923b06 into main Dec 4, 2024
45 checks passed
@phryneas phryneas deleted the pr/react-19-rc.1 branch December 4, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants