-
Notifications
You must be signed in to change notification settings - Fork 817
Expand file tree
/
Copy path__utils.js
More file actions
63 lines (50 loc) · 1.34 KB
/
__utils.js
File metadata and controls
63 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { HttpLink } = require("apollo-link-http");
const fetch = require("node-fetch");
const { execute, toPromise } = require("apollo-link");
module.exports.toPromise = toPromise;
const {
dataSources,
context: defaultContext,
typeDefs,
resolvers,
ApolloServer,
LaunchAPI,
UserAPI,
store
} = require("../");
/**
* Integration testing utils
*/
const constructTestServer = ({ context = defaultContext } = {}) => {
const userAPI = new UserAPI({ store });
const launchAPI = new LaunchAPI();
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({ userAPI, launchAPI }),
context
});
return { server, userAPI, launchAPI };
};
module.exports.constructTestServer = constructTestServer;
/**
* e2e Testing Utils
*/
const startTestServer = async server => {
// if using apollo-server-express...
// const app = express();
// server.applyMiddleware({ app });
// const httpServer = await app.listen(0);
const httpServer = await server.listen({ port: 0 });
const link = new HttpLink({
uri: `http://localhost:${httpServer.port}`,
fetch
});
const executeOperation = ({ query, variables = {} }) => execute(link, { query, variables });
return {
link,
stop: () => httpServer.server.close(),
graphql: executeOperation
};
};
module.exports.startTestServer = startTestServer;