apollo-server-testslisted
Install: claude install-skill testland/qa-skills
# apollo-server-tests
## Overview
`executeOperation` initializes automatically - no startup needed for
unit-style tests against the schema in-process. For HTTP-layer tests
(CORS, middleware, response headers), use `supertest` against an
ephemeral-port server.
## When to use
- Unit tests for resolvers using `executeOperation`.
- Integration tests for HTTP-layer behaviour using `supertest`.
- Production-config gates: assert introspection / APQ /
hideSchemaDetails settings match your production config.
## Authoring
### Install
```bash
npm install --save-dev @apollo/server supertest @types/supertest
```
### In-process tests with `executeOperation`
```typescript
import { ApolloServer } from '@apollo/server';
import { typeDefs, resolvers } from './schema';
const testServer = new ApolloServer({ typeDefs, resolvers });
test('returns greeting', async () => {
const response = await testServer.executeOperation({
query: 'query SayHelloWorld($name: String) { hello(name: $name) }',
variables: { name: 'world' },
});
// Parse/validation/execution errors surface in `errors`, not thrown
if (response.body.kind !== 'single') throw new Error('expected single');
expect(response.body.singleResult.errors).toBeUndefined();
expect(response.body.singleResult.data?.hello).toBe('Hello world!');
});
```
### Context injection (auth, datasources)
```typescript
const res = await testServer.executeOperation(
{ query: GET_LAUNCH, variables: { id: 1 } },
{
contextValu