@platformatic/service 0.22.0 → 0.23.1

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.
Files changed (38) hide show
  1. package/fixtures/hello-client-ts/platformatic.service.json +2 -1
  2. package/index.js +118 -169
  3. package/lib/load-config.js +6 -1
  4. package/lib/plugins/clients.js +12 -0
  5. package/lib/plugins/cors.js +29 -0
  6. package/lib/plugins/file-watcher.js +44 -0
  7. package/lib/plugins/health-check.js +17 -0
  8. package/lib/plugins/plugins.js +56 -0
  9. package/lib/plugins/typescript.js +46 -0
  10. package/lib/root-endpoint/index.js +1 -0
  11. package/lib/schema.js +8 -1
  12. package/lib/start.mjs +27 -136
  13. package/lib/utils.js +2 -2
  14. package/package.json +9 -8
  15. package/test/autoload.test.js +77 -59
  16. package/test/cli/compile.test.mjs +45 -33
  17. package/test/cli/watch.test.mjs +39 -0
  18. package/test/clients.test.js +24 -17
  19. package/test/config.test.js +58 -86
  20. package/test/cors.test.js +48 -30
  21. package/test/fixtures/bad-typescript-plugin/platformatic.service.json +3 -1
  22. package/test/fixtures/typescript-autoload/platformatic.service.json +3 -1
  23. package/test/fixtures/typescript-plugin/platformatic.service.json +3 -1
  24. package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +2 -1
  25. package/test/graphql.test.js +18 -14
  26. package/test/healthcheck.test.js +22 -13
  27. package/test/https.test.js +11 -8
  28. package/test/lambda.test.js +103 -0
  29. package/test/load-and-reload-files.test.js +97 -112
  30. package/test/load-plugin.test.js +8 -4
  31. package/test/metrics.test.js +59 -39
  32. package/test/routes.test.js +43 -25
  33. package/test/utils.test.js +2 -2
  34. package/test/watch.test.js +182 -0
  35. /package/lib/{graphql.js → plugins/graphql.js} +0 -0
  36. /package/lib/{metrics-plugin.js → plugins/metrics.js} +0 -0
  37. /package/lib/{openapi.js → plugins/openapi.js} +0 -0
  38. /package/lib/{sandbox-wrapper.js → plugins/sandbox-wrapper.js} +0 -0
@@ -16,7 +16,7 @@ test('load and reload', async ({ teardown, equal, pass, same }) => {
16
16
  }`
17
17
  )
18
18
 
19
- const server = await buildServer({
19
+ const app = await buildServer({
20
20
  server: {
21
21
  hostname: '127.0.0.1',
22
22
  port: 0
@@ -26,11 +26,14 @@ test('load and reload', async ({ teardown, equal, pass, same }) => {
26
26
  },
27
27
  metrics: false
28
28
  })
29
- teardown(server.stop)
30
- await server.listen()
29
+
30
+ teardown(async () => {
31
+ await app.close()
32
+ })
33
+ await app.start()
31
34
 
32
35
  {
33
- const res = await request(`${server.url}/`)
36
+ const res = await request(`${app.url}/`)
34
37
  equal(res.statusCode, 200, 'status code')
35
38
  const data = await res.body.json()
36
39
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
@@ -38,13 +41,13 @@ test('load and reload', async ({ teardown, equal, pass, same }) => {
38
41
 
39
42
  await writeFile(file, `
40
43
  module.exports = async function (app) {
41
- app.get('/', () => "hello world" )
44
+ app.get('/', () => "hello world" )
42
45
  }`)
43
46
 
44
- await server.restart()
47
+ await app.restart()
45
48
 
46
49
  {
47
- const res = await request(`${server.url}/`)
50
+ const res = await request(`${app.url}/`)
48
51
  equal(res.statusCode, 200, 'add status code')
49
52
  same(await res.body.text(), 'hello world', 'response')
50
53
  }
@@ -60,7 +63,7 @@ test('error', async ({ teardown, equal, pass, match }) => {
60
63
  })
61
64
  }`)
62
65
 
