forked from apollographql/apollo-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastifyApollo.test.ts
More file actions
57 lines (49 loc) · 1.46 KB
/
Copy pathfastifyApollo.test.ts
File metadata and controls
57 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import fastify from 'fastify';
import { FastifyInstance } from 'fastify';
import { ApolloServer } from '../ApolloServer';
import { graphqlFastify } from '../fastifyApollo';
import testSuite, {
schema as Schema,
CreateAppOptions,
} from 'apollo-server-integration-testsuite';
import { GraphQLOptions, Config } from 'apollo-server-core';
async function createApp(options: CreateAppOptions = {}) {
const app = fastify();
const server = new ApolloServer(
(options.graphqlOptions as Config) || { schema: Schema },
);
await server.applyMiddleware({ app });
try {
await app.listen(3007);
} catch (err) {
app.log.error('error in starting server', err);
process.exit(1);
}
return app.server;
}
async function destroyApp(app: any) {
if (!app || !app.close) {
return;
}
await new Promise(cb => app.close(cb));
}
describe('fastifyApollo', () => {
it('throws error if called without schema', function() {
expect(() =>
graphqlFastify(
{} as FastifyInstance,
undefined as GraphQLOptions,
undefined,
),
).toThrow('Apollo Server requires options.');
});
it('throws an error if called with argument not equal to 3', function() {
expect(() => (<any>graphqlFastify)({}, { graphqlOptions: {} })).toThrow(
'Apollo Server expects exactly 3 argument, got 2',
);
});
});
// Uncomment this to see the breaking tests
describe('integration:Fastify', () => {
testSuite(createApp, destroyApp);
});