@platformatic/basic 2.0.0-alpha.3

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 (47) hide show
  1. package/LICENSE +201 -0
  2. package/eslint.config.js +3 -0
  3. package/index.js +105 -0
  4. package/lib/base.js +82 -0
  5. package/lib/schema.js +30 -0
  6. package/lib/server.js +135 -0
  7. package/lib/utils.js +77 -0
  8. package/package.json +41 -0
  9. package/test/express.test.js +34 -0
  10. package/test/fastify.test.js +34 -0
  11. package/test/fixtures/express/no-build/index.js +16 -0
  12. package/test/fixtures/express/no-build/package.json +7 -0
  13. package/test/fixtures/express/no-build/platformatic.app.json +3 -0
  14. package/test/fixtures/express/no-build/platformatic.as-entrypoint.runtime.json +19 -0
  15. package/test/fixtures/express/no-build/platformatic.no-entrypoint.runtime.json +16 -0
  16. package/test/fixtures/express/with-build/index.js +17 -0
  17. package/test/fixtures/express/with-build/package.json +7 -0
  18. package/test/fixtures/express/with-build/platformatic.app.json +3 -0
  19. package/test/fixtures/express/with-build/platformatic.as-entrypoint.runtime.json +19 -0
  20. package/test/fixtures/express/with-build/platformatic.no-entrypoint.runtime.json +16 -0
  21. package/test/fixtures/fastify/no-build/index.js +14 -0
  22. package/test/fixtures/fastify/no-build/package.json +7 -0
  23. package/test/fixtures/fastify/no-build/platformatic.app.json +3 -0
  24. package/test/fixtures/fastify/no-build/platformatic.as-entrypoint.runtime.json +19 -0
  25. package/test/fixtures/fastify/no-build/platformatic.no-entrypoint.runtime.json +16 -0
  26. package/test/fixtures/fastify/with-build/index.js +15 -0
  27. package/test/fixtures/fastify/with-build/package.json +7 -0
  28. package/test/fixtures/fastify/with-build/platformatic.app.json +3 -0
  29. package/test/fixtures/fastify/with-build/platformatic.as-entrypoint.runtime.json +19 -0
  30. package/test/fixtures/fastify/with-build/platformatic.no-entrypoint.runtime.json +16 -0
  31. package/test/fixtures/nodejs/no-build/index.js +21 -0
  32. package/test/fixtures/nodejs/no-build/package.json +7 -0
  33. package/test/fixtures/nodejs/no-build/platformatic.app.json +3 -0
  34. package/test/fixtures/nodejs/no-build/platformatic.as-entrypoint.runtime.json +19 -0
  35. package/test/fixtures/nodejs/no-build/platformatic.no-entrypoint.runtime.json +16 -0
  36. package/test/fixtures/nodejs/no-configuration/index.js +21 -0
  37. package/test/fixtures/nodejs/no-configuration/platformatic.as-entrypoint.runtime.json +18 -0
  38. package/test/fixtures/nodejs/no-configuration/platformatic.no-entrypoint.runtime.json +16 -0
  39. package/test/fixtures/nodejs/with-build/index.js +20 -0
  40. package/test/fixtures/nodejs/with-build/package.json +7 -0
  41. package/test/fixtures/nodejs/with-build/platformatic.app.json +3 -0
  42. package/test/fixtures/nodejs/with-build/platformatic.as-entrypoint.runtime.json +19 -0
  43. package/test/fixtures/nodejs/with-build/platformatic.no-entrypoint.runtime.json +16 -0
  44. package/test/fixtures/platformatic-service/platformatic.service.json +15 -0
  45. package/test/fixtures/platformatic-service/plugin.js +12 -0
  46. package/test/helper.js +65 -0
  47. package/test/node.test.js +66 -0
@@ -0,0 +1,34 @@
1
+ import { ifError } from 'node:assert'
2
+ import { test } from 'node:test'
3
+ import { createRuntime, verifyViaHTTP, verifyViaInject } from './helper.js'
4
+
5
+ test('can detect and start an express application with no build function defined', async t => {
6
+ const { runtime, url } = await createRuntime(t, 'express/no-build/platformatic.as-entrypoint.runtime.json')
7
+
8
+ await verifyViaHTTP(url, '/direct', 200, { ok: true })
9
+ await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
10
+ })
11
+
12
+ test('can detect and start an express application with no build function and when not the entrypoint', async t => {
13
+ const { runtime, url } = await createRuntime(t, 'express/no-build/platformatic.no-entrypoint.runtime.json')
14
+
15
+ await verifyViaHTTP(url, '/mesh', 200, { ok: true })
16
+ await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
17
+ })
18
+
19
+ test('can detect and start an express application with build function defined', async t => {
20
+ const { runtime, url } = await createRuntime(t, 'express/with-build/platformatic.as-entrypoint.runtime.json')
21
+
22
+ await verifyViaHTTP(url, '/direct', 200, { ok: true })
23
+ await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
24
+ })
25
+
26
+ test('can detect and start an express applicationwith build function defined and when not the entrypoint', async t => {
27
+ const { runtime, url } = await createRuntime(t, 'express/no-build/platformatic.no-entrypoint.runtime.json')
28
+
29
+ await verifyViaHTTP(url, '/mesh', 200, { ok: true })
30
+ await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
31
+
32
+ const details = await runtime.getServiceDetails('internal')
33
+ ifError(details.url)
34
+ })
@@ -0,0 +1,34 @@
1
+ import { ifError } from 'node:assert'
2
+ import { test } from 'node:test'
3
+ import { createRuntime, verifyViaHTTP, verifyViaInject } from './helper.js'
4
+
5
+ test('can detect and start a fastify application with no build function defined', async t => {
6
+ const { runtime, url } = await createRuntime(t, 'fastify/no-build/platformatic.as-entrypoint.runtime.json')
7
+
8
+ await verifyViaHTTP(url, '/direct', 200, { ok: true })
9
+ await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
10
+ })
11
+
12
+ test('can detect and start a fastify application with no build function and when not the entrypoint', async t => {
13
+ const { runtime, url } = await createRuntime(t, 'fastify/no-build/platformatic.no-entrypoint.runtime.json')
14
+
15
+ await verifyViaHTTP(url, '/mesh', 200, { ok: true })
16
+ await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
17
+ })
18
+
19
+ test('can detect and start a fastify application with build function defined', async t => {
20
+ const { runtime, url } = await createRuntime(t, 'fastify/with-build/platformatic.as-entrypoint.runtime.json')
21
+
22
+ await verifyViaHTTP(url, '/direct', 200, { ok: true })
23
+ await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
24
+ })
25
+
26
+ test('can detect and start a fastify application with build function defined and when not the entrypoint', async t => {
27
+ const { runtime, url } = await createRuntime(t, 'fastify/no-build/platformatic.no-entrypoint.runtime.json')
28
+
29
+ await verifyViaHTTP(url, '/mesh', 200, { ok: true })
30
+ await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
31
+
32
+ const details = await runtime.getServiceDetails('internal')
33
+ ifError(details.url)
34
+ })
@@ -0,0 +1,16 @@
1
+ import express from 'express'
2
+
3
+ const app = express()
4
+
5
+ app.get('/direct', (req, res) => {
6
+ res.send({ ok: true })
7
+ })
8
+
9
+ app.get('/internal', (req, res) => {
10
+ fetch('http://main.plt.local/direct')
11
+ .then(response => response.json())
12
+ .then(res.json.bind(res))
13
+ })
14
+
15
+ // This would likely fail if our code doesn't work
16
+ app.listen(1)
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "index.js",
3
+ "type": "module",
4
+ "dependencies": {
5
+ "express": "^4.19.2"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": ".",
16
+ "config": "platformatic.app.json"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
+ ]
16
+ }
@@ -0,0 +1,17 @@
1
+ import express from 'express'
2
+
3
+ export function build () {
4
+ const app = express()
5
+
6
+ app.get('/direct', (req, res) => {
7
+ res.send({ ok: true })
8
+ })
9
+
10
+ app.get('/internal', (req, res) => {
11
+ fetch('http://main.plt.local/direct')
12
+ .then(response => response.json())
13
+ .then(res.json.bind(res))
14
+ })
15
+
16
+ return app
17
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "index.js",
3
+ "type": "module",
4
+ "dependencies": {
5
+ "express": "^4.19.2"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": ".",
16
+ "config": "platformatic.app.json"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
+ ]
16
+ }
@@ -0,0 +1,14 @@
1
+ import fastify from 'fastify'
2
+
3
+ const app = fastify()
4
+
5
+ app.get('/direct', async () => {
6
+ return { ok: true }
7
+ })
8
+
9
+ app.get('/internal', () => {
10
+ return fetch('http://main.plt.local/direct').then(response => response.json())
11
+ })
12
+
13
+ // This would likely fail if our code doesn't work
14
+ app.listen({ port: 1 })
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "index.js",
3
+ "type": "module",
4
+ "dependencies": {
5
+ "fastify": "^4.28.1"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": ".",
16
+ "config": "platformatic.app.json"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
+ ]
16
+ }
@@ -0,0 +1,15 @@
1
+ import fastify from 'fastify'
2
+
3
+ export function build () {
4
+ const app = fastify()
5
+
6
+ app.get('/direct', async () => {
7
+ return { ok: true }
8
+ })
9
+
10
+ app.get('/internal', () => {
11
+ return fetch('http://main.plt.local/direct').then(response => response.json())
12
+ })
13
+
14
+ return app
15
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "index.js",
3
+ "type": "module",
4
+ "dependencies": {
5
+ "fastify": "^4.28.1"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": ".",
16
+ "config": "platformatic.app.json"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": false,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "error"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
+ ]
16
+ }
@@ -0,0 +1,21 @@
1
+ import { createServer } from 'node:http'
2
+
3
+ const server = createServer((req, res) => {
4
+ if (req.url === '/direct') {
5
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
6
+ res.end(JSON.stringify({ ok: true }))
7
+ } else if (req.url === '/mesh') {
8
+ fetch('http://main.plt.local/direct')
9
+ .then(response => response.json())
10
+ .then(json => {
11
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
12
+ res.end(JSON.stringify({ ok: true }))
13
+ })
14
+ } else {
15
+ res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
16
+ res.end(JSON.stringify({ ok: false }))
17
+ }
18
+ })
19
+
20
+ // This would likely fail if our code doesn't work
21
+ server.listen(1)
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "index.js",
3
+ "type": "module",
4
+ "dependencies": {
5
+ "express": "^4.19.2"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": true,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "warn"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": ".",
16
+ "config": "platformatic.app.json"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": true,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "warn"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
+ ]
16
+ }
@@ -0,0 +1,21 @@
1
+ import { createServer } from 'node:http'
2
+
3
+ const server = createServer((req, res) => {
4
+ if (req.url === '/direct') {
5
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
6
+ res.end(JSON.stringify({ ok: true }))
7
+ } else if (req.url === '/mesh') {
8
+ fetch('http://main.plt.local/direct')
9
+ .then(response => response.json())
10
+ .then(json => {
11
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
12
+ res.end(JSON.stringify({ ok: true }))
13
+ })
14
+ } else {
15
+ res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
16
+ res.end(JSON.stringify({ ok: false }))
17
+ }
18
+ })
19
+
20
+ // This would likely fail if our code doesn't work
21
+ server.listen(1)
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": true,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "warn"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": "."
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": true,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "warn"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": "." }
15
+ ]
16
+ }
@@ -0,0 +1,20 @@
1
+ import { createServer } from 'node:http'
2
+
3
+ export function build () {
4
+ return createServer((req, res) => {
5
+ if (req.url === '/direct') {
6
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
7
+ res.end(JSON.stringify({ ok: true }))
8
+ } else if (req.url === '/mesh') {
9
+ fetch('http://main.plt.local/direct')
10
+ .then(response => response.json())
11
+ .then(json => {
12
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
13
+ res.end(JSON.stringify({ ok: true }))
14
+ })
15
+ } else {
16
+ res.writeHead(404, { 'content-type': 'application/json', connection: 'close' })
17
+ res.end(JSON.stringify({ ok: false }))
18
+ }
19
+ })
20
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "main": "index.js",
3
+ "type": "module",
4
+ "dependencies": {
5
+ "express": "^4.19.2"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": true,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "warn"
10
+ }
11
+ },
12
+ "services": [
13
+ {
14
+ "id": "main",
15
+ "path": ".",
16
+ "config": "platformatic.app.json"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
+ "entrypoint": "main",
4
+ "watch": false,
5
+ "managementApi": true,
6
+ "metrics": false,
7
+ "server": {
8
+ "logger": {
9
+ "level": "warn"
10
+ }
11
+ },
12
+ "services": [
13
+ { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
+ { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
+ ]
16
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "plugins": {
9
+ "paths": [
10
+ {
11
+ "path": "./plugin.js"
12
+ }
13
+ ]
14
+ }
15
+ }
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ export default async function (app) {
4
+ app.get('/mesh', async () => {
5
+ const response = await fetch('http://internal.plt.local/direct')
6
+ return response.json()
7
+ })
8
+
9
+ app.get('/direct', async () => {
10
+ return { ok: true }
11
+ })
12
+ }
package/test/helper.js ADDED
@@ -0,0 +1,65 @@
1
+ import { deepStrictEqual, strictEqual } from 'node:assert'
2
+ import { resolve } from 'node:path'
3
+ import { setTimeout as sleep } from 'node:timers/promises'
4
+ import { Client, request } from 'undici'
5
+ import { loadConfig } from '../../config/index.js'
6
+ import { buildServer, platformaticRuntime } from '../../runtime/index.js'
7
+
8
+ export const fixturesDir = resolve(import.meta.dirname, './fixtures')
9
+
10
+ export async function createRuntime (t, path) {
11
+ const configFile = resolve(fixturesDir, path)
12
+ const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
13
+ const runtime = await buildServer(config.configManager.current)
14
+ const url = await runtime.start()
15
+
16
+ t.after(async () => {
17
+ await runtime.close()
18
+ })
19
+
20
+ return { runtime, url }
21
+ }
22
+
23
+ export async function verifyViaHTTP (baseUrl, path, expectedCode, expectedContent) {
24
+ const { statusCode, body } = await request(baseUrl + path)
25
+ strictEqual(statusCode, expectedCode)
26
+ deepStrictEqual(await body.json(), expectedContent)
27
+ }
28
+
29
+ export async function verifyViaInject (app, serviceId, method, url, expectedCode, expectedContent) {
30
+ const { statusCode, body } = await app.inject(serviceId, { method, url })
31
+ strictEqual(statusCode, expectedCode)
32
+ deepStrictEqual(JSON.parse(body), expectedContent)
33
+ }
34
+
35
+ export async function getLogs (app) {
36
+ const client = new Client(
37
+ {
38
+ hostname: 'localhost',
39
+ protocol: 'http:',
40
+ },
41
+ {
42
+ socketPath: app.getManagementApiUrl(),
43
+ keepAliveTimeout: 10,
44
+ keepAliveMaxTimeout: 10,
45
+ }
46
+ )
47
+
48
+ // Wait for logs to be written
49
+ await sleep(3000)
50
+
51
+ const { statusCode, body } = await client.request({
52
+ method: 'GET',
53
+ path: '/api/v1/logs/all',
54
+ })
55
+
56
+ strictEqual(statusCode, 200)
57
+
58
+ const rawLogs = await body.text()
59
+
60
+ return rawLogs
61
+ .trim()
62
+ .split('\n')
63
+ .filter(l => l)
64
+ .map(m => JSON.parse(m))
65
+ }