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 Apollo Server Integration Testsuite #2

Closed
martinnabhan opened this issue Oct 19, 2022 · 2 comments · Fixed by #14
Closed

Add Apollo Server Integration Testsuite #2

martinnabhan opened this issue Oct 19, 2022 · 2 comments · Fixed by #14
Assignees

Comments

@martinnabhan
Copy link
Collaborator

martinnabhan commented Oct 19, 2022

https://github.com/apollographql/apollo-server/tree/main/packages/integration-testsuite

@martinnabhan martinnabhan self-assigned this Oct 21, 2022
@martinnabhan martinnabhan changed the title Add tests Add Apollo Server Integration Testsuite Oct 21, 2022
@martinnabhan
Copy link
Collaborator Author

Current progress:

Next.js unit testing is usually done by just rendering React components. API Routes are quite similar, usually you just test the logic in the handler. In this case however I want to make sure we actually unit test using Next.js, not just the React or logic handling parts, so we can be sure that error handling and server responses are correct.

Looking at Next.js they seem to do integration testing by running Next.js once in dev mode, and once by actually building the application and serving it: https://github.com/vercel/next.js/blob/canary/test/integration/404-page/test/index.test.js

This would work, however the Apollo Server Integration Testsuite has a wide array of tests, where both Apollo Server's config (defineIntegrationTestSuite's serverOptions parameter) and the Apollo Server integration's options (testOptions parameter) change depending on the test, which means we can't just build our Next.js app and run it, since then both Apollo Server and the integration's options will become static.

To counter this I'm trying out a method where for each test we save serverOptions and testOptions to a temporary file. We then load this temporary file in our Next.js handler during runtime, allowing us to dynamically change both Apollo Server's and the integration's options. This might be a bit slow but it should work. I'm however still seeing a lot of failing tests, so this will need some more work. I'll keep trying this week and we'll see how it goes!

Another issue I've encountered is that all the tests assume Apollo Server is accessible at /. Next.js only allows creating API routes with the /api/ URL prefix, which means in most cases Apollo Server will be accessible at /api/graphql. To counter this I've tried implementing a Next.js middleware which rewrites / to /api/graphql, which seems to be working. I might later send a pull request to apollo-server, allowing us to specify which url Apollo Server is accessible at.

@trevor-scheer
Copy link
Member

If you see good ways to improve the API for the testsuite, please don't hesitate to open a PR! For serverless-y integrations, we generally mock the incoming request so it calls your function/lambda the way it would be called. It's clunky for sure!

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 a pull request may close this issue.

2 participants