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

Adds MSW + testing utilities example #11763

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

alessbell
Copy link
Member

@alessbell alessbell commented Apr 5, 2024

Closes #11709. Configures initial integration tests with MSW.

Copy link

changeset-bot bot commented Apr 5, 2024

⚠️ No Changeset found

Latest commit: 9435317

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
Contributor

github-actions bot commented Apr 5, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 38.61 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 46.49 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 44.04 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 34.16 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 32.04 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.24 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.22 KB (0%)
import { useQuery } from "dist/react/index.js" 5.27 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.35 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.51 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.58 KB (0%)
import { useMutation } from "dist/react/index.js" 3.51 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.73 KB (0%)
import { useSubscription } from "dist/react/index.js" 3.19 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.38 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.44 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.11 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 4.92 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.58 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.03 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.69 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.32 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.26 KB (0%)
import { useFragment } from "dist/react/index.js" 2.29 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.24 KB (0%)

Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 9435317
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/661e95b479043500086aacc4
😎 Deploy Preview https://deploy-preview-11763--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.

@alessbell alessbell marked this pull request as ready for review April 10, 2024 13:23
"test": "jest"
},
"dependencies": {
"@apollo/client": "^3.10.0-rc.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Will wait to merge this until the next RC is published and I can update the version here along with the new fn names

@alessbell alessbell linked an issue Apr 10, 2024 that may be closed by this pull request
integration-tests/vite-jest-msw/playwright.config.ts Outdated Show resolved Hide resolved
Comment on lines +7 to +8
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
Copy link
Member

@phryneas phryneas Apr 11, 2024

Choose a reason for hiding this comment

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

Suggested change
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
"moduleResolution": "bundler",
"noEmit": true,
"allowSyntheticDefaultImports": true

Otherwise, running tsc might result in stray files.

Copy link
Member Author

@alessbell alessbell Apr 11, 2024

Choose a reason for hiding this comment

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

Should I update all the tsconfig.node.json in integration tests?

Edit: updated 2a69c5a

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like that caused tsc to error with Referenced project '/home/circleci/project/integration-tests/vite-jest-msw/tsconfig.node.json' may not disable emit.

"noFallthroughCasesInSwitch": true
},
"files": ["@types/graphql.d.ts"],
"include": ["src", "./tests/setupTests.js"],
Copy link
Member

Choose a reason for hiding this comment

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

Currently, no tsconfig seems to be including the tests folder, so everything in there will fall back to some kinda-random defaults. Is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Including tests there was causing some weird failure mode either in my editor or CI (but not both)... I forget what that was :/

Comment on lines +17 to +21
beforeEach(() => {
// since all our tests now use our "real" production Apollo Client instance,
// we need to reset the client cache before each test
return client.cache.reset();
});
Copy link
Member

Choose a reason for hiding this comment

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

I have to admit, I'm still not 100% sold on "having only one client".
I am 100% sold on "using the real client", but I wouldn't have only one of them.
(Sorry for bringing this up so late, but I'm only really realizing through reviewing these PRs, we mostly discussed other parts of the testing setup.)

My suggestion would be to establish a pattern of a makeClient() function (maybe also a makeClient({fetch?}) function?) so that every test could use a "real" production client, but no two tests use the same - even if you reset the cache here, the QueryManager is not reset - and it could still have pending queries, and those would be deduplicate into the next test.

For comparison, see https://redux.js.org/usage/writing-tests#setting-up-a-test-environment which suggests a setupStore function that automatically creates a new store in renderWithProviders.

Copy link
Member Author

@alessbell alessbell Apr 11, 2024

Choose a reason for hiding this comment

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

That's a great call out. I'll come back and make this change once the next RC is out since I'll have to update this PR then anyways, and will incorporate that guidance into the docs I'm writing 👍

Edit: I'll actually come back around to this in a separate PR

@alessbell alessbell requested a review from phryneas April 16, 2024 15:20
Base automatically changed from release-3.10 to main April 24, 2024 15:49
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.

[Testing utilities] Example with MSW
2 participants