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

Refactor remaining tests that instantiate QueryManager directly and remove mockQueryManager helper #12327

Merged
merged 97 commits into from
Jan 31, 2025

Conversation

jerelmiller
Copy link
Member

Refactors the remaining tests that instantiated a QueryManager instance directly to instantiate an ApolloClient instance instead. This makes our tests resemble more of the end-user experience. As a result, the mockQueryManager and mockWatchQuery helpers were removed as they are no longer used.

This PR also updates as many matchers as possible to use to*ApolloQueryResult to ensure results match the expected values. This revealed several issues with our existing values emitted from the core API that don't match our TypeScript types. This will be corrected in the v4 release.

Copy link

changeset-bot bot commented Jan 31, 2025

⚠️ No Changeset found

Latest commit: 7d8883d

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

@svc-apollo-docs
Copy link

svc-apollo-docs commented Jan 31, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 8c21210bcdb72a675c871898

Copy link
Member Author

Choose a reason for hiding this comment

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

These are no longer needed since the tests that compared against these snapshots now check against an ApolloError instance directly.

Copy link

pkg-pr-new bot commented Jan 31, 2025

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

commit: 7d8883d

Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 7d8883d
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/679c56007296b60008614090
😎 Deploy Preview https://deploy-preview-12327--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jan 31, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 40.67 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.08 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.19 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.18 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.58 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.29 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.7 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.78 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.74 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.36 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.31 KB (0%)

const { data, loading } = await stream.takeNext();
await expect(stream).toEmitApolloQueryResult({
// TODO: Ensure this value is undefined instead of an empty object
data: {},
Copy link
Member Author

Choose a reason for hiding this comment

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

Once these tests are pulled in the v4 branch, these should be fixed by the updated behavior of cache.diff.

const result = await stream.takeNext();
await expect(stream).toEmitApolloQueryResult({
// TODO: Fix this error
// @ts-expect-error `ApolloQueryResult` needs to be updated to allow for `undefined` and this value needs to emit undefined instead of empty object
Copy link
Member Author

Choose a reason for hiding this comment

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

This refactor exposed several issues with the values we emit at runtime vs the ApolloQueryResult type. This is something that will be addressed in v4.

@jerelmiller jerelmiller merged commit eeba2ef into main Jan 31, 2025
46 checks passed
@jerelmiller jerelmiller deleted the jerel/remove-mock-query-manager branch January 31, 2025 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants