@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.
Files changed (43) hide show
  1. package/fixtures/hello/warn-log.service.json +19 -0
  2. package/fixtures/hello-client/platformatic.service.json +1 -1
  3. package/fixtures/hello-client-ts/platformatic.service.json +3 -2
  4. package/index.js +139 -229
  5. package/lib/compile.js +9 -5
  6. package/lib/load-config.js +13 -15
  7. package/lib/plugins/clients.js +12 -0
  8. package/lib/plugins/cors.js +29 -0
  9. package/lib/plugins/file-watcher.js +44 -0
  10. package/lib/plugins/health-check.js +17 -0
  11. package/lib/plugins/plugins.js +56 -0
  12. package/lib/plugins/typescript.js +46 -0
  13. package/lib/root-endpoint/index.js +1 -0
  14. package/lib/schema.js +8 -1
  15. package/lib/start.mjs +27 -135
  16. package/lib/utils.js +2 -11
  17. package/package.json +24 -23
  18. package/test/autoload.test.js +77 -59
  19. package/test/cli/compile.test.mjs +45 -36
  20. package/test/cli/start.test.mjs +13 -1
  21. package/test/cli/watch.test.mjs +40 -2
  22. package/test/clients.test.js +25 -18
  23. package/test/config.test.js +67 -27
  24. package/test/cors.test.js +48 -30
  25. package/test/fixtures/bad-typescript-plugin/platformatic.service.json +3 -1
  26. package/test/fixtures/custom-port-placeholder.json +10 -0
  27. package/test/fixtures/typescript-autoload/platformatic.service.json +3 -1
  28. package/test/fixtures/typescript-plugin/platformatic.service.json +3 -1
  29. package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +2 -1
  30. package/test/graphql.test.js +18 -14
  31. package/test/healthcheck.test.js +22 -13
  32. package/test/https.test.js +13 -11
  33. package/test/lambda.test.js +103 -0
  34. package/test/load-and-reload-files.test.js +98 -109
  35. package/test/load-plugin.test.js +8 -4
  36. package/test/metrics.test.js +59 -39
  37. package/test/routes.test.js +43 -25
  38. package/test/utils.test.js +6 -15
  39. package/test/watch.test.js +182 -0
  40. /package/lib/{graphql.js → plugins/graphql.js} +0 -0
  41. /package/lib/{metrics-plugin.js → plugins/metrics.js} +0 -0
  42. /package/lib/{openapi.js → plugins/openapi.js} +0 -0
  43. /package/lib/{sandbox-wrapper.js → plugins/sandbox-wrapper.js} +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { mkdtemp, writeFile } = require('fs/promises')
4
4
  const { tmpdir } = require('os')
5
- const { isAbsolute, join, relative } = require('path')
5
+ const { join, relative } = require('path')
6
6
  const selfCert = require('self-cert')
7
7
  const { test } = require('tap')
8
8
  const { Agent, setGlobalDispatcher, request } = require('undici')
@@ -10,7 +10,7 @@ const { buildServer } = require('..')
10
10
  const { buildConfig } = require('./helper')
11
11
 
12
12
  test('supports https options', async ({ teardown, equal, same, plan, comment }) => {
13
- plan(7)
13
+ plan(6)
14
14
 
15
15
  const { certificate, privateKey } = selfCert({})
16
16
  const localDir = tmpdir()
@@ -31,7 +31,7 @@ test('supports https options', async ({ teardown, equal, same, plan, comment })
31
31
  }
32
32
  }))
33
33
 
