@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
@@ -32,23 +32,28 @@ t.test('should compile typescript plugin', async (t) => {
32
32
 
33
33
  await cp(testDir, cwd, { recursive: true })
34
34
 
35
- try {
36
- const child = await execa('node', [cliPath, 'compile'], { cwd })
37
- t.equal(child.stdout.includes('Typescript compilation completed successfully.'), true)
38
- } catch (err) {
39
- console.log(err.stdout)
40
- console.log(err.stderr)
41
- t.fail(err.stderr)
42
- }
35
+ const child = execa('node', [cliPath, 'compile'], { cwd })
43
36
 
44
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
45
- try {
46
- await access(jsPluginPath)
47
- } catch (err) {
48
- t.fail(err)
49
- }
37
+ t.teardown(exitOnTeardown(child))
50
38
 
51
- t.pass()
39
+ const splitter = split()
40
+ child.stdout.pipe(splitter)
41
+
42
+ for await (const data of splitter) {
43
+ const sanitized = stripAnsi(data)
44
+ if (sanitized.includes('Typescript compilation completed successfully.')) {
45
+ const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
46
+ try {
47
+ await access(jsPluginPath)
48
+ } catch (err) {
49
+ t.fail(err)
50
+ }
51
+
52
+ t.pass()
53
+ return
54
+ }
55
+ }
56
+ t.fail('should compile typescript plugin with a compile command')
52
57
  })
53
58
 
