2018-06-11 14:25:59 +02:00
|
|
|
import hapi from 'hapi';
|
2018-06-14 01:36:09 -07:00
|
|
|
import { ApolloServer } from './ApolloServer';
|
2018-06-13 15:19:08 -07:00
|
|
|
import { Config } from 'apollo-server-core';
|
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
|
|
|
|
2018-06-13 15:19:08 -07:00
|
|
|
async function createApp(options: CreateAppOptions = {}) {
|
|
|
|
const app = new hapi.Server({
|
2018-01-09 00:08:01 +01:00
|
|
|
host: 'localhost',
|
|
|
|
port: 8000,
|
2016-07-05 17:25:18 -07:00
|
|
|
});
|
|
|
|
|
2018-06-13 15:19:08 -07:00
|
|
|
const server = new ApolloServer(
|
|
|
|
(options.graphqlOptions as Config) || { schema: Schema },
|
|
|
|
);
|
2018-06-14 01:36:09 -07:00
|
|
|
await server.applyMiddleware({
|
2018-06-13 15:19:08 -07:00
|
|
|
app,
|
2016-07-05 17:25:18 -07:00
|
|
|
});
|
|
|
|
|
2018-06-13 15:19:08 -07:00
|
|
|
await app.start();
|
2017-12-08 00:04:12 -08:00
|
|
|
|
2018-06-13 15:19:08 -07:00
|
|
|
return app.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
|
|
|
});
|