@platformatic/service 0.21.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fixtures/hello/warn-log.service.json +19 -0
- package/fixtures/hello-client/platformatic.service.json +1 -1
- package/fixtures/hello-client-ts/platformatic.service.json +3 -2
- package/index.js +139 -229
- package/lib/compile.js +9 -5
- package/lib/load-config.js +13 -15
- package/lib/plugins/clients.js +12 -0
- package/lib/plugins/cors.js +29 -0
- package/lib/plugins/file-watcher.js +44 -0
- package/lib/plugins/health-check.js +17 -0
- package/lib/plugins/plugins.js +56 -0
- package/lib/plugins/typescript.js +46 -0
- package/lib/root-endpoint/index.js +1 -0
- package/lib/schema.js +8 -1
- package/lib/start.mjs +27 -135
- package/lib/utils.js +2 -11
- package/package.json +24 -23
- package/test/autoload.test.js +77 -59
- package/test/cli/compile.test.mjs +45 -36
- package/test/cli/start.test.mjs +13 -1
- package/test/cli/watch.test.mjs +40 -2
- package/test/clients.test.js +25 -18
- package/test/config.test.js +67 -27
- package/test/cors.test.js +48 -30
- package/test/fixtures/bad-typescript-plugin/platformatic.service.json +3 -1
- package/test/fixtures/custom-port-placeholder.json +10 -0
- package/test/fixtures/typescript-autoload/platformatic.service.json +3 -1
- package/test/fixtures/typescript-plugin/platformatic.service.json +3 -1
- package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +2 -1
- package/test/graphql.test.js +18 -14
- package/test/healthcheck.test.js +22 -13
- package/test/https.test.js +13 -11
- package/test/lambda.test.js +103 -0
- package/test/load-and-reload-files.test.js +98 -109
- package/test/load-plugin.test.js +8 -4
- package/test/metrics.test.js +59 -39
- package/test/routes.test.js +43 -25
- package/test/utils.test.js +6 -15
- package/test/watch.test.js +182 -0
- /package/lib/{graphql.js → plugins/graphql.js} +0 -0
- /package/lib/{metrics-plugin.js → plugins/metrics.js} +0 -0
- /package/lib/{openapi.js → plugins/openapi.js} +0 -0
- /package/lib/{sandbox-wrapper.js → plugins/sandbox-wrapper.js} +0 -0
package/test/config.test.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require('./helper')
|
|
4
4
|
const { test } = require('tap')
|
|
5
5
|
const { buildServer } = require('..')
|
|
6
|
+
const { loadConfig } = require('../lib/load-config')
|
|
6
7
|
const { request } = require('undici')
|
|
7
8
|
const { join } = require('path')
|
|
8
9
|
const os = require('os')
|
|
@@ -16,7 +17,7 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
|
|
|
16
17
|
app.get('/', () => options.message)
|
|
17
18
|
}`)
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
+
const app = await buildServer({
|
|
20
21
|
server: {
|
|
21
22
|
hostname: '127.0.0.1',
|
|
22
23
|
port: 0
|
|
@@ -31,16 +32,19 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
|
|
|
31
32
|
},
|
|
32
33
|
metrics: false
|
|
33
34
|
})
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
teardown(async () => {
|
|
37
|
+
await app.close()
|
|
38
|
+
})
|
|
39
|
+
await app.start()
|
|
36
40
|
|
|
37
41
|
{
|
|
38
|
-
const res = await request(`${
|
|
42
|
+
const res = await request(`${app.url}/`)
|
|
39
43
|
equal(res.statusCode, 200, 'add status code')
|
|
40
44
|
same(await res.body.text(), 'hello', 'response')
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
await
|
|
47
|
+
await app.platformatic.configManager.update({
|
|
44
48
|
server: {
|
|
45
49
|
hostname: '127.0.0.1',
|
|
46
50
|
port: 0
|
|
@@ -56,10 +60,10 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
|
|
|
56
60
|
metrics: false
|
|
57
61
|
})
|
|
58
62
|
|
|
59
|
-
await
|
|
63
|
+
await app.restart()
|
|
60
64
|
|
|
61
65
|
{
|
|
62
|
-
const res = await request(`${
|
|
66
|
+
const res = await request(`${app.url}/`)
|
|
63
67
|
equal(res.statusCode, 200, 'add status code')
|
|
64
68
|
same(await res.body.text(), 'ciao mondo', 'response')
|
|
65
69
|
}
|
|
@@ -90,17 +94,20 @@ test('config reloads from a written file', async ({ teardown, equal, pass, same
|
|
|
90
94
|
app.get('/', () => options.message)
|
|
91
95
|
}`)
|
|
92
96
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const app = await buildServer(config)
|
|
98
|
+
|
|
99
|
+
teardown(async () => {
|
|
100
|
+
await app.close()
|
|
101
|
+
})
|
|
102
|
+
await app.start()
|
|
96
103
|
|
|
97
104
|
{
|
|
98
|
-
const res = await request(`${
|
|
105
|
+
const res = await request(`${app.url}/`)
|
|
99
106
|
equal(res.statusCode, 200, 'add status code')
|
|
100
107
|
same(await res.body.text(), 'hello', 'response')
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
await
|
|
110
|
+
await app.platformatic.configManager.update({
|
|
104
111
|
server: {
|
|
105
112
|
hostname: '127.0.0.1',
|
|
106
113
|
port: 0
|
|
@@ -116,10 +123,10 @@ test('config reloads from a written file', async ({ teardown, equal, pass, same
|
|
|
116
123
|
metrics: false
|
|
117
124
|
})
|
|
118
125
|
|
|
119
|
-
await
|
|
126
|
+
await app.restart()
|
|
120
127
|
|
|
121
128
|
{
|
|
122
|
-
const res = await request(`${
|
|
129
|
+
const res = await request(`${app.url}/`)
|
|
123
130
|
equal(res.statusCode, 200, 'add status code')
|
|
124
131
|
same(await res.body.text(), 'ciao mondo', 'response')
|
|
125
132
|
}
|
|
@@ -173,25 +180,28 @@ test('config reloads from a written file from a route', async ({ teardown, equal
|
|
|
173
180
|
})
|
|
174
181
|
}`)
|
|
175
182
|
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
const app = await buildServer(config)
|
|
184
|
+
|
|
185
|
+
teardown(async () => {
|
|
186
|
+
await app.close()
|
|
187
|
+
})
|
|
188
|
+
await app.start()
|
|
179
189
|
|
|
180
190
|
{
|
|
181
|
-
const res = await request(`${
|
|
191
|
+
const res = await request(`${app.url}/`)
|
|
182
192
|
equal(res.statusCode, 200, 'add status code')
|
|
183
193
|
same(await res.body.text(), 'hello', 'response')
|
|
184
194
|
}
|
|
185
195
|
|
|
186
196
|
{
|
|
187
|
-
const res = await request(`${
|
|
197
|
+
const res = await request(`${app.url}/restart`, {
|
|
188
198
|
method: 'POST'
|
|
189
199
|
})
|
|
190
200
|
equal(res.statusCode, 200, 'add status code')
|
|
191
201
|
}
|
|
192
202
|
|
|
193
203
|
{
|
|
194
|
-
const res = await request(`${
|
|
204
|
+
const res = await request(`${app.url}/`)
|
|
195
205
|
equal(res.statusCode, 200, 'add status code')
|
|
196
206
|
same(await res.body.text(), 'ciao mondo', 'response')
|
|
197
207
|
}
|
|
@@ -234,7 +244,7 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
|
|
|
234
244
|
app.get('/', () => options.message)
|
|
235
245
|
}`)
|
|
236
246
|
|
|
237
|
-
const
|
|
247
|
+
const app = await buildServer({
|
|
238
248
|
server: {
|
|
239
249
|
hostname: '127.0.0.1',
|
|
240
250
|
port: 0
|
|
@@ -249,16 +259,19 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
|
|
|
249
259
|
},
|
|
250
260
|
metrics: false
|
|
251
261
|
})
|
|
252
|
-
|
|
253
|
-
|
|
262
|
+
|
|
263
|
+
teardown(async () => {
|
|
264
|
+
await app.close()
|
|
265
|
+
})
|
|
266
|
+
await app.start()
|
|
254
267
|
|
|
255
268
|
{
|
|
256
|
-
const res = await request(`${
|
|
269
|
+
const res = await request(`${app.url}/`)
|
|
257
270
|
equal(res.statusCode, 200, 'add status code')
|
|
258
271
|
same(await res.body.text(), 'hello', 'response')
|
|
259
272
|
}
|
|
260
273
|
|
|
261
|
-
await
|
|
274
|
+
await app.platformatic.configManager.update({
|
|
262
275
|
server: {
|
|
263
276
|
hostname: '127.0.0.1',
|
|
264
277
|
port: 0
|
|
@@ -274,11 +287,38 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
|
|
|
274
287
|
metrics: false
|
|
275
288
|
})
|
|
276
289
|
|
|
277
|
-
await
|
|
290
|
+
await app.restart()
|
|
278
291
|
|
|
279
292
|
{
|
|
280
|
-
const res = await request(`${
|
|
293
|
+
const res = await request(`${app.url}/`)
|
|
281
294
|
equal(res.statusCode, 200, 'add status code')
|
|
282
295
|
same(await res.body.text(), 'ciao mondo', 'response')
|
|
283
296
|
}
|
|
284
297
|
})
|
|
298
|
+
|
|
299
|
+
test('can merge provided config with default config', async ({ plan, same }) => {
|
|
300
|
+
plan(6)
|
|
301
|
+
const configFile = join(__dirname, 'fixtures', 'custom-port-placeholder.json')
|
|
302
|
+
const defaultConfig = {
|
|
303
|
+
mergeDefaults: true,
|
|
304
|
+
onMissingEnv (key) {
|
|
305
|
+
same(key, 'A_CUSTOM_PORT')
|
|
306
|
+
return '42'
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
{
|
|
311
|
+
const config = await loadConfig({}, ['-c', configFile], defaultConfig)
|
|
312
|
+
same(config.configManager.current.server.port, 42)
|
|
313
|
+
// This comes from the default config.
|
|
314
|
+
same(config.configManager.schemaOptions.useDefaults, true)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
{
|
|
318
|
+
defaultConfig.mergeDefaults = false
|
|
319
|
+
const config = await loadConfig({}, ['-c', configFile], defaultConfig)
|
|
320
|
+
same(config.configManager.current.server.port, 42)
|
|
321
|
+
// This comes from the default config.
|
|
322
|
+
same(config.configManager.schemaOptions.useDefaults, undefined)
|
|
323
|
+
}
|
|
324
|
+
})
|
package/test/cors.test.js
CHANGED
|
@@ -6,7 +6,7 @@ const { buildServer, platformaticService } = require('..')
|
|
|
6
6
|
const { request } = require('undici')
|
|
7
7
|
|
|
8
8
|
test('CORS is disabled by default', async ({ teardown, equal, pass, same }) => {
|
|
9
|
-
const
|
|
9
|
+
const app = await buildServer({
|
|
10
10
|
server: {
|
|
11
11
|
hostname: '127.0.0.1',
|
|
12
12
|
port: 0
|
|
@@ -18,9 +18,12 @@ test('CORS is disabled by default', async ({ teardown, equal, pass, same }) => {
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
// handles login
|
|
21
|
-
teardown(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
teardown(async () => {
|
|
22
|
+
await app.close()
|
|
23
|
+
})
|
|
24
|
+
await app.start()
|
|
25
|
+
|
|
26
|
+
const res = await (request(`${app.url}/login`, {
|
|
24
27
|
method: 'OPTIONS',
|
|
25
28
|
headers: {
|
|
26
29
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -31,7 +34,7 @@ test('CORS is disabled by default', async ({ teardown, equal, pass, same }) => {
|
|
|
31
34
|
})
|
|
32
35
|
|
|
33
36
|
test('CORS can be enabled', async ({ teardown, equal, pass, same }) => {
|
|
34
|
-
const
|
|
37
|
+
const app = await buildServer({
|
|
35
38
|
server: {
|
|
36
39
|
hostname: '127.0.0.1',
|
|
37
40
|
port: 0,
|
|
@@ -45,11 +48,14 @@ test('CORS can be enabled', async ({ teardown, equal, pass, same }) => {
|
|
|
45
48
|
app.register(platformaticService, opts)
|
|
46
49
|
app.post('/login', (req, reply) => {})
|
|
47
50
|
})
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
|
|
52
|
+
teardown(async () => {
|
|
53
|
+
await app.close()
|
|
54
|
+
})
|
|
55
|
+
await app.start()
|
|
50
56
|
|
|
51
57
|
{
|
|
52
|
-
const res = await (request(`${
|
|
58
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
53
59
|
method: 'OPTIONS',
|
|
54
60
|
headers: {
|
|
55
61
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -63,7 +69,7 @@ test('CORS can be enabled', async ({ teardown, equal, pass, same }) => {
|
|
|
63
69
|
})
|
|
64
70
|
|
|
65
71
|
test('CORS with a regexp', async ({ teardown, equal, pass, same }) => {
|
|
66
|
-
const
|
|
72
|
+
const app = await buildServer({
|
|
67
73
|
server: {
|
|
68
74
|
hostname: '127.0.0.1',
|
|
69
75
|
port: 0,
|
|
@@ -79,11 +85,14 @@ test('CORS with a regexp', async ({ teardown, equal, pass, same }) => {
|
|
|
79
85
|
app.register(platformaticService, opts)
|
|
80
86
|
app.post('/login', (req, reply) => {})
|
|
81
87
|
})
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
|
|
89
|
+
teardown(async () => {
|
|
90
|
+
await app.close()
|
|
91
|
+
})
|
|
92
|
+
await app.start()
|
|
84
93
|
|
|
85
94
|
{
|
|
86
|
-
const res = await (request(`${
|
|
95
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
87
96
|
method: 'OPTIONS',
|
|
88
97
|
headers: {
|
|
89
98
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -96,7 +105,7 @@ test('CORS with a regexp', async ({ teardown, equal, pass, same }) => {
|
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
{
|
|
99
|
-
const res = await (request(`${
|
|
108
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
100
109
|
method: 'OPTIONS',
|
|
101
110
|
headers: {
|
|
102
111
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -109,7 +118,7 @@ test('CORS with a regexp', async ({ teardown, equal, pass, same }) => {
|
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
{
|
|
112
|
-
const res = await (request(`${
|
|
121
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
113
122
|
method: 'OPTIONS',
|
|
114
123
|
headers: {
|
|
115
124
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -123,7 +132,7 @@ test('CORS with a regexp', async ({ teardown, equal, pass, same }) => {
|
|
|
123
132
|
})
|
|
124
133
|
|
|
125
134
|
test('CORS with an array of strings', async ({ teardown, equal, pass, same }) => {
|
|
126
|
-
const
|
|
135
|
+
const app = await buildServer({
|
|
127
136
|
server: {
|
|
128
137
|
hostname: '127.0.0.1',
|
|
129
138
|
port: 0,
|
|
@@ -137,11 +146,14 @@ test('CORS with an array of strings', async ({ teardown, equal, pass, same }) =>
|
|
|
137
146
|
app.register(platformaticService, opts)
|
|
138
147
|
app.post('/login', (req, reply) => {})
|
|
139
148
|
})
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
|
|
150
|
+
teardown(async () => {
|
|
151
|
+
await app.close()
|
|
152
|
+
})
|
|
153
|
+
await app.start()
|
|
142
154
|
|
|
143
155
|
{
|
|
144
|
-
const res = await (request(`${
|
|
156
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
145
157
|
method: 'OPTIONS',
|
|
146
158
|
headers: {
|
|
147
159
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -154,7 +166,7 @@ test('CORS with an array of strings', async ({ teardown, equal, pass, same }) =>
|
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
{
|
|
157
|
-
const res = await (request(`${
|
|
169
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
158
170
|
method: 'OPTIONS',
|
|
159
171
|
headers: {
|
|
160
172
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -167,7 +179,7 @@ test('CORS with an array of strings', async ({ teardown, equal, pass, same }) =>
|
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
{
|
|
170
|
-
const res = await (request(`${
|
|
182
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
171
183
|
method: 'OPTIONS',
|
|
172
184
|
headers: {
|
|
173
185
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -181,7 +193,7 @@ test('CORS with an array of strings', async ({ teardown, equal, pass, same }) =>
|
|
|
181
193
|
})
|
|
182
194
|
|
|
183
195
|
test('CORS with an array and a regexp', async ({ teardown, equal, pass, same }) => {
|
|
184
|
-
const
|
|
196
|
+
const app = await buildServer({
|
|
185
197
|
server: {
|
|
186
198
|
hostname: '127.0.0.1',
|
|
187
199
|
port: 0,
|
|
@@ -197,11 +209,14 @@ test('CORS with an array and a regexp', async ({ teardown, equal, pass, same })
|
|
|
197
209
|
app.register(platformaticService, opts)
|
|
198
210
|
app.post('/login', (req, reply) => {})
|
|
199
211
|
})
|
|
200
|
-
|
|
201
|
-
|
|
212
|
+
|
|
213
|
+
teardown(async () => {
|
|
214
|
+
await app.close()
|
|
215
|
+
})
|
|
216
|
+
await app.start()
|
|
202
217
|
|
|
203
218
|
{
|
|
204
|
-
const res = await (request(`${
|
|
219
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
205
220
|
method: 'OPTIONS',
|
|
206
221
|
headers: {
|
|
207
222
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -214,7 +229,7 @@ test('CORS with an array and a regexp', async ({ teardown, equal, pass, same })
|
|
|
214
229
|
}
|
|
215
230
|
|
|
216
231
|
{
|
|
217
|
-
const res = await (request(`${
|
|
232
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
218
233
|
method: 'OPTIONS',
|
|
219
234
|
headers: {
|
|
220
235
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -227,7 +242,7 @@ test('CORS with an array and a regexp', async ({ teardown, equal, pass, same })
|
|
|
227
242
|
}
|
|
228
243
|
|
|
229
244
|
{
|
|
230
|
-
const res = await (request(`${
|
|
245
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
231
246
|
method: 'OPTIONS',
|
|
232
247
|
headers: {
|
|
233
248
|
'Access-Control-Request-Method': 'POST',
|
|
@@ -241,7 +256,7 @@ test('CORS with an array and a regexp', async ({ teardown, equal, pass, same })
|
|
|
241
256
|
})
|
|
242
257
|
|
|
243
258
|
test('CORS with a string', async ({ teardown, equal, pass, same }) => {
|
|
244
|
-
const
|
|
259
|
+
const app = await buildServer({
|
|
245
260
|
server: {
|
|
246
261
|
hostname: '127.0.0.1',
|
|
247
262
|
port: 0,
|
|
@@ -255,11 +270,14 @@ test('CORS with a string', async ({ teardown, equal, pass, same }) => {
|
|
|
255
270
|
app.register(platformaticService, opts)
|
|
256
271
|
app.post('/login', (req, reply) => {})
|
|
257
272
|
})
|
|
258
|
-
|
|
259
|
-
|
|
273
|
+
|
|
274
|
+
teardown(async () => {
|
|
275
|
+
await app.close()
|
|
276
|
+
})
|
|
277
|
+
await app.start()
|
|
260
278
|
|
|
261
279
|
{
|
|
262
|
-
const res = await (request(`${
|
|
280
|
+
const res = await (request(`${app.url}/_admin/login`, {
|
|
263
281
|
method: 'OPTIONS',
|
|
264
282
|
headers: {
|
|
265
283
|
'Access-Control-Request-Method': 'POST',
|
package/test/graphql.test.js
CHANGED
|
@@ -7,7 +7,7 @@ const { request } = require('undici')
|
|
|
7
7
|
const { join } = require('path')
|
|
8
8
|
|
|
9
9
|
test('graphql enabled', async ({ teardown, equal, same }) => {
|
|
10
|
-
const
|
|
10
|
+
const app = await buildServer(buildConfig({
|
|
11
11
|
server: {
|
|
12
12
|
hostname: '127.0.0.1',
|
|
13
13
|
port: 0,
|
|
@@ -23,12 +23,14 @@ test('graphql enabled', async ({ teardown, equal, same }) => {
|
|
|
23
23
|
paths: [join(__dirname, 'fixtures', 'hello-world-resolver.js')]
|
|
24
24
|
}
|
|
25
25
|
}))
|
|
26
|
-
teardown(server.stop)
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
teardown(async () => {
|
|
28
|
+
await app.close()
|
|
29
|
+
})
|
|
30
|
+
await app.start()
|
|
29
31
|
|
|
30
32
|
{
|
|
31
|
-
const res = await request(`${
|
|
33
|
+
const res = await request(`${app.url}/graphql`, {
|
|
32
34
|
method: 'POST',
|
|
33
35
|
headers: {
|
|
34
36
|
'content-type': 'application/json'
|
|
@@ -50,14 +52,14 @@ test('graphql enabled', async ({ teardown, equal, same }) => {
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
{
|
|
53
|
-
const res = await request(`${
|
|
55
|
+
const res = await request(`${app.url}/graphiql`)
|
|
54
56
|
equal(res.statusCode, 200, 'graphiql status code')
|
|
55
57
|
}
|
|
56
58
|
})
|
|
57
59
|
|
|
58
60
|
test('graphql disabled', async ({ teardown, equal, fail }) => {
|
|
59
61
|
try {
|
|
60
|
-
const
|
|
62
|
+
const app = await buildServer(buildConfig({
|
|
61
63
|
server: {
|
|
62
64
|
hostname: '127.0.0.1',
|
|
63
65
|
port: 0,
|
|
@@ -73,7 +75,7 @@ test('graphql disabled', async ({ teardown, equal, fail }) => {
|
|
|
73
75
|
paths: [join(__dirname, 'fixtures', 'hello-world-resolver.js')]
|
|
74
76
|
}
|
|
75
77
|
}))
|
|
76
|
-
await
|
|
78
|
+
await app.close()
|
|
77
79
|
fail('should have errored but did not')
|
|
78
80
|
} catch (err) {
|
|
79
81
|
equal(err.message, 'Cannot read properties of undefined (reading \'extendSchema\')')
|
|
@@ -81,7 +83,7 @@ test('graphql disabled', async ({ teardown, equal, fail }) => {
|
|
|
81
83
|
})
|
|
82
84
|
|
|
83
85
|
test('disable graphiql', async ({ teardown, equal, same }) => {
|
|
84
|
-
const
|
|
86
|
+
const app = await buildServer(buildConfig({
|
|
85
87
|
server: {
|
|
86
88
|
hostname: '127.0.0.1',
|
|
87
89
|
port: 0,
|
|
@@ -99,12 +101,14 @@ test('disable graphiql', async ({ teardown, equal, same }) => {
|
|
|
99
101
|
paths: [join(__dirname, 'fixtures', 'hello-world-resolver.js')]
|
|
100
102
|
}
|
|
101
103
|
}))
|
|
102
|
-
teardown(server.stop)
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
teardown(async () => {
|
|
106
|
+
await app.close()
|
|
107
|
+
})
|
|
108
|
+
await app.start()
|
|
105
109
|
|
|
106
110
|
{
|
|
107
|
-
const res = await request(`${
|
|
111
|
+
const res = await request(`${app.url}/graphql`, {
|
|
108
112
|
method: 'POST',
|
|
109
113
|
headers: {
|
|
110
114
|
'content-type': 'application/json'
|
|
@@ -126,14 +130,14 @@ test('disable graphiql', async ({ teardown, equal, same }) => {
|
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
{
|
|
129
|
-
const res = await request(`${
|
|
133
|
+
const res = await request(`${app.url}/graphiql`)
|
|
130
134
|
equal(res.statusCode, 404, 'graphiql status code')
|
|
131
135
|
}
|
|
132
136
|
})
|
|
133
137
|
|
|
134
138
|
test('graphql disabled by default', async ({ teardown, equal, fail }) => {
|
|
135
139
|
try {
|
|
136
|
-
const
|
|
140
|
+
const app = await buildServer(buildConfig({
|
|
137
141
|
server: {
|
|
138
142
|
hostname: '127.0.0.1',
|
|
139
143
|
port: 0,
|
|
@@ -146,7 +150,7 @@ test('graphql disabled by default', async ({ teardown, equal, fail }) => {
|
|
|
146
150
|
paths: [join(__dirname, 'fixtures', 'hello-world-resolver.js')]
|
|
147
151
|
}
|
|
148
152
|
}))
|
|
149
|
-
await
|
|
153
|
+
await app.close()
|
|
150
154
|
fail('should have errored but did not')
|
|
151
155
|
} catch (err) {
|
|
152
156
|
equal(err.message, 'Cannot read properties of undefined (reading \'extendSchema\')')
|
package/test/healthcheck.test.js
CHANGED
|
@@ -7,7 +7,7 @@ const { request } = require('undici')
|
|
|
7
7
|
|
|
8
8
|
test('healthcheck route enabled with interval', async ({ teardown, equal, same }) => {
|
|
9
9
|
let check = true
|
|
10
|
-
const
|
|
10
|
+
const app = await buildServer({
|
|
11
11
|
server: {
|
|
12
12
|
hostname: '127.0.0.1',
|
|
13
13
|
port: 0,
|
|
@@ -20,11 +20,14 @@ test('healthcheck route enabled with interval', async ({ teardown, equal, same }
|
|
|
20
20
|
},
|
|
21
21
|
metrics: false
|
|
22
22
|
})
|
|
23
|
-
teardown(server.stop)
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
teardown(async () => {
|
|
25
|
+
await app.close()
|
|
26
|
+
})
|
|
27
|
+
await app.start()
|
|
28
|
+
|
|
26
29
|
{
|
|
27
|
-
const res = await (request(`${
|
|
30
|
+
const res = await (request(`${app.url}/status`))
|
|
28
31
|
equal(res.statusCode, 200)
|
|
29
32
|
const body = await res.body.json()
|
|
30
33
|
same(body, { status: 'ok' })
|
|
@@ -33,7 +36,7 @@ test('healthcheck route enabled with interval', async ({ teardown, equal, same }
|
|
|
33
36
|
check = false
|
|
34
37
|
|
|
35
38
|
{
|
|
36
|
-
const res = await (request(`${
|
|
39
|
+
const res = await (request(`${app.url}/status`))
|
|
37
40
|
equal(res.statusCode, 503)
|
|
38
41
|
const body = await res.body.json()
|
|
39
42
|
same(body, {
|
|
@@ -48,7 +51,7 @@ test('healthcheck route enabled with interval', async ({ teardown, equal, same }
|
|
|
48
51
|
})
|
|
49
52
|
|
|
50
53
|
test('healthcheck route enabled without interval', async ({ teardown, equal, same }) => {
|
|
51
|
-
const
|
|
54
|
+
const app = await buildServer({
|
|
52
55
|
server: {
|
|
53
56
|
hostname: '127.0.0.1',
|
|
54
57
|
port: 0,
|
|
@@ -56,11 +59,14 @@ test('healthcheck route enabled without interval', async ({ teardown, equal, sam
|
|
|
56
59
|
},
|
|
57
60
|
metrics: false
|
|
58
61
|
})
|
|
59
|
-
teardown(server.stop)
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
teardown(async () => {
|
|
64
|
+
await app.close()
|
|
65
|
+
})
|
|
66
|
+
await app.start()
|
|
67
|
+
|
|
62
68
|
{
|
|
63
|
-
const res = await (request(`${
|
|
69
|
+
const res = await (request(`${app.url}/status`))
|
|
64
70
|
equal(res.statusCode, 200)
|
|
65
71
|
const body = await res.body.json()
|
|
66
72
|
same(body, { status: 'ok' })
|
|
@@ -68,16 +74,19 @@ test('healthcheck route enabled without interval', async ({ teardown, equal, sam
|
|
|
68
74
|
})
|
|
69
75
|
|
|
70
76
|
test('healthcheck route disabled', async ({ teardown, equal, same }) => {
|
|
71
|
-
const
|
|
77
|
+
const app = await buildServer({
|
|
72
78
|
server: {
|
|
73
79
|
hostname: '127.0.0.1',
|
|
74
80
|
port: 0
|
|
75
81
|
},
|
|
76
82
|
metrics: false
|
|
77
83
|
})
|
|
78
|
-
teardown(server.stop)
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
teardown(async () => {
|
|
86
|
+
await app.close()
|
|
87
|
+
})
|
|
88
|
+
await app.start()
|
|
89
|
+
|
|
90
|
+
const res = await (request(`${app.url}/status`))
|
|
82
91
|
equal(res.statusCode, 404)
|
|
83
92
|
})
|