54
59
  t.test('should compile typescript plugin even if typescript is `false`', async (t) => {
@@ -57,23 +62,28 @@ t.test('should compile typescript plugin even if typescript is `false`', async (
57
62
 
58
63
  await cp(testDir, cwd, { recursive: true })
59
64
 
60
- try {
61
- const child = await execa('node', [cliPath, 'compile'], { cwd })
62
- t.equal(child.stdout.includes('Typescript compilation completed successfully.'), true)
63
- } catch (err) {
64
- console.log(err.stdout)
65
- console.log(err.stderr)
66
- t.fail(err.stderr)
67
- }
65
+ const child = execa('node', [cliPath, 'compile'], { cwd })
68
66
 
69
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
70
- try {
71
- await access(jsPluginPath)
72
- } catch (err) {
73
- t.fail(err)
74
- }
67
+ t.teardown(exitOnTeardown(child))
75
68
 
76
- t.pass()
69
+ const splitter = split()
70
+ child.stdout.pipe(splitter)
71
+
72
+ for await (const data of splitter) {
73
+ const sanitized = stripAnsi(data)
74
+ if (sanitized.includes('Typescript compilation completed successfully.')) {
75
+ const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
76
+ try {
77
+ await access(jsPluginPath)
78
+ } catch (err) {
79
+ t.fail(err)
80
+ }
81
+
82
+ t.pass()
83
+ return
84
+ }
85
+ }
86
+ t.fail('should compile typescript plugin with a compile command')
77
87
  })
78
88
 
79
89
  t.test('should compile typescript plugin with start command', async (t) => {
@@ -84,8 +94,6 @@ t.test('should compile typescript plugin with start command', async (t) => {
84
94
 
85
95
  const child = execa('node', [cliPath, 'start'], { cwd })
86
96
 
87
- t.teardown(exitOnTeardown(child))
88
-
89
97
  const splitter = split()
90
98
  child.stdout.pipe(splitter)
91
99
 
@@ -156,7 +164,11 @@ t.test('start command should not compile typescript plugin with errors', async (
156
164
  await childProcess
157
165
  t.fail('should not compile bad typescript plugin')
158
166
  } catch (err) {
159
- t.equal(err.stderr.includes('Found 1 error'), true)
167
+ if (!err.stderr.includes('Found 1 error')) {
168
+ t.comment(err.stdout)
169
+ t.comment(err.stderr)
170
+ t.fail('should throw one ts error')
171
+ }
160
172
  childProcess.kill('SIGINT')
161
173
  }
162
174
 
@@ -291,3 +291,42 @@ test('should not hot reload files with `--hot-reload false`', async ({ teardown,
291
291
  equal(version, 'v1')
292
292
  }
293
293
  })
294
+
295
+ test('should not fail when updating wrong config', async ({ equal, teardown, comment }) => {
296
+ const tmpDir = await mkdtemp(join(os.tmpdir(), 'watch-'))
297
+ comment(`using ${tmpDir}`)
298
+ const pluginFilePath = join(tmpDir, 'plugin.js')
299
+ const configFilePath = join(tmpDir, 'platformatic.service.json')
300
+
301
+ const defaultConfig = {
302
+ server: {
303
+ logger: {
304
+ level: 'info'
305
+ },
306
+ hostname: '127.0.0.1',
307
+ port: 0
308
+ },
309
+ plugins: {
310
+ paths: [pluginFilePath]
311
+ },
312
+ watch: false
313
+ }
314
+
315
+ await Promise.all([
316
+ writeFile(configFilePath, JSON.stringify(defaultConfig)),
317
+ writeFile(pluginFilePath, createLoggingPlugin('v1', true))
318
+ ])
319
+
320
+ const { child, url } = await start('-c', configFilePath)
321
+ teardown(() => child.kill('SIGINT'))
322
+
323
+ writeFile(configFilePath, 'this is not a valid config')
324
+
325
+ for await (const log of child.ndj) {
326
+ if (log.msg === 'error reloading the configuration') break
327
+ }
328
+
329
+ const res = await request(`${url}/version`)
330
+ const version = await res.body.text()
331
+ equal(version, 'v1')
332
+ })
@@ -8,30 +8,38 @@ const { request } = require('undici')
8
8
  const { compile } = require('../lib/compile')
9
9
  const { rmdir } = require('fs/promises')
10
10
 
11
- test('client is loaded', async ({ teardown, equal, pass, same, comment }) => {
12
- const server1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
13
- await server1.listen()
11
+ test('client is loaded', async ({ teardown, equal, same }) => {
12
+ const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
14
13
 
15
- process.env.PLT_CLIENT_URL = server1.url
14
+ teardown(async () => {
15
+ await app1.close()
16
+ })
17
+ await app1.start()
16
18
 
17
- const server2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client', 'platformatic.service.json'))
19
+ process.env.PLT_CLIENT_URL = app1.url
20
+
21
+ const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client', 'platformatic.service.json'))
18
22
 
19
23
  teardown(async () => {
20
- await server2.stop()
21
- await server1.stop()
24
+ await app2.close()
22
25
  })
23
- await server2.listen()
24
- const res = await request(`${server2.url}/`)
26
+ await app2.start()
27
+
28
+ const res = await request(`${app2.url}/`)
25
29
  equal(res.statusCode, 200, 'status code')
26
30
  const data = await res.body.json()
27
31
  same(data, { hello: 'world' })
28
32
  })
29
33
 
30
34
  test('client is loaded (ts)', async ({ teardown, equal, pass, same }) => {
31
- const server1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
32
- await server1.listen()
35
+ const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
36
+
37
+ teardown(async () => {
38
+ await app1.close()
39
+ })
40
+ await app1.start()
33
41
 
34
- process.env.PLT_CLIENT_URL = server1.url
42
+ process.env.PLT_CLIENT_URL = app1.url
35
43
 
36
44
  const targetDir = join(__dirname, '..', 'fixtures', 'hello-client-ts')
37
45
 
@@ -41,14 +49,13 @@ test('client is loaded (ts)', async ({ teardown, equal, pass, same }) => {
41
49
 
42
50
  await compile(targetDir, { server: { logger: { level: 'warn' } } })
43
51
 
44
- const server2 = await buildServer(join(targetDir, 'platformatic.service.json'))
52
+ const app2 = await buildServer(join(targetDir, 'platformatic.service.json'))
45
53
  teardown(async () => {
46
- await server2.stop()
47
- await server1.stop()
54
+ await app2.close()
48
55
  })
49
- await server2.listen()
56
+ await app2.start()
50
57
 
51
- const res = await request(`${server2.url}/`)
58
+ const res = await request(`${app2.url}/`)
52
59
  equal(res.statusCode, 200, 'status code')
53
60
  const data = await res.body.json()
54
61
  same(data, { hello: 'world' })
@@ -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 server = await buildServer({
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
- teardown(server.stop)
35
- await server.listen()
35
+
36
+ teardown(async () => {
37
+ await app.close()
38
+ })
39
+ await app.start()
36
40
 
37
41
  {
38
- const res = await request(`${server.url}/`)
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 server.app.platformatic.configManager.update({
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 server.restart()
63
+ await app.restart()
60
64
 
61
65
  {
62
- const res = await request(`${server.url}/`)
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 server = await buildServer(config)
94
- teardown(server.stop)
95
- await server.listen()
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(`${server.url}/`)
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 server.app.platformatic.configManager.update({
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 server.restart()
126
+ await app.restart()
120
127
 
121
128
  {
122
- const res = await request(`${server.url}/`)
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 server = await buildServer(config)
177
- teardown(server.stop)
178
- await server.listen()
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(`${server.url}/`)
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(`${server.url}/restart`, {
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(`${server.url}/`)
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 server = await buildServer({
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
- teardown(server.stop)
253
- await server.listen()
262
+
263
+ teardown(async () => {
264
+ await app.close()
265
+ })
266
+ await app.start()
254
267
 
255
268
  {
256
- const res = await request(`${server.url}/`)
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 server.app.platformatic.configManager.update({
274
+ await app.platformatic.configManager.update({
262
275
  server: {
263
276
  hostname: '127.0.0.1',
264
277
  port: 0
@@ -274,79 +287,38 @@ test('config reloads', async ({ teardown, equal, pass, same }) => {
274
287
  metrics: false
275
288
  })
276
289
 
277
- await server.restart()
290
+ await app.restart()
278
291
 
279
292
  {
280
- const res = await request(`${server.url}/`)
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
  })
285
298
 
286
- test('restart throws if config is invalid', async ({ teardown, rejects }) => {
287
- const server = await buildServer({
288
- server: {
289
- hostname: '127.0.0.1',
290
- port: 0
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'
291
307
  }
292
- })
293
- teardown(server.stop)
294
- await server.listen()
295
-
296
- await rejects(server.restart({ foo: 'bar' }))
297
- })
298
-
299
- test('config reloads by calling restart', async ({ teardown, equal, pass, same }) => {
300
- const file = join(os.tmpdir(), `${process.pid}-1.js`)
301
-
302
- await writeFile(file, `
303
- module.exports = async function (app, options) {
304
- app.get('/', () => options.message)
305
- }`)
306
-
307
- const server = await buildServer({
308
- server: {
309
- hostname: '127.0.0.1',
310
- port: 0
311
- },
312
- plugins: {
313
- paths: [{
314
- path: file,
315
- options: {
316
- message: 'hello'
317
- }
318
- }]
319
- },
320
- metrics: false
321
- })
322
- teardown(server.stop)
323
- await server.listen()
308
+ }
324
309
 
325
310
  {
326
- const res = await request(`${server.url}/`)
327
- equal(res.statusCode, 200, 'add status code')
328
- same(await res.body.text(), 'hello', 'response')
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)
329
315
  }
330
316
 
331
- await server.restart({
332
- server: {
333
- hostname: '127.0.0.1',
334
- port: 0
335
- },
336
- plugins: {
337
- paths: [{
338
- path: file,
339
- options: {
340
- message: 'ciao mondo'
341
- }
342
- }]
343
- },
344
- metrics: false
345
- })
346
-
347
317
  {
348
- const res = await request(`${server.url}/`)
349
- equal(res.statusCode, 200, 'add status code')
350
- same(await res.body.text(), 'ciao mondo', 'response')
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)
351
323
  }
352
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 server = await buildServer({
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(server.stop)
22
- await server.listen()
23
- const res = await (request(`${server.url}/login`, {
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 server = await buildServer({
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
- teardown(server.stop)
49
- await server.listen()
51
+
52
+ teardown(async () => {
53
+ await app.close()
54
+ })
55
+ await app.start()
50
56
 
51
57
  {
52
- const res = await (request(`${server.url}/_admin/login`, {
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 server = await buildServer({
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
- teardown(server.stop)
83
- await server.listen()
88
+
89
+ teardown(async () => {
90
+ await app.close()
91
+ })
92
+ await app.start()
84
93
 
85
94
  {
86
- const res = await (request(`${server.url}/_admin/login`, {
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(`${server.url}/_admin/login`, {
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(`${server.url}/_admin/login`, {
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 server = await buildServer({
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
- teardown(server.stop)
141
- await server.listen()
149
+
150
+ teardown(async () => {
151
+ await app.close()
152
+ })
153
+ await app.start()
142
154
 
143
155
  {
144
- const res = await (request(`${server.url}/_admin/login`, {
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(`${server.url}/_admin/login`, {
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(`${server.url}/_admin/login`, {
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 server = await buildServer({
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
- teardown(server.stop)
201
- await server.listen()
212
+
213
+ teardown(async () => {
214
+ await app.close()
215
+ })
216
+ await app.start()
202
217
 
203
218
  {
204
- const res = await (request(`${server.url}/_admin/login`, {
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(`${server.url}/_admin/login`, {
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(`${server.url}/_admin/login`, {
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 server = await buildServer({
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
- teardown(server.stop)
259
- await server.listen()
273
+
274
+ teardown(async () => {
275
+ await app.close()
276
+ })
277
+ await app.start()
260
278
 
261
279
  {
262
- const res = await (request(`${server.url}/_admin/login`, {
280
+ const res = await (request(`${app.url}/_admin/login`, {
263
281
  method: 'OPTIONS',
264
282
  headers: {
265
283
  'Access-Control-Request-Method': 'POST',