forked from apollographql/apollo-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke-test.cjs
90 lines (79 loc) · 2.44 KB
/
smoke-test.cjs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { ApolloServer } = require('@apollo/server');
const { startStandaloneServer } = require('@apollo/server/standalone');
const fetch = require('make-fetch-happen');
const assert = require('assert');
async function validateAllImports() {
require('@apollo/server');
require('@apollo/server/plugin/cacheControl');
require('@apollo/server/plugin/disabled');
require('@apollo/server/plugin/drainHttpServer');
require('@apollo/server/plugin/inlineTrace');
require('@apollo/server/plugin/landingPage/default');
require('@apollo/server/plugin/schemaReporting');
require('@apollo/server/plugin/usageReporting');
require('@apollo/server/standalone');
}
async function smokeTest() {
await validateAllImports();
const s = new ApolloServer({
typeDefs: `
directive @defer(if: Boolean! = true, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT
type Query {hello:String}
`,
resolvers: {
Query: {
hello() {
return 'world';
},
},
},
});
const { url } = await startStandaloneServer(s, { listen: { port: 0 } });
{
const response = await fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query: '{hello}' }),
});
const body = await response.json();
assert.strictEqual(body.data.hello, 'world');
}
if (process.env.INCREMENTAL_DELIVERY_TESTS_ENABLED) {
const response = await fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
accept: 'multipart/mixed; deferSpec=20220824, application/json',
},
body: JSON.stringify({ query: '{h1: hello ...@defer{ h2: hello }}' }),
});
assert.strictEqual(
response.headers.get('content-type'),
'multipart/mixed; boundary="-"; deferSpec=20220824',
);
const body = await response.text();
assert.strictEqual(
body,
'\r\n' +
'---\r\n' +
'content-type: application/json; charset=utf-8\r\n' +
'\r\n' +
'{"hasNext":true,"data":{"h1":"world"}}\r\n' +
'---\r\n' +
'content-type: application/json; charset=utf-8\r\n' +
'\r\n' +
'{"hasNext":false,"incremental":[{"path":[],"data":{"h2":"world"}}]}\r\n' +
'-----\r\n',
);
}
await s.stop();
}
smokeTest()
.then(() => {
console.log('CJS smoke test passed!');
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});