apollo-server/packages/apollo-server-hapi/src/hapiApollo.test.ts

39 lines
791 B
TypeScript
Raw Normal View History

import * as hapi from 'hapi';
import { ApolloServer } from './ApolloServer';
import { Config } from 'apollo-server-core';
import 'mocha';
2016-07-05 17:25:18 -07:00
import testSuite, {
schema as Schema,
CreateAppOptions,
} from 'apollo-server-integration-testsuite';
2016-07-05 17:25:18 -07:00
async function createApp(options: CreateAppOptions = {}) {
const app = new hapi.Server({
host: 'localhost',
port: 8000,
2016-07-05 17:25:18 -07:00
});
const server = new ApolloServer(
(options.graphqlOptions as Config) || { schema: Schema },
);
await server.applyMiddleware({
app,
2016-07-05 17:25:18 -07:00
});
await app.start();
return app.listener;
2016-07-05 17:25:18 -07:00
}
async function destroyApp(app) {
if (!app || !app.close) {
return;
}
await new Promise(resolve => app.close(resolve));
}
describe('integration:Hapi', () => {
testSuite(createApp, destroyApp);
});