63
- const server = await buildServer({
66
+ const app = await buildServer({
64
67
  server: {
65
68
  hostname: '127.0.0.1',
66
69
  port: 0
@@ -70,63 +73,19 @@ test('error', async ({ teardown, equal, pass, match }) => {
70
73
  },
71
74
  metrics: false
72
75
  })
73
- teardown(server.stop)
74
- await server.listen()
75
76
 
76
- const res = await request(`${server.url}/`)
77
+ teardown(async () => {
78
+ await app.close()
79
+ })
80
+ await app.start()
81
+
82
+ const res = await request(`${app.url}/`)
77
83
  equal(res.statusCode, 500, 'add status code')
78
84
  match(await res.body.json(), {
79
85
  message: 'kaboom'
80
86
  })
81
87
  })
82
88
 
83
- test('update config', async ({ teardown, equal, pass, same }) => {
84
- const file = join(os.tmpdir(), `some-plugin-${process.pid}.js`)
85
- await writeFile(file, `
86
- module.exports = async function (app) {
87
- }`
88
- )
89
-
90
- const server = await buildServer({
91
- server: {
92
- hostname: '127.0.0.1',
93
- port: 0
94
- },
95
- metrics: false
96
- })
97
- teardown(server.stop)
98
- await server.listen()
99
-
100
- {
101
- const res = await request(`${server.url}/`)
102
- equal(res.statusCode, 200, 'status code')
103
- const data = await res.body.json()
104
- same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
105
- }
106
-
107
- const file2 = join(os.tmpdir(), `some-plugin-${process.pid}-2.js`)
108
- await writeFile(file2, `
109
- module.exports = async function (app) {
110
- app.get('/', () => "hello world" )
111
- }`)
112
-
113
- await server.restart({
114
- server: {
115
- hostname: '127.0.0.1',
116
- port: 0
117
- },
118
- plugins: {
119
- paths: [file2]
120
- }
121
- })
122
-
123
- {
124
- const res = await request(`${server.url}/`)
125
- equal(res.statusCode, 200, 'add status code')
126
- same(await res.body.text(), 'hello world', 'response')
127
- }
128
- })
129
-
130
89
  test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
131
90
  const previousAgent = getGlobalDispatcher()
132
91
  teardown(() => setGlobalDispatcher(previousAgent))
@@ -147,7 +106,7 @@ test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
147
106
  hello: 'world'
148
107
  })
149
108
 