34
- const server = await buildServer(buildConfig({
34
+ const app = await buildServer(buildConfig({
35
35
  server: {
36
36
  hostname: '127.0.0.1',
37
37
  port: 0,
@@ -42,20 +42,22 @@ test('supports https options', async ({ teardown, equal, same, plan, comment })
42
42
  }
43
43
  }))
44
44
 
45
- teardown(server.stop)
46
- await server.listen()
45
+ teardown(async () => {
46
+ await app.close()
47
+ })
47
48
 
48
- equal(isAbsolute(server.app.platformatic.configManager.current.server.https.cert[0].path), true)
49
- equal(server.url.startsWith('https://'), true)
50
- let res = await (request(`${server.url}/`))
49
+ await app.start()
50
+
51
+ equal(app.url.startsWith('https://'), true)
52
+ let res = await (request(`${app.url}/`))
51
53
  equal(res.statusCode, 200)
52
54
  let body = await res.body.json()
53
55
  same(body, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
54
56
 
55
- await server.restart()
57
+ await app.restart()
56
58
 
57
- equal(server.url.startsWith('https://'), true)
58
- res = await (request(`${server.url}/`))
59
+ equal(app.url.startsWith('https://'), true)
60
+ res = await (request(`${app.url}/`))
59
61
  equal(res.statusCode, 200)
60
62
  body = await res.body.json()
61
63
  same(body, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
@@ -0,0 +1,103 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('tap')
4
+ const { buildServer } = require('..')
5
+ const { buildConfig } = require('./helper')
6
+ const { join } = require('path')
7
+ const awsLambdaFastify = require('@fastify/aws-lambda')
8
+
9
+ test('should respond 200 on root endpoint', async ({ teardown, equal, same, ok }) => {
10
+ const app = await buildServer(buildConfig({
11
+ server: {
12
+ hostname: '127.0.0.1',
13
+ port: 0,
14
+ healthCheck: {
15
+ enabled: true,
16
+ interval: 2000
17
+ }
18
+ }
19
+ }))
20
+
21
+ teardown(async () => {
22
+ await app.close()
23
+ })
24
+
25
+ const handler = awsLambdaFastify(app)
26
+
27
+ {
28
+ // No browser (i.e. curl)
29
+ const evt = {
30
+ version: '2.0',
31
+ httpMethod: 'GET',
32
+ path: '/',
33
+ headers: {
34
+ },
35
+ cookies: [],
36
+ queryStringParameters: ''
37
+ }
38
+
39
+ const ret = await handler(evt)
40
+
41
+ equal(ret.body, JSON.stringify({ message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' }))
42
+ equal(ret.isBase64Encoded, false)
43
+ ok(ret.headers)
44
+ equal(ret.headers['content-type'], 'application/json; charset=utf-8')
45
+ equal(ret.headers['content-length'], '80')
46
+ ok(ret.headers.date)
47
+ equal(ret.headers.connection, 'keep-alive')
48
+ }
49
+
50
+ {
51
+ // browser
52
+ const evt = {
53
+ version: '2.0',
54
+ httpMethod: 'GET',
55
+ path: '/',
56
+ headers: {
57
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
58
+ },
59
+ cookies: [],
60
+ queryStringParameters: ''
61
+ }
62
+
63
+ const ret = await handler(evt)
64
+
65
+ // No browser (i.e. curl)
66
+ equal(ret.isBase64Encoded, false)
67
+ ok(ret.headers)
68
+ equal(ret.headers['content-type'], 'text/html; charset=UTF-8')
69
+ ok(ret.headers.date)
70
+ equal(ret.headers.connection, 'keep-alive')
71
+ }
72
+ })
73
+
74
+ test('from a config file on disk', async ({ teardown, equal, same, ok }) => {
75
+ const app = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
76
+
77
+ teardown(async () => {
78
+ await app.close()
79
+ })
80
+
81
+ const handler = awsLambdaFastify(app)
82
+
83
+ // No browser (i.e. curl)
84
+ const evt = {
85
+ version: '2.0',
86
+ httpMethod: 'GET',
87
+ path: '/',
88
+ headers: {
89
+ },
90
+ cookies: [],
91
+ queryStringParameters: ''
92
+ }
93
+
94
+ const ret = await handler(evt)
95
+
96
+ equal(ret.body, JSON.stringify({ hello: 'world' }))
97
+ equal(ret.isBase64Encoded, false)
98
+ ok(ret.headers)
99
+ equal(ret.headers['content-type'], 'application/json; charset=utf-8')
100
+ equal(ret.headers['content-length'], '17')
101
+ ok(ret.headers.date)
102
+ equal(ret.headers.connection, 'keep-alive')
103
+ })
@@ -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,59 +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
- plugins: {
115
- paths: [file2]
116
- }
117
- })
118
-
119
- {
120
- const res = await request(`${server.url}/`)
121
- equal(res.statusCode, 200, 'add status code')
122
- same(await res.body.text(), 'hello world', 'response')
123
- }
124
- })
125
-
126
89
  test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
127
90
  const previousAgent = getGlobalDispatcher()
128
91
  teardown(() => setGlobalDispatcher(previousAgent))
@@ -143,7 +106,7 @@ test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
143
106
  hello: 'world'
144
107
  })
145
108
 
146
- const server = await buildServer({
109
+ const app = await buildServer({
147
110
  server: {
148
111
  hostname: '127.0.0.1',
149
112
  port: 0
@@ -152,10 +115,13 @@ test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
152
115
  paths: [join(__dirname, 'fixtures', 'undici-plugin.js')]
153
116
  }
154
117
  })
155
- teardown(server.stop)
156
- await server.listen()
157
118
 
158
- 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`, {
159
125
  method: 'GET'
160
126
  })
161
127
  equal(res.statusCode, 200)
@@ -172,7 +138,7 @@ test('load and reload with the fallback', async ({ teardown, equal, pass, same }
172
138
  }`
173
139
  )
174
140
 
175
- const server = await buildServer({
141
+ const app = await buildServer({
176
142
  server: {
177
143
  hostname: '127.0.0.1',
178
144
  port: 0
@@ -183,11 +149,14 @@ test('load and reload with the fallback', async ({ teardown, equal, pass, same }
183
149
  fallback: true
184
150
  }
185
151
  })
186
- teardown(server.stop)
187
- await server.listen()
152
+
153
+ teardown(async () => {
154
+ await app.close()
155
+ })
156
+ await app.start()
188
157
 
189
158
  {
190
- const res = await request(`${server.url}/`)
159
+ const res = await request(`${app.url}/`)
191
160
  equal(res.statusCode, 200, 'status code')
192
161
  const data = await res.body.json()
193
162
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
@@ -195,13 +164,13 @@ test('load and reload with the fallback', async ({ teardown, equal, pass, same }
195
164
 
196
165
  await writeFile(file, `
197
166
  module.exports = async function (app) {
198
- app.get('/', () => "hello world" )
167
+ app.get('/', () => "hello world" )
199
168
  }`)
200
169
 
201
- await server.restart()
170
+ await app.restart()
202
171
 
203
172
  {
204
- const res = await request(`${server.url}/`)
173
+ const res = await request(`${app.url}/`)
205
174
  equal(res.statusCode, 200, 'add status code')
206
175
  same(await res.body.text(), 'hello world', 'response')
207
176
  }
@@ -215,7 +184,7 @@ test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
215
184
  }`
216
185
  )
217
186
 
218
- const server = await buildServer({
187
+ const app = await buildServer({
219
188
  server: {
220
189
  hostname: '127.0.0.1',
221
190
  port: 0
@@ -224,11 +193,14 @@ test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
224
193
  paths: [file]
225
194
  }
226
195
  })
227
- teardown(server.stop)
228
- await server.listen()
196
+
197
+ teardown(async () => {
198
+ await app.close()
199
+ })
200
+ await app.start()
229
201
 
230
202
  {
231
- const res = await request(`${server.url}/`)
203
+ const res = await request(`${app.url}/`)
232
204
  equal(res.statusCode, 200, 'status code')
233
205
  const data = await res.body.json()
234
206
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
@@ -236,19 +208,19 @@ test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
236
208
 
237
209
  await writeFile(file, `
238
210
  export default async function (app) {
239
- app.get('/', () => "hello world" )
211
+ app.get('/', () => "hello world" )
240
212
  }`)
241
213
 
242
- await server.restart()
214
+ await app.restart()
243
215
 
244
216
  {
245
- const res = await request(`${server.url}/`)
217
+ const res = await request(`${app.url}/`)
246
218
  equal(res.statusCode, 200, 'add status code')
247
219
  same(await res.body.text(), 'hello world', 'response')
248
220
  }
249
221
  })
250
222
 
251
- test('server should be available after reload a compromised plugin', async ({ teardown, equal, pass, same }) => {
223
+ test('server should be available after reload a compromised plugin', async ({ teardown, equal, pass, same, rejects }) => {
252
224
  const file = join(os.tmpdir(), `some-plugin-${process.pid}.js`)
253
225
 
254
226
  const workingModule = `
@@ -267,34 +239,35 @@ test('server should be available after reload a compromised plugin', async ({ te
267
239
  paths: [file]
268
240
  }
269
241
  }
270
- const restartConfig = { ...config }
271
- delete restartConfig.server
272
242
 
273
- const server = await buildServer(config)
274
- await server.listen()
243
+ const app = await buildServer(config)
244
+
245
+ teardown(async () => {
246
+ await app.close()
247
+ })
248
+ await app.start()
249
+
275
250
  await writeFile(file, compromisedModule)
276
- await server.restart(restartConfig).catch(() => {
251
+ await app.restart().catch(() => {
277
252
  pass('plugin reload failed')
278
253
  })
279
254
 
280
255
  {
281
- const res = await request(`${server.url}/`, { method: 'GET' })
256
+ const res = await request(`${app.url}/`, { method: 'GET' })
282
257
  equal(res.statusCode, 200, 'status code')
283
258
  const data = await res.body.json()
284
259
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
285
260
  }
286
261
 
287
262
  await writeFile(file, workingModule)
288
- await server.restart(restartConfig)
263
+ await app.restart()
289
264
 
290
265
  {
291
- const res = await request(`${server.url}/`, { method: 'GET' })
266
+ const res = await request(`${app.url}/`, { method: 'GET' })
292
267
  equal(res.statusCode, 200, 'add status code')
293
268
  const data = await res.body.json()
294
269
  same(data, { message: 'Welcome to Platformatic! Please visit https://oss.platformatic.dev' })
295
270
  }
296
-
297
- teardown(server.stop)
298
271
  })
299
272
 
300
273
  test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) => {
@@ -308,7 +281,7 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
308
281
  }`
309
282
  )
310
283
 
311
- const server = await buildServer({
284
+ const app = await buildServer({
312
285
  server: {
313
286
  hostname: '127.0.0.1',
314
287
  port: 0
@@ -318,11 +291,14 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
318
291
  hotReload: false
319
292
  }
320
293
  })
321
- teardown(server.stop)
322
- await server.listen()
294
+
295
+ teardown(async () => {
296
+ await app.close()
297
+ })
298
+ await app.start()
323
299
 
324
300
  {
325
- const res = await request(`${server.url}/test`, {
301
+ const res = await request(`${app.url}/test`, {
326
302
  method: 'GET'
327
303
  })
328
304
  equal(res.statusCode, 200)
@@ -337,10 +313,10 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
337
313
  }`
338
314
  )
339
315
 
340
- await server.restart()
316
+ await app.restart()
341
317
 
342
318
  {
343
- const res = await request(`${server.url}/test`, {
319
+ const res = await request(`${app.url}/test`, {
344
320
  method: 'GET'
345
321
  })
346
322
  equal(res.statusCode, 200)
@@ -350,9 +326,10 @@ test('hot reload disabled, CommonJS', async ({ teardown, equal, pass, same }) =>
350
326
  })
351
327
 
352
328
  test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
353
- 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`)
354
331
 
355
- await writeFile(file, `
332
+ await writeFile(pathToPlugin, `
356
333
  export default async function (app) {
357
334
  app.get('/test', {}, async function (request, response) {
358
335
  return { res: "plugin, version 1"}
@@ -360,31 +337,36 @@ test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
360
337
  }`
361
338
  )
362
339
 
363
- const server = await buildServer({
340
+ const config = {
364
341
  server: {
365
342
  hostname: '127.0.0.1',
366
343
  port: 0
367
344
  },
368
345
  plugins: {
369
- paths: [file],
346
+ paths: [pathToPlugin],
370
347
  stopTimeout: 1000,
371
348
  hotReload: false
372
349
  },
373
350
  watch: true,
374
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()
375
358
  })
376
- teardown(server.stop)
377
- await server.listen()
359
+ await app.start()
378
360
 
379
361
  {
380
- const res = await request(`${server.url}/test`, {
362
+ const res = await request(`${app.url}/test`, {
381
363
  method: 'GET'
382
364
  })
383
365
  equal(res.statusCode, 200)
384
366
  same(await res.body.json(), { res: 'plugin, version 1' }, 'get rest plugin')
385
367
  }
386
368
 
387
- await writeFile(file, `
369
+ await writeFile(pathToPlugin, `
388
370
  export default async function (app) {
389
371
  app.get('/test', {}, async function (request, response) {
390
372
  return { res: "plugin, version 2"}
@@ -392,10 +374,10 @@ test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
392
374
  }`
393
375
  )
394
376
 
395
- await server.restart()
377
+ await app.restart()
396
378
 
397
379
  {
398
- const res = await request(`${server.url}/test`, {
380
+ const res = await request(`${app.url}/test`, {
399
381
  method: 'GET'
400
382
  })
401
383
  equal(res.statusCode, 200)
@@ -405,9 +387,10 @@ test('hot reload disabled, ESM', async ({ teardown, equal, pass, same }) => {
405
387
  })
406
388
 
407
389
  test('hot reload disabled, with default export', async ({ teardown, equal, pass, same }) => {
408
- 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`)
409
392
 
410
- await writeFile(file, `
393
+ await writeFile(pathToPlugin, `
411
394
  Object.defineProperty(exports, "__esModule", { value: true })
412
395
  exports.default = async function plugin (app) {
413
396
  app.get('/test', {}, async function (request, response) {
@@ -415,30 +398,36 @@ test('hot reload disabled, with default export', async ({ teardown, equal, pass,
415
398
  })
416
399
  }`)
417
400
 
418
- const server = await buildServer({
401
+ const config = {
419
402
  server: {
420
403
  hostname: '127.0.0.1',
421
404
  port: 0
422
405
  },
423
406
  plugins: {
424
- paths: [file],
407
+ paths: [pathToPlugin],
425
408
  stopTimeout: 1000,
426
409
  hotReload: false
427
410
  },
428
411
  watch: true,
429
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()
430
420
  })
431
- teardown(server.stop)
432
- await server.listen()
421
+ await app.start()
433
422
 
434
423
  {
435
- const res = await request(`${server.url}/test`, {
424
+ const res = await request(`${app.url}/test`, {
436
425
  method: 'GET'
437
426
  })
438
427
  same(await res.body.json(), { res: 'plugin, version 1' }, 'get rest plugin')
439
428
  }
440
429
 
441
- await writeFile(file, `
430
+ await writeFile(pathToPlugin, `
442
431
  Object.defineProperty(exports, "__esModule", { value: true })
443
432
  exports.default = async function plugin (app) {
444
433
  app.get('/test', {}, async function (request, response) {
@@ -447,10 +436,10 @@ test('hot reload disabled, with default export', async ({ teardown, equal, pass,
447
436
  }`
448
437
  )
449
438
 
450
- await server.restart()
439
+ await app.restart()
451
440
 
452
441
  {
453
- const res = await request(`${server.url}/test`, {
442
+ const res = await request(`${app.url}/test`, {
454
443
  method: 'GET'
455
444
  })
456
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')