Recommendations for writing integration tests for ...
# random
c
Recommendations for writing integration tests for Apollo Server? The docs https://www.apollographql.com/docs/apollo-server/testing/testing/ say Apollo Server has a built-in 
executeOperation
 method which feels more like unit testing to me, but maybe I'm wrong. Here's a post https://thenewstack.io/automatic-testing-for-graphql-apis/ about using Jest and supertest which is more like what I've done with REST APIs. Opinions or advice appreciated!
p
c
Thanks! Looks like an awesome tool for front-end development however even after reading this page https://mswjs.io/docs/getting-started/integrate/node I'm confused about how it would help me test a Node/Apollo Server GraphQL API that doesn't depend on any external resources.
p
Ah sorry, I thought you meant frontend
h
I ended up writing tests like here (https://github.com/dooboolab/hackatalk/tree/master/server/tests) last year. However, there might be a better approach today.
🙌 1
One day I'd like to try mocking Prisma (https://www.prisma.io/docs/guides/testing/unit-testing) which I've not succeeded lately.
c
I just figured out if you pass
mocks: true
to Apollo Server, it mocks your ENTIRE API automatically! You can also customize the data that gets provided.
🙌 1
h
@Chris Tsongas Do you have any content to share more about it? I would like try it out.
c
u
But if you mock your API it’s more for testing the front end because you aren’t actually testing your code, you are juste testing the graphql schema. I tried using executeOperation but you can’t pass headers so if you wanna test secured routes it won’t work. I really wanted it to work because you don’t have to start the server to call executeOperation. But it’s very very limited. Personally I use https://github.com/prisma-labs/graphql-request (Prisma yay), but you have to start you server to test it so you have to wait for server to be up when running the test command… Which is annoying…
🙌 1
c
Thanks, almost all of my routes are secured so that's super helpful. I need to write some code to make my server to connect to a test database when running tests....
u
I’ve been using docker compose to start an empty pg db, the server and then some tests. Only for test because I don’t like using docker for the dev environment 🙂