150
- const server = await buildServer({
109
+ const app = await buildServer({
151
110
  server: {
152
111
  hostname: '127.0.0.1',
153
112
  port: 0
@@ -156,10 +115,13 @@ test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
156
115
  paths: [join(__dirname, 'fixtures', 'undici-plugin.js')]
157
116
  }
158
117
  })
159
- teardown(server.stop)
160
- await server.listen()
161
118
 
162
- const res = await request(`${server.url}/request`, {
119
+ teardown(async () => {
120
+ await app.close()
121
+ })
122
+ await app.start()
123
+
124
+ const res = await request(`${app.url}/request`, {
163
125
  method: 'GET'
164
126
  })
165
127
  equal(res.statusCode, 200)
@@ -176,7 +138,7 @@ test('load and reload with the fallback', async ({ teardown, equal, pass, same }
176
138
  }`
177
139
  )
178
140
 
179
- const server = await buildServer({
141
+ const app = await buildServer({
180
142
  server: {
181
143
  hostname: '127.0.0.1',
182
144
  port: 0
@@ -187,11 +149,14 @@ test('load and reload with the fallback', async ({ teardown, equal, pass, same }
187
149
  fallback: true
188
150
  }
189
151
  })
190
- teardown(server.stop)
191
- await server.listen()
152
+
153
+ teardown(async () => {
154
+ await app.close()
155
+ })
156
+ await app.start()
192
157
 
193
158
  {
194
- const res = await request(`${server.url}/`)
159
+ const res = await request(`${app.url}/`)
195
160
  equal(res.statusCode, 200, 'status code')
196
161
  const data = await res.body.json()
197
162
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
@@ -199,13 +164,13 @@ test('load and reload with the fallback', async ({ teardown, equal, pass, same }
199
164
 
200
165
  await writeFile(file, `
201
166
  module.exports = async function (app) {
202
- app.get('/', () => "hello world" )
167
+ app.get('/', () => "hello world" )
203
168
  }`)
204
169
 
205
- await server.restart()
170
+ await app.restart()
206
171
 
207
172
  {
208
- const res = await request(`${server.url}/`)
173
+ const res = await request(`${app.url}/`)
209
174
  equal(res.statusCode, 200, 'add status code')
210
175
  same(await res.body.text(), 'hello world', 'response')
211
176
  }
@@ -219,7 +184,7 @@ test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
219
184
  }`
220
185
  )
221
186
 
222
- const server = await buildServer({
187
+ const app = await buildServer({
223
188
  server: {
224
189
  hostname: '127.0.0.1',
225
190
  port: 0
@@ -228,11 +193,14 @@ test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
228
193
  paths: [file]
229
194
  }
230
195
  })
231
- teardown(server.stop)
232
- await server.listen()
196
+
197
+ teardown(async () => {
198
+ await app.close()
199
+ })
200
+ await app.start()
233
201
 
234
202
  {
235
- const res = await request(`${server.url}/`)
203
+ const res = await request(`${app.url}/`)
236
204
  equal(res.statusCode, 200, 'status code')
237
205
  const data = await res.body.json()
238
206
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
@@ -240,13 +208,13 @@ test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
240
208
 
241
209
  await writeFile(file, `
242
210
  export default async function (app) {
243
- app.get('/', () => "hello world" )
211
+ app.get('/', () => "hello world" )
244
212
  }`)
245
213
 
246
- await server.restart()
214
+ await app.restart()
247
215
 
248
216
  {
249
- const res = await request(`${server.url}/`)
217
+ const res = await request(`${app.url}/`)
250
218
  equal(res.statusCode, 200, 'add status code')
251
219
  same(await res.body.text(), 'hello world', 'response')
252
220
  }
@@ -271,34 +239,35 @@ test('server should be available after reload a compromised plugin', async ({ te
271
239
  paths: [file]
272
240
  }
273
241
  }
274
- const restartConfig = { ...config }
275
- delete restartConfig.server
276
242
 
277
- const server = await buildServer(config)
278
- await server.listen()
243
+ const app = await buildServer(config)
244
+
245
+ teardown(async () => {
246
+ await app.close()
247
+ })
248
+ await app.start()
249
+
279
250
  await writeFile(file, compromisedModule)
280
- await server.restart(restartConfig).catch(() => {
251
+ await app.restart().catch(() => {
281
252
  pass('plugin reload failed')
282
253
  })
283
254
 
284
255
  {
285
- const res = await request(`${server.url}/`, { method: 'GET' })
256
+ const res = await request(`${app.url}/`, { method: 'GET' })
286
257
  equal(res.statusCode, 200, 'status code')
287
258
  const data = await res.body.json()
288
259
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
289
260
  }
290
261
 
291
262
  await writeFile(file, workingModule)
292
- await rejects(server.restart(restartConfig))
263
+ await app.restart()
293
264
 
294
265
  {
295
- const res = await request(`${server.url}/`, { method: 'GET' })
266
+ const res = await request(`${app.url}/`, { method: 'GET' })
296
267
  equal(res.statusCode, 200, 'add status code')
297
268
  const data = await res.body.json()
298
269
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
299
270
  }
300
-
301
- teardown(server.stop)
302
271
  })
303
272
 
304
273
  test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) => {
@@ -312,7 +281,7 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
312
281
  }`
313
282
  )
314
283
 
315
- const server = await buildServer({
284
+ const app = await buildServer({
316
285
  server: {
317
286
  hostname: '127.0.0.1',
318
287
  port: 0
@@ -322,11 +291,14 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
322
291
  hotReload: false
323
292
  }
324
293
  })
325
- teardown(server.stop)
326
- await server.listen()
294
+
295
+ teardown(async () => {
296
+ await app.close()
297
+ })
298
+ await app.start()
327
299
 
328
300
  {
329
- const res = await request(`${server.url}/test`, {
301
+ const res = await request(`${app.url}/test`, {
330
302
  method: 'GET'
331
303
  })
332
304
  equal(res.statusCode, 200)
@@ -341,10 +313,10 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
341
313
  }`
342
314
  )
343
315
 
344
- await server.restart()
316
+ await app.restart()
345
317
 
346
318
  {
347
- const res = await request(`${server.url}/test`, {
319
+ const res = await request(`${app.url}/test`, {
348
320
  method: 'GET'
349
321
  })
350
322
  equal(res.statusCode, 200)
@@ -354,9 +326,10 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
354
326
  })
355
327
 
356
328
  test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
357
- const file = join(os.tmpdir(), `some-plugin-hot-rel-test-${process.pid}.mjs`)
329
+ const pathToPlugin = join(os.tmpdir(), `some-plugin-hot-rel-test-${process.pid}.mjs`)
330
+ const pathToConfig = join(os.tmpdir(), `platformatic.service.${process.pid}.json`)
358
331
 
359
- await writeFile(file, `
332
+ await writeFile(pathToPlugin, `
360
333
  export default async function (app) {
361
334
  app.get('/test', {}, async function (request, response) {
362
335
  return { res: "plugin, version 1"}
@@ -364,31 +337,36 @@ test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
364
337
  }`
365
338
  )
366
339
 
367
- const server = await buildServer({
340
+ const config = {
368
341
  server: {
369
342
  hostname: '127.0.0.1',
370
343
  port: 0
371
344
  },
372
345
  plugins: {
373
- paths: [file],
346
+ paths: [pathToPlugin],
374
347
  stopTimeout: 1000,
375
348
  hotReload: false
376
349
  },
377
350
  watch: true,
378
351
  metrics: false
352
+ }
353
+ await writeFile(pathToConfig, JSON.stringify(config, null, 2))
354
+ const app = await buildServer(pathToConfig)
355
+
356
+ teardown(async () => {
357
+ await app.close()
379
358
  })
380
- teardown(server.stop)
381
- await server.listen()
359
+ await app.start()
382
360
 
383
361
  {
384
- const res = await request(`${server.url}/test`, {
362
+ const res = await request(`${app.url}/test`, {
385
363
  method: 'GET'
386
364
  })
387
365
  equal(res.statusCode, 200)
388
366
  same(await res.body.json(), { res: 'plugin, version 1' }, 'get rest plugin')
389
367
  }
390
368
 
391
- await writeFile(file, `
369
+ await writeFile(pathToPlugin, `
392
370
  export default async function (app) {
393
371
  app.get('/test', {}, async function (request, response) {
394
372
  return { res: "plugin, version 2"}
@@ -396,10 +374,10 @@ test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
396
374
  }`
397
375
  )
398
376
 
399
- await server.restart()
377
+ await app.restart()
400
378
 
401
379
  {
402
- const res = await request(`${server.url}/test`, {
380
+ const res = await request(`${app.url}/test`, {
403
381
  method: 'GET'
404
382
  })
405
383
  equal(res.statusCode, 200)
@@ -409,9 +387,10 @@ test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
409
387
  })
410
388
 
411
389
  test('hot reload disabled, with default export', async ({ teardown, equal, pass, same }) => {
412
- const file = join(os.tmpdir(), `some-plugin-hot-rel-test-${process.pid}.js`)
390
+ const pathToPlugin = join(os.tmpdir(), `some-plugin-hot-rel-test-${process.pid}.js`)
391
+ const pathToConfig = join(os.tmpdir(), `platformatic.service.${process.pid}.json`)
413
392
 
414
- await writeFile(file, `
393
+ await writeFile(pathToPlugin, `
415
394
  Object.defineProperty(exports, "__esModule", { value: true })
416
395
  exports.default = async function plugin (app) {
417
396
  app.get('/test', {}, async function (request, response) {
@@ -419,30 +398,36 @@ test('hot reload disabled, with default export', async ({ teardown, equal, pass,
419
398
  })
420
399
  }`)
421
400
 
422
- const server = await buildServer({
401
+ const config = {
423
402
  server: {
424
403
  hostname: '127.0.0.1',
425
404
  port: 0
426
405
  },
427
406
  plugins: {
428
- paths: [file],
407
+ paths: [pathToPlugin],
429
408
  stopTimeout: 1000,
430
409
  hotReload: false
431
410
  },
432
411
  watch: true,
433
412
  metrics: false
413
+ }
414
+
415
+ await writeFile(pathToConfig, JSON.stringify(config, null, 2))
416
+ const app = await buildServer(pathToConfig)
417
+
418
+ teardown(async () => {
419
+ await app.close()
434
420
  })
435
- teardown(server.stop)
436
- await server.listen()
421
+ await app.start()
437
422
 
438
423
  {
439
- const res = await request(`${server.url}/test`, {
424
+ const res = await request(`${app.url}/test`, {
440
425
  method: 'GET'
441
426
  })
442
427
  same(await res.body.json(), { res: 'plugin, version 1' }, 'get rest plugin')
443
428
  }
444
429
 
445
- await writeFile(file, `
430
+ await writeFile(pathToPlugin, `
446
431
  Object.defineProperty(exports, "__esModule", { value: true })
447
432
  exports.default = async function plugin (app) {
448
433
  app.get('/test', {}, async function (request, response) {
@@ -451,10 +436,10 @@ test('hot reload disabled, with default export', async ({ teardown, equal, pass,
451
436
  }`
452
437
  )
453
438
 
454
- await server.restart()
439
+ await app.restart()
455
440
 
456
441
  {
457
- const res = await request(`${server.url}/test`, {
442
+ const res = await request(`${app.url}/test`, {
458
443
  method: 'GET'
459
444
  })
460
445
  equal(res.statusCode, 200)
@@ -14,15 +14,19 @@ test('customize service', async ({ teardown, equal }) => {
14
14
  }])
15
15
  }
16
16
 
17
- const server = await buildServer({
17
+ const app = await buildServer({
18
18
  server: {
19
19
  hostname: '127.0.0.1',
20
20
  port: 0
21
21
  }
22
22
  }, myApp)
23
- teardown(server.stop)
24
- await server.listen()
25
- const res = await (request(server.url))
23
+
24
+ teardown(async () => {
25
+ await app.close()
26
+ })
27
+ await app.start()
28
+
29
+ const res = await (request(app.url))
26
30
  const body = await res.body.text()
27
31
  equal(res.statusCode, 200)
28
32
  equal(body, 'hello world')
@@ -10,15 +10,19 @@ const { promisify } = require('util')
10
10
  const sleep = promisify(setTimeout)
11
11
 
12
12
  test('has /metrics endpoint on default prometheus port', async ({ teardown, equal, fail, match }) => {
13
- const server = await buildServer({
13
+ const app = await buildServer({
14
14
  server: {
15
15
  hostname: '127.0.0.1',
16
16
  port: 0
17
17
  },
18
18
  metrics: true
19
19
  })
20
- teardown(server.stop)
21
- await server.listen()
20
+
21
+ teardown(async () => {
22
+ await app.close()
23
+ })
24
+ await app.start()
25
+
22
26
  // needed to reach 100% code cov, otherwise the ELU check won't run
23
27
  await sleep(120)
24
28
  const res = await (request('http://127.0.0.1:9090/metrics'))
@@ -29,15 +33,19 @@ test('has /metrics endpoint on default prometheus port', async ({ teardown, equa
29
33
  })
30
34
 
31
35
  test('has /metrics endpoint with accept application/json', async ({ teardown, equal, fail, match }) => {
32
- const server = await buildServer({
36
+ const app = await buildServer({
33
37
  server: {
34
38
  hostname: '127.0.0.1',
35
39
  port: 0
36
40
  },
37
41
  metrics: true
38
42
  })
39
- teardown(server.stop)
40
- await server.listen()
43
+
44
+ teardown(async () => {
45
+ await app.close()
46
+ })
47
+ await app.start()
48
+
41
49
  const res = await (request(
42
50
  'http://127.0.0.1:9090/metrics',
43
51
  {
@@ -53,7 +61,7 @@ test('has /metrics endpoint with accept application/json', async ({ teardown, eq
53
61
  })
54
62
 
55
63
  test('has /metrics endpoint on configured port', async ({ teardown, equal, fail, match }) => {
56
- const server = await buildServer({
64
+ const app = await buildServer({
57
65
  server: {
58
66
  hostname: '127.0.0.1',
59
67
  port: 0
@@ -62,8 +70,12 @@ test('has /metrics endpoint on configured port', async ({ teardown, equal, fail,
62
70
  port: 9999
63
71
  }
64
72
  })
65
- teardown(server.stop)
66
- await server.listen()
73
+
74
+ teardown(async () => {
75
+ await app.close()
76
+ })
77
+ await app.start()
78
+
67
79
  const res = await (request('http://127.0.0.1:9999/metrics'))
68
80
  equal(res.statusCode, 200)
69
81
  match(res.headers['content-type'], /^text\/plain/)
@@ -72,7 +84,7 @@ test('has /metrics endpoint on configured port', async ({ teardown, equal, fail,
72
84
  })
73
85
 
74
86
  test('support basic auth', async ({ teardown, equal, fail, match }) => {
75
- const server = await buildServer({
87
+ const app = await buildServer({
76
88
  server: {
77
89
  hostname: '127.0.0.1',
78
90
  port: 0
@@ -84,8 +96,12 @@ test('support basic auth', async ({ teardown, equal, fail, match }) => {
84
96
  }
85
97
  }
86
98
  })
87
- teardown(server.stop)
88
- await server.listen()
99
+
100
+ teardown(async () => {
101
+ await app.close()
102
+ })
103
+ await app.start()
104
+
89
105
  {
90
106
  const res = await (request('http://127.0.0.1:9090/metrics'))
91
107
  equal(res.statusCode, 401)
@@ -116,15 +132,28 @@ test('support basic auth', async ({ teardown, equal, fail, match }) => {
116
132
  }
117
133
  })
118
134
 
119
- function testPrometheusJsonOutput (output) {
120
- for (const metric of output) {
121
- equal(typeof metric.help, 'string', 'metric.help is string')
122
- equal(typeof metric.name, 'string', 'metric.name is string')
123
- equal(typeof metric.type, 'string', 'metric.type is string')
124
- equal(typeof metric.aggregator, 'string', 'metric.aggregator is string')
125
- equal(Array.isArray(metric.values), true, 'metric.values is array')
126
- }
127
- }
135
+ test('do not error on restart', async ({ teardown, equal, fail, match }) => {
136
+ const app = await buildServer({
137
+ server: {
138
+ hostname: '127.0.0.1',
139
+ port: 0
140
+ },
141
+ metrics: true
142
+ })
143
+
144
+ teardown(async () => {
145
+ await app.close()
146
+ })
147
+ await app.start()
148
+ await app.restart()
149
+
150
+ const res = await (request('http://127.0.0.1:9090/metrics'))
151
+ equal(res.statusCode, 200)
152
+ match(res.headers['content-type'], /^text\/plain/)
153
+ const body = await res.body.text()
154
+ testPrometheusOutput(body)
155
+ })
156
+
128
157
  function testPrometheusOutput (output) {
129
158
  let metricBlock = []
130
159
  const lines = output.split('\n')
@@ -157,21 +186,12 @@ function checkMetricBlock (metricBlock) {
157
186
  return true
158
187
  }
159
188
 
160
- test('do not error on restart', async ({ teardown, equal, fail, match }) => {
161
- const server = await buildServer({
162
- server: {
163
- hostname: '127.0.0.1',
164
- port: 0
165
- },
166
- metrics: true
167
- })
168
- teardown(server.stop)
169
- await server.listen()
170
- await server.restart()
171
-
172
- const res = await (request('http://127.0.0.1:9090/metrics'))
173
- equal(res.statusCode, 200)
174
- match(res.headers['content-type'], /^text\/plain/)
175
- const body = await res.body.text()
176
- testPrometheusOutput(body)
177
- })
189
+ function testPrometheusJsonOutput (output) {
190
+ for (const metric of output) {
191
+ equal(typeof metric.help, 'string', 'metric.help is string')
192
+ equal(typeof metric.name, 'string', 'metric.name is string')
193
+ equal(typeof metric.type, 'string', 'metric.type is string')
194
+ equal(typeof metric.aggregator, 'string', 'metric.aggregator is string')
195
+ equal(Array.isArray(metric.values), true, 'metric.values is array')
196
+ }
197
+ }