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

49 lines
1,008 B
TypeScript
Raw Normal View History

2016-07-05 17:25:18 -07:00
import * as hapi from 'hapi';
import { graphqlHapi, graphiqlHapi } from './hapiApollo';
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 server = new hapi.Server({
host: 'localhost',
port: 8000,
2016-07-05 17:25:18 -07:00
});
await server.register({
plugin: graphqlHapi,
options: {
graphqlOptions: (options && options.graphqlOptions) || { schema: Schema },
path: '/graphql',
},
2016-07-05 17:25:18 -07:00
});
await server.register({
plugin: graphiqlHapi,
options: {
path: '/graphiql',
graphiqlOptions: (options && options.graphiqlOptions) || {
endpointURL: '/graphql',
},
},
2016-07-06 07:05:59 -07:00
});
await server.start();
2016-07-06 07:05:59 -07:00
return server.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);
});