Skip to content

Instantly share code, notes, and snippets.

@seandearnaley
Last active February 1, 2020 22:57
Show Gist options
  • Save seandearnaley/92bed116302c90b5ad21879e69fe8e88 to your computer and use it in GitHub Desktop.
Save seandearnaley/92bed116302c90b5ad21879e69fe8e88 to your computer and use it in GitHub Desktop.
BrainStrike Server End-2-End Test
import {
GraphQLRequest,
Observable,
FetchResult,
toPromise
} from "apollo-link";
import {
startTestServer,
constructTestServer,
createTestingConnection,
Connection
} from "./__utils";
import gql from "graphql-tag";
const GET_CARDS = gql`
query getCards {
cards {
id
number
label
description
}
}
`;
describe("Server - e2e", () => {
let connection: Connection;
let stop: () => void,
graphql: ({}: GraphQLRequest) => Observable<FetchResult>;
beforeAll(async () => {
connection = await createTestingConnection();
});
beforeEach(async () => {
const { apolloServer } = await constructTestServer(connection);
const testServer = await startTestServer(apolloServer);
stop = testServer.stop;
graphql = testServer.graphql;
});
afterEach(async () => {
stop();
});
afterAll(async () => {
await connection.close();
});
it("gets list of cards", async () => {
const res = await toPromise(
graphql({
query: GET_CARDS
})
);
expect(res).toMatchSnapshot();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment