2016-07-05 17:25:18 -07:00
|
|
|
import * as hapi from 'hapi';
|
2017-01-13 13:49:25 +02:00
|
|
|
import { graphqlHapi, graphiqlHapi } from './hapiApollo';
|
2016-10-03 23:13:08 +03:00
|
|
|
import 'mocha';
|
2016-07-05 17:25:18 -07:00
|
|
|
|
2018-01-09 00:08:01 +01:00
|
|
|
import testSuite, {
|
|
|
|
schema as Schema,
|
|
|
|
CreateAppOptions,
|
|
|
|
} from 'apollo-server-integration-testsuite';
|
2016-07-05 17:25:18 -07:00
|
|
|
|
2017-12-08 00:04:12 -08:00
|
|
|
async function createApp(options: CreateAppOptions) {
|
|
|
|
const server = new hapi.Server({
|
2018-01-09 00:08:01 +01:00
|
|
|
host: 'localhost',
|
|
|
|
port: 8000,
|
2016-07-05 17:25:18 -07:00
|
|
|
});
|
|
|
|
|
2017-12-08 00:04:12 -08:00
|
|
|
await server.register({
|
2018-01-09 00:08:01 +01:00
|
|
|
plugin: graphqlHapi,
|
|
|
|
options: {
|
|
|
|
graphqlOptions: (options && options.graphqlOptions) || { schema: Schema },
|
|
|
|
path: '/graphql',
|
|
|
|
},
|
2016-07-05 17:25:18 -07:00
|
|
|
});
|
|
|
|
|
2017-12-08 00:04:12 -08:00
|
|
|
await server.register({
|
2018-01-09 00:08:01 +01:00
|
|
|
plugin: graphiqlHapi,
|
|
|
|
options: {
|
|
|
|
path: '/graphiql',
|
|
|
|
graphiqlOptions: (options && options.graphiqlOptions) || {
|
|
|
|
endpointURL: '/graphql',
|
2016-09-09 07:49:23 -05:00
|
|
|
},
|
2018-01-09 00:08:01 +01:00
|
|
|
},
|
2016-07-06 07:05:59 -07:00
|
|
|
});
|
|
|
|
|
2017-12-08 00:04:12 -08:00
|
|
|
await server.start();
|
|
|
|
|
2016-07-06 07:05:59 -07:00
|
|
|
return server.listener;
|
2016-07-05 17:25:18 -07:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:04:12 -08:00
|
|
|
async function destroyApp(app) {
|
|
|
|
if (!app || !app.close) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-09 00:08:01 +01:00
|
|
|
await new Promise(resolve => app.close(resolve));
|
2017-12-08 00:04:12 -08:00
|
|
|
}
|
|
|
|
|
2016-09-09 20:22:13 -05:00
|
|
|
describe('integration:Hapi', () => {
|
2017-12-08 00:04:12 -08:00
|
|
|
testSuite(createApp, destroyApp);
|
2016-07-07 08:46:10 -07:00
|
|
|
});
|