When testing, it is useful to call graphQlServer.start({ port: 0 }) within the beforeAll / beforeEach sections of tests. It would be great to be able to stop the server in an afterAll / afterEach by calling graphQlServer.stop().
The function should kill any running process initiated by start().
In the meantime, is there any existing way to kill the server after calling start()?
This is specifically referring to integration testing. Happy to hear any other ideas on how to get integration testing up and running!
Can't believe this is not present. I also need to stop the server in integration tests.
It is possible to directly access the http server instance which is resolved in the promise returned by server.start like this:
const httpServer = await graphqlServer.start(({ port }) => console.log(`Server is running on http://localhost:${port}`));
// ... your code
httpServer.close();
Edit: This approach works for me w/ Jest and setting up the server in beforeAll and closing it in afterAll:
let server;
beforeAll(await () => server = await startGraphQLServer());
afterAll(() => server.close());
@phikes I thought the return type was void

EDIT:
@phikes thanks! but confirming that it was my fault. I abstracted it in my own class but forgot to return 馃ぃ
It might be that the API changed in the meantime, I don't currently use this anymore.
Most helpful comment
It is possible to directly access the http server instance which is resolved in the promise returned by
server.startlike this:Edit: This approach works for me w/ Jest and setting up the server in
beforeAlland closing it inafterAll: