@platformatic/service 0.45.1 → 0.46.2

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 (120) hide show
  1. package/index.js +2 -2
  2. package/package.json +6 -6
  3. package/fixtures/hello/no-server-logger.json +0 -13
  4. package/fixtures/hello/platformatic.service.json +0 -18
  5. package/fixtures/hello/plugin.js +0 -7
  6. package/fixtures/hello/warn-log.service.json +0 -18
  7. package/fixtures/hello-client/hello/hello.cjs +0 -21
  8. package/fixtures/hello-client/hello/hello.d.ts +0 -34
  9. package/fixtures/hello-client/hello/hello.openapi.json +0 -22
  10. package/fixtures/hello-client/hello/package.json +0 -5
  11. package/fixtures/hello-client/platformatic.service.json +0 -19
  12. package/fixtures/hello-client/plugin.js +0 -8
  13. package/fixtures/hello-client-ts/hello/hello.cjs +0 -21
  14. package/fixtures/hello-client-ts/hello/hello.d.ts +0 -34
  15. package/fixtures/hello-client-ts/hello/hello.openapi.json +0 -22
  16. package/fixtures/hello-client-ts/hello/package.json +0 -5
  17. package/fixtures/hello-client-ts/platformatic.service.json +0 -21
  18. package/fixtures/hello-client-ts/plugin.ts +0 -8
  19. package/fixtures/hello-client-ts/tsconfig.json +0 -23
  20. package/fixtures/hello-client-ts-without-deps/hello.d.ts +0 -34
  21. package/fixtures/hello-client-ts-without-deps/hello.openapi.json +0 -22
  22. package/fixtures/hello-client-ts-without-deps/platformatic.service.json +0 -23
  23. package/fixtures/hello-client-ts-without-deps/plugin.ts +0 -8
  24. package/fixtures/hello-client-ts-without-deps/tsconfig.json +0 -22
  25. package/fixtures/hello-client-without-deps/hello.d.ts +0 -34
  26. package/fixtures/hello-client-without-deps/hello.openapi.json +0 -22
  27. package/fixtures/hello-client-without-deps/platformatic.service.json +0 -21
  28. package/fixtures/hello-client-without-deps/plugin.js +0 -8
  29. package/fixtures/https/embedded-pem.json +0 -20
  30. package/fixtures/https/https.crt +0 -25
  31. package/fixtures/https/https.key +0 -27
  32. package/fixtures/https/pem-path.json +0 -20
  33. package/fixtures/https/plugin.js +0 -7
  34. package/fixtures/options/platformatic.service.yml +0 -9
  35. package/fixtures/options/plugin.js +0 -7
  36. package/test/autoload.test.js +0 -486
  37. package/test/cli/compile-1.test.mjs +0 -532
  38. package/test/cli/compile-2.test.mjs +0 -310
  39. package/test/cli/gen-schema.test.mjs +0 -44
  40. package/test/cli/gen-types.test.mjs +0 -30
  41. package/test/cli/helper.mjs +0 -67
  42. package/test/cli/start.test.mjs +0 -126
  43. package/test/cli/tap-parallel-not-ok +0 -0
  44. package/test/cli/validations.test.mjs +0 -33
  45. package/test/clients.test.js +0 -87
  46. package/test/config.test.js +0 -316
  47. package/test/cors.test.js +0 -291
  48. package/test/fixtures/bad-typescript-plugin/platformatic.service.json +0 -16
  49. package/test/fixtures/bad-typescript-plugin/plugin.ts +0 -5
  50. package/test/fixtures/bad-typescript-plugin/tsconfig.json +0 -22
  51. package/test/fixtures/custom-port-placeholder.json +0 -10
  52. package/test/fixtures/default-env-var-names.json +0 -7
  53. package/test/fixtures/directories/platformatic.service.json +0 -13
  54. package/test/fixtures/directories/plugins/decorator.js +0 -7
  55. package/test/fixtures/directories/routes/foo/bar.js +0 -11
  56. package/test/fixtures/directories/routes/foo/baz/index.js +0 -7
  57. package/test/fixtures/directories/routes/foo/baz/index2.js +0 -11
  58. package/test/fixtures/directories/routes/oof/auto.hooks.js +0 -5
  59. package/test/fixtures/directories/routes/oof/index.js +0 -7
  60. package/test/fixtures/directories/routes/root.js +0 -7
  61. package/test/fixtures/hello-ts-with-config/global.d.ts +0 -8
  62. package/test/fixtures/hello-ts-with-config/platformatic.service.json +0 -16
  63. package/test/fixtures/hello-ts-with-config/plugin.ts +0 -8
  64. package/test/fixtures/hello-ts-with-config/tsconfig.json +0 -23
  65. package/test/fixtures/hello-world-resolver.js +0 -16
  66. package/test/fixtures/missing-property.config.json +0 -1
  67. package/test/fixtures/nested-directories/modules/catalogue/index.js +0 -11
  68. package/test/fixtures/nested-directories/modules/catalogue/routes/products.js +0 -14
  69. package/test/fixtures/nested-directories/modules/inventory/index.js +0 -33
  70. package/test/fixtures/nested-directories/modules/inventory/routes/product.js +0 -15
  71. package/test/fixtures/nested-directories/package.json +0 -3
  72. package/test/fixtures/nested-directories/platformatic.service.json +0 -23
  73. package/test/fixtures/nested-directories/plugins/decorator.js +0 -3
  74. package/test/fixtures/nested-directories/plugins/handlers.js +0 -17
  75. package/test/fixtures/not-load.js +0 -8
  76. package/test/fixtures/not-load.service.json +0 -13
  77. package/test/fixtures/other-side.js +0 -9
  78. package/test/fixtures/request-id.js +0 -9
  79. package/test/fixtures/root-endpoint-plugin.js +0 -8
  80. package/test/fixtures/throw-resolver.js +0 -16
  81. package/test/fixtures/typescript-autoload/platformatic.service.json +0 -16
  82. package/test/fixtures/typescript-autoload/routes/plugin.ts +0 -5
  83. package/test/fixtures/typescript-autoload/tsconfig.json +0 -22
  84. package/test/fixtures/typescript-compiled/compiled/plugin.js +0 -6
  85. package/test/fixtures/typescript-compiled/platformatic.service.json +0 -18
  86. package/test/fixtures/typescript-plugin/platformatic.service.json +0 -16
  87. package/test/fixtures/typescript-plugin/plugin.ts +0 -5
  88. package/test/fixtures/typescript-plugin/tsconfig.json +0 -22
  89. package/test/fixtures/typescript-plugin-custom-flags/platformatic.service.json +0 -18
  90. package/test/fixtures/typescript-plugin-custom-flags/plugin.ts +0 -5
  91. package/test/fixtures/typescript-plugin-custom-flags/tsconfig.json +0 -22
  92. package/test/fixtures/typescript-plugin-custom-tsconfig/a-config-for-ts.json +0 -22
  93. package/test/fixtures/typescript-plugin-custom-tsconfig/platformatic.service.json +0 -18
  94. package/test/fixtures/typescript-plugin-custom-tsconfig/plugin.ts +0 -5
  95. package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +0 -16
  96. package/test/fixtures/typescript-plugin-nocompile/plugin.ts +0 -5
  97. package/test/fixtures/typescript-plugin-nocompile/tsconfig.json +0 -22
  98. package/test/fixtures/typescript-plugin-nocompile-enabled/platformatic.service.json +0 -18
  99. package/test/fixtures/typescript-plugin-nocompile-enabled/plugin.ts +0 -5
  100. package/test/fixtures/typescript-plugin-nocompile-enabled/tsconfig.json +0 -22
  101. package/test/fixtures/typescript-plugin-nocompile-string/platformatic.service.json +0 -16
  102. package/test/fixtures/typescript-plugin-nocompile-string/plugin.ts +0 -5
  103. package/test/fixtures/typescript-plugin-nocompile-string/tsconfig.json +0 -22
  104. package/test/fixtures/typescript-plugin-string/platformatic.service.json +0 -16
  105. package/test/fixtures/typescript-plugin-string/plugin.ts +0 -5
  106. package/test/fixtures/typescript-plugin-string/tsconfig.json +0 -22
  107. package/test/fixtures/undici-plugin.js +0 -15
  108. package/test/graphql.test.js +0 -219
  109. package/test/healthcheck.test.js +0 -92
  110. package/test/helper.js +0 -30
  111. package/test/https.test.js +0 -64
  112. package/test/lambda.test.js +0 -103
  113. package/test/load-and-reload-files.test.js +0 -180
  114. package/test/load-plugin.test.js +0 -67
  115. package/test/metrics.test.js +0 -220
  116. package/test/routes.test.js +0 -230
  117. package/test/schema.test.js +0 -12
  118. package/test/tap-parallel-ok +0 -0
  119. package/test/telemetry.test.js +0 -87
  120. package/test/utils.test.js +0 -37
@@ -1,180 +0,0 @@
1
- 'use strict'
2
-
3
- require('./helper')
4
- const { test } = require('tap')
5
- const { buildServer } = require('..')
6
- const { request, setGlobalDispatcher, getGlobalDispatcher, MockAgent } = require('undici')
7
- const { randomUUID } = require('crypto')
8
- const { join } = require('path')
9
- const os = require('os')
10
- const { writeFile } = require('fs/promises')
11
-
12
- test('load and reload', async ({ teardown, equal, pass, same }) => {
13
- const file = join(os.tmpdir(), `some-plugin-${randomUUID()}.js`)
14
-
15
- await writeFile(file, `
16
- module.exports = async function (app) {
17
- }`
18
- )
19
-
20
- const app = await buildServer({
21
- server: {
22
- hostname: '127.0.0.1',
23
- port: 0
24
- },
25
- plugins: {
26
- paths: [file]
27
- },
28
- watch: false,
29
- metrics: false
30
- })
31
-
32
- teardown(async () => {
33
- await app.close()
34
- })
35
- await app.start()
36
-
37
- {
38
- const res = await request(`${app.url}/`)
39
- equal(res.statusCode, 200, 'status code')
40
- const data = await res.body.json()
41
- same(data, { message: 'Welcome to Platformatic! Please visit https://docs.platformatic.dev' })
42
- }
43
-
44
- await writeFile(file, `
45
- module.exports = async function (app) {
46
- app.get('/', () => "hello world" )
47
- }`)
48
-
49
- await app.restart()
50
-
51
- {
52
- const res = await request(`${app.url}/`)
53
- equal(res.statusCode, 200, 'add status code')
54
- // The plugin is in Node's module cache, so the new value is not seen.
55
- same(await res.body.json(), { message: 'Welcome to Platformatic! Please visit https://docs.platformatic.dev' })
56
- }
57
- })
58
-
59
- test('error', async ({ teardown, equal, pass, match }) => {
60
- const file = join(os.tmpdir(), `some-plugin-${randomUUID()}.js`)
61
-
62
- await writeFile(file, `
63
- module.exports = async function (app) {
64
- app.get('/', () => {
65
- throw new Error('kaboom')
66
- })
67
- }`)
68
-
69
- const app = await buildServer({
70
- server: {
71
- hostname: '127.0.0.1',
72
- port: 0
73
- },
74
- plugins: {
75
- paths: [file]
76
- },
77
- watch: false,
78
- metrics: false
79
- })
80
-
81
- teardown(async () => {
82
- await app.close()
83
- })
84
- await app.start()
85
-
86
- const res = await request(`${app.url}/`)
87
- equal(res.statusCode, 500, 'add status code')
88
- match(await res.body.json(), {
89
- message: 'kaboom'
90
- })
91
- })
92
-
93
- test('mock undici is supported', async ({ teardown, equal, pass, same }) => {
94
- const previousAgent = getGlobalDispatcher()
95
- teardown(() => setGlobalDispatcher(previousAgent))
96
-
97
- const mockAgent = new MockAgent({
98
- keepAliveTimeout: 10,
99
- keepAliveMaxTimeout: 10
100
- })
101
- setGlobalDispatcher(mockAgent)
102
-
103
- const mockPool = mockAgent.get('http://localhost:42')
104
-
105
- // intercept the request
106
- mockPool.intercept({
107
- path: '/',
108
- method: 'GET'
109
- }).reply(200, {
110
- hello: 'world'
111
- })
112
-
113
- const app = await buildServer({
114
- server: {
115
- hostname: '127.0.0.1',
116
- port: 0
117
- },
118
- plugins: {
119
- paths: [join(__dirname, 'fixtures', 'undici-plugin.js')]
120
- }
121
- })
122
-
123
- teardown(async () => {
124
- await app.close()
125
- })
126
- await app.start()
127
-
128
- const res = await request(`${app.url}/request`, {
129
- method: 'GET'
130
- })
131
- equal(res.statusCode, 200)
132
- same(await res.body.json(), {
133
- hello: 'world'
134
- })
135
- })
136
-
137
- test('load and reload ESM', async ({ teardown, equal, pass, same }) => {
138
- const file = join(os.tmpdir(), `some-plugin-${process.pid}.mjs`)
139
-
140
- await writeFile(file, `
141
- export default async function (app) {
142
- }`
143
- )
144
-
145
- const app = await buildServer({
146
- server: {
147
- hostname: '127.0.0.1',
148
- port: 0
149
- },
150
- plugins: {
151
- paths: [file]
152
- }
153
- })
154
-
155
- teardown(async () => {
156
- await app.close()
157
- })
158
- await app.start()
159
-
160
- {
161
- const res = await request(`${app.url}/`)
162
- equal(res.statusCode, 200, 'status code')
163
- const data = await res.body.json()
164
- same(data, { message: 'Welcome to Platformatic! Please visit https://docs.platformatic.dev' })
165
- }
166
-
167
- await writeFile(file, `
168
- export default async function (app) {
169
- app.get('/', () => "hello world" )
170
- }`)
171
-
172
- await app.restart()
173
-
174
- {
175
- const res = await request(`${app.url}/`)
176
- equal(res.statusCode, 200, 'add status code')
177
- // The plugin is in Node's module cache, so the new value is not seen.
178
- same(await res.body.json(), { message: 'Welcome to Platformatic! Please visit https://docs.platformatic.dev' })
179
- }
180
- })
@@ -1,67 +0,0 @@
1
- 'use strict'
2
-
3
- // setup the undici agent
4
- require('./helper')
5
-
6
- const { test } = require('tap')
7
- const { buildServer, platformaticService } = require('..')
8
- const { request } = require('undici')
9
-
10
- test('customize service', async ({ teardown, equal }) => {
11
- async function myApp (app, opts) {
12
- await platformaticService(app, opts, [async function (app) {
13
- app.get('/', () => 'hello world')
14
- }])
15
- }
16
-
17
- const app = await buildServer({
18
- server: {
19
- hostname: '127.0.0.1',
20
- port: 0
21
- }
22
- }, myApp)
23
-
24
- teardown(async () => {
25
- await app.close()
26
- })
27
- await app.start()
28
-
29
- const res = await (request(app.url))
30
- const body = await res.body.text()
31
- equal(res.statusCode, 200)
32
- equal(body, 'hello world')
33
- })
34
-
35
- test('catch errors from the other side', async ({ teardown, equal, same }) => {
36
- async function myApp (app, opts) {
37
- await platformaticService(app, opts, [async function (app) {
38
- app.get('/', () => 'hello world')
39
- }])
40
- }
41
-
42
- const app = await buildServer({
43
- server: {
44
- hostname: '127.0.0.1',
45
- port: 0
46
- },
47
- plugins: {
48
- paths: [{
49
- path: require.resolve('./fixtures/other-side.js')
50
- }]
51
- }
52
- }, myApp)
53
-
54
- teardown(async () => {
55
- await app.close()
56
- })
57
- await app.start()
58
-
59
- const res = await (request(app.url))
60
- const body = await res.body.json()
61
- equal(res.statusCode, 500)
62
- same(body, {
63
- statusCode: 500,
64
- error: 'Internal Server Error',
65
- message: 'kaboom'
66
- })
67
- })
@@ -1,220 +0,0 @@
1
- 'use strict'
2
-
3
- // setup the undici agent
4
- require('./helper')
5
-
6
- const { test, equal } = require('tap')
7
- const { buildServer } = require('..')
8
- const { request } = require('undici')
9
- const { promisify } = require('util')
10
- const sleep = promisify(setTimeout)
11
-
12
- test('has /metrics endpoint on default prometheus port', async ({ teardown, equal, fail, match }) => {
13
- const app = await buildServer({
14
- server: {
15
- hostname: '127.0.0.1',
16
- port: 0
17
- },
18
- metrics: true
19
- })
20
-
21
- teardown(async () => {
22
- await app.close()
23
- })
24
- await app.start()
25
-
26
- // needed to reach 100% code cov, otherwise the ELU check won't run
27
- await sleep(120)
28
- const res = await (request('http://127.0.0.1:9090/metrics'))
29
- const body = await res.body.text()
30
- equal(res.statusCode, 200)
31
- match(res.headers['content-type'], /^text\/plain/)
32
- testPrometheusOutput(body)
33
- })
34
-
35
- test('has /metrics endpoint with accept application/json', async ({ teardown, equal, fail, match }) => {
36
- const app = await buildServer({
37
- server: {
38
- hostname: '127.0.0.1',
39
- port: 0
40
- },
41
- metrics: true
42
- })
43
-
44
- teardown(async () => {
45
- await app.close()
46
- })
47
- await app.start()
48
-
49
- const res = await (request(
50
- 'http://127.0.0.1:9090/metrics',
51
- {
52
- headers: {
53
- accept: 'application/json'
54
- }
55
- }
56
- ))
57
- match(res.headers['content-type'], /^application\/json/)
58
- const json = await res.body.json()
59
- equal(res.statusCode, 200)
60
- testPrometheusJsonOutput(json)
61
- })
62
-
63
- test('has /metrics endpoint on configured port', async ({ teardown, equal, fail, match }) => {
64
- const app = await buildServer({
65
- server: {
66
- hostname: '127.0.0.1',
67
- port: 0
68
- },
69
- metrics: {
70
- port: 9999
71
- }
72
- })
73
-
74
- teardown(async () => {
75
- await app.close()
76
- })
77
- await app.start()
78
-
79
- const res = await (request('http://127.0.0.1:9999/metrics'))
80
- equal(res.statusCode, 200)
81
- match(res.headers['content-type'], /^text\/plain/)
82
- const body = await res.body.text()
83
- testPrometheusOutput(body)
84
- })
85
-
86
- test('support basic auth', async ({ teardown, equal, fail, match }) => {
87
- const app = await buildServer({
88
- server: {
89
- hostname: '127.0.0.1',
90
- port: 0
91
- },
92
- metrics: {
93
- auth: {
94
- username: 'foo',
95
- password: 'bar'
96
- }
97
- }
98
- })
99
-
100
- teardown(async () => {
101
- await app.close()
102
- })
103
- await app.start()
104
-
105
- {
106
- const res = await (request('http://127.0.0.1:9090/metrics'))
107
- equal(res.statusCode, 401)
108
- match(res.headers['content-type'], /^application\/json/)
109
- }
110
-
111
- {
112
- // wrong credentials
113
- const res = await (request('http://127.0.0.1:9090/metrics', {
114
- headers: {
115
- authorization: `Basic ${Buffer.from('bar:foo').toString('base64')}`
116
- }
117
- }))
118
- equal(res.statusCode, 401)
119
- match(res.headers['content-type'], /^application\/json/)
120
- }
121
-
122
- {
123
- const res = await (request('http://127.0.0.1:9090/metrics', {
124
- headers: {
125
- authorization: `Basic ${Buffer.from('foo:bar').toString('base64')}`
126
- }
127
- }))
128
- equal(res.statusCode, 200)
129
- match(res.headers['content-type'], /^text\/plain/)
130
- const body = await res.body.text()
131
- testPrometheusOutput(body)
132
- }
133
- })
134
-
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
-
157
- test('restarting 10 times does not leak', async ({ teardown, equal, fail, match }) => {
158
- process.on('warning', (warning) => {
159
- fail('warning was raised')
160
- })
161
- const app = await buildServer({
162
- server: {
163
- hostname: '127.0.0.1',
164
- port: 0
165
- },
166
- metrics: true
167
- })
168
-
169
- teardown(async () => {
170
- await app.close()
171
- })
172
-
173
- await app.start()
174
-
175
- for (let i = 0; i < 10; i++) {
176
- await app.restart()
177
- }
178
- })
179
-
180
- function testPrometheusOutput (output) {
181
- let metricBlock = []
182
- const lines = output.split('\n')
183
- for (let i = 0; i < lines.length; i++) {
184
- const line = lines[i]
185
- if (line === '') {
186
- // check this metric set
187
- checkMetricBlock(metricBlock)
188
- metricBlock = []
189
- } else {
190
- metricBlock.push(line)
191
- }
192
- }
193
- }
194
-
195
- function checkMetricBlock (metricBlock) {
196
- if (!metricBlock[0].match(/^# HELP/)) {
197
- throw new Error('First line should be HELP')
198
- }
199
-
200
- if (!metricBlock[1].match(/^# TYPE/)) {
201
- throw new Error('Second line should be TYPE')
202
- }
203
- for (let i = 2; i < metricBlock.length; i++) {
204
- const split = metricBlock[i].split(' ')
205
- if (split.length !== 2) {
206
- throw new Error(`Bad format for metric: ${metricBlock[i]}`)
207
- }
208
- }
209
- return true
210
- }
211
-
212
- function testPrometheusJsonOutput (output) {
213
- for (const metric of output) {
214
- equal(typeof metric.help, 'string', 'metric.help is string')
215
- equal(typeof metric.name, 'string', 'metric.name is string')
216
- equal(typeof metric.type, 'string', 'metric.type is string')
217
- equal(typeof metric.aggregator, 'string', 'metric.aggregator is string')
218
- equal(Array.isArray(metric.values), true, 'metric.values is array')
219
- }
220
- }
@@ -1,230 +0,0 @@
1
- 'use strict'
2
-
3
- const { test } = require('tap')
4
- const { buildServer } = require('..')
5
- const { buildConfig } = require('./helper')
6
- const { request } = require('undici')
7
- const { join } = require('path')
8
-
9
- test('should respond 200 on root endpoint', async ({ teardown, equal, same }) => {
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
- await app.start()
25
-
26
- {
27
- // No browser (i.e. curl)
28
- const res = await (request(`${app.url}/`))
29
- equal(res.statusCode, 200)
30
- const body = await res.body.json()
31
- same(body, { message: 'Welcome to Platformatic! Please visit https://docs.platformatic.dev' })
32
- }
33
-
34
- {
35
- // browser
36
- const res = await (request(`${app.url}/`, {
37
- headers: {
38
- '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'
39
- }
40
- }))
41
-
42
- equal(res.statusCode, 200)
43
- equal(res.headers['content-type'], 'text/html; charset=UTF-8')
44
- }
45
- })
46
-
47
- test('should not overwrite a plugin which define a root endpoint', async ({ teardown, equal, same }) => {
48
- const app = await buildServer(buildConfig({
49
- server: {
50
- hostname: '127.0.0.1',
51
- port: 0,
52
- healthCheck: {
53
- enabled: true,
54
- interval: 2000
55
- }
56
- },
57
- plugins: {
58
- paths: [join(__dirname, 'fixtures', 'root-endpoint-plugin.js')]
59
- }
60
- }))
61
-
62
- teardown(async () => {
63
- await app.close()
64
- })
65
- await app.start()
66
-
67
- const res = await (request(`${app.url}/`))
68
- equal(res.statusCode, 200)
69
- const body = await res.body.json()
70
- same(body, { message: 'Root Plugin' })
71
- })
72
-
73
- test('openapi enabled', async ({ teardown, equal, same }) => {
74
- const app = await buildServer(buildConfig({
75
- server: {
76
- hostname: '127.0.0.1',
77
- port: 0,
78
- healthCheck: {
79
- enabled: true,
80
- interval: 2000
81
- }
82
- },
83
- service: {
84
- openapi: true
85
- },
86
- plugins: {
87
- paths: [join(__dirname, 'fixtures', 'root-endpoint-plugin.js')]
88
- }
89
- }))
90
-
91
- teardown(async () => {
92
- await app.close()
93
- })
94
- await app.start()
95
-
96
- {
97
- // No browser (i.e. curl)
98
- const res = await (request(`${app.url}/documentation/json`))
99
- equal(res.statusCode, 200)
100
- const body = await res.body.json()
101
-
102
- equal(body.openapi, '3.0.3')
103
- equal(body.info.title, 'Platformatic')
104
- equal(body.info.version, '1.0.0')
105
- equal(!!body.paths['/'].get, true)
106
- }
107
- })
108
-
109
- test('openapi config', async ({ teardown, equal, same }) => {
110
- const app = await buildServer(buildConfig({
111
- server: {
112
- hostname: '127.0.0.1',
113
- port: 0
114
- },
115
- service: {
116
- openapi: {
117
- info: {
118
- title: 'My Service',
119
- version: '0.0.42',
120
- description: 'My Service is the best service ever'
121
- }
122
- }
123
- },
124
- plugins: {
125
- paths: [join(__dirname, 'fixtures', 'root-endpoint-plugin.js')]
126
- }
127
- }))
128
-
129
- teardown(async () => {
130
- await app.close()
131
- })
132
- await app.start()
133
-
134
- {
135
- // No browser (i.e. curl)
136
- const res = await (request(`${app.url}/documentation/json`))
137
- equal(res.statusCode, 200)
138
- const body = await res.body.json()
139
-
140
- equal(body.openapi, '3.0.3')
141
- equal(body.info.title, 'My Service')
142
- equal(body.info.version, '0.0.42')
143
- equal(body.info.description, 'My Service is the best service ever')
144
- equal(!!body.paths['/'].get, true)
145
- }
146
- })
147
-
148
- test('openapi disabled', async ({ teardown, equal, same }) => {
149
- const app = await buildServer(buildConfig({
150
- server: {
151
- hostname: '127.0.0.1',
152
- port: 0,
153
- healthCheck: {
154
- enabled: true,
155
- interval: 2000
156
- }
157
- },
158
- service: {
159
- openapi: false
160
- },
161
- plugins: {
162
- paths: [join(__dirname, 'fixtures', 'root-endpoint-plugin.js')]
163
- }
164
- }))
165
-
166
- teardown(async () => {
167
- await app.close()
168
- })
169
- await app.start()
170
-
171
- {
172
- // No browser (i.e. curl)
173
- const res = await (request(`${app.url}/documentation/json`))
174
- equal(res.statusCode, 404)
175
- await res.body.text()
176
- }
177
- })
178
-
179
- test('openapi disabled by default', async ({ teardown, equal, same }) => {
180
- const app = await buildServer(buildConfig({
181
- server: {
182
- hostname: '127.0.0.1',
183
- port: 0,
184
- healthCheck: {
185
- enabled: true,
186
- interval: 2000
187
- }
188
- },
189
- plugins: {
190
- paths: [join(__dirname, 'fixtures', 'root-endpoint-plugin.js')]
191
- }
192
- }))
193
-
194
- teardown(async () => {
195
- await app.close()
196
- })
197
- await app.start()
198
-
199
- {
200
- // No browser (i.e. curl)
201
- const res = await (request(`${app.url}/documentation/json`))
202
- equal(res.statusCode, 404)
203
- await res.body.text()
204
- }
205
- })
206
-
207
- test('request id is a uuid', async ({ teardown, equal, match }) => {
208
- const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
209
- const app = await buildServer({
210
- server: {
211
- hostname: '127.0.0.1',
212
- port: 0
213
- },
214
- plugins: {
215
- paths: [join(__dirname, 'fixtures', 'request-id.js')]
216
- }
217
- })
218
-
219
- teardown(async () => {
220
- await app.close()
221
- })
222
- await app.start()
223
-
224
- const res = await request(`${app.url}/request-id`, {
225
- method: 'GET'
226
- })
227
- equal(res.statusCode, 200)
228
- const json = await res.body.json()
229
- match(json.request_id, UUID_REGEX)
230
- })
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- const { test } = require('tap')
4
- const { join } = require('path')
5
- const { schema } = require('../lib/schema')
6
-
7
- test('schema output', async (t) => {
8
- const { execa } = await import('execa')
9
- const { stdout } = await execa(process.execPath, [join(__dirname, '..', 'lib', 'schema.js')])
10
-
11
- t.same(stdout, JSON.stringify(schema, null, 2))
12
- })
File without changes