@platformatic/service 0.46.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.
- package/package.json +6 -6
- package/fixtures/hello/no-server-logger.json +0 -13
- package/fixtures/hello/platformatic.service.json +0 -18
- package/fixtures/hello/plugin.js +0 -7
- package/fixtures/hello/warn-log.service.json +0 -18
- package/fixtures/hello-client/hello/hello.cjs +0 -21
- package/fixtures/hello-client/hello/hello.d.ts +0 -34
- package/fixtures/hello-client/hello/hello.openapi.json +0 -22
- package/fixtures/hello-client/hello/package.json +0 -5
- package/fixtures/hello-client/platformatic.service.json +0 -19
- package/fixtures/hello-client/plugin.js +0 -8
- package/fixtures/hello-client-ts/hello/hello.cjs +0 -21
- package/fixtures/hello-client-ts/hello/hello.d.ts +0 -34
- package/fixtures/hello-client-ts/hello/hello.openapi.json +0 -22
- package/fixtures/hello-client-ts/hello/package.json +0 -5
- package/fixtures/hello-client-ts/platformatic.service.json +0 -21
- package/fixtures/hello-client-ts/plugin.ts +0 -8
- package/fixtures/hello-client-ts/tsconfig.json +0 -23
- package/fixtures/hello-client-ts-without-deps/hello.d.ts +0 -34
- package/fixtures/hello-client-ts-without-deps/hello.openapi.json +0 -22
- package/fixtures/hello-client-ts-without-deps/platformatic.service.json +0 -23
- package/fixtures/hello-client-ts-without-deps/plugin.ts +0 -8
- package/fixtures/hello-client-ts-without-deps/tsconfig.json +0 -22
- package/fixtures/hello-client-without-deps/hello.d.ts +0 -34
- package/fixtures/hello-client-without-deps/hello.openapi.json +0 -22
- package/fixtures/hello-client-without-deps/platformatic.service.json +0 -21
- package/fixtures/hello-client-without-deps/plugin.js +0 -8
- package/fixtures/https/embedded-pem.json +0 -20
- package/fixtures/https/https.crt +0 -25
- package/fixtures/https/https.key +0 -27
- package/fixtures/https/pem-path.json +0 -20
- package/fixtures/https/plugin.js +0 -7
- package/fixtures/options/platformatic.service.yml +0 -9
- package/fixtures/options/plugin.js +0 -7
- package/test/autoload.test.js +0 -486
- package/test/cli/compile-1.test.mjs +0 -352
- package/test/cli/compile-2.test.mjs +0 -310
- package/test/cli/gen-schema.test.mjs +0 -44
- package/test/cli/gen-types.test.mjs +0 -30
- package/test/cli/helper.mjs +0 -67
- package/test/cli/start.test.mjs +0 -126
- package/test/cli/tap-parallel-not-ok +0 -0
- package/test/cli/validations.test.mjs +0 -33
- package/test/clients.test.js +0 -87
- package/test/config.test.js +0 -316
- package/test/cors.test.js +0 -291
- package/test/fixtures/bad-typescript-plugin/platformatic.service.json +0 -16
- package/test/fixtures/bad-typescript-plugin/plugin.ts +0 -5
- package/test/fixtures/bad-typescript-plugin/tsconfig.json +0 -22
- package/test/fixtures/custom-port-placeholder.json +0 -10
- package/test/fixtures/default-env-var-names.json +0 -7
- package/test/fixtures/directories/platformatic.service.json +0 -13
- package/test/fixtures/directories/plugins/decorator.js +0 -7
- package/test/fixtures/directories/routes/foo/bar.js +0 -11
- package/test/fixtures/directories/routes/foo/baz/index.js +0 -7
- package/test/fixtures/directories/routes/foo/baz/index2.js +0 -11
- package/test/fixtures/directories/routes/oof/auto.hooks.js +0 -5
- package/test/fixtures/directories/routes/oof/index.js +0 -7
- package/test/fixtures/directories/routes/root.js +0 -7
- package/test/fixtures/hello-ts-with-config/global.d.ts +0 -8
- package/test/fixtures/hello-ts-with-config/platformatic.service.json +0 -16
- package/test/fixtures/hello-ts-with-config/plugin.ts +0 -8
- package/test/fixtures/hello-ts-with-config/tsconfig.json +0 -23
- package/test/fixtures/hello-world-resolver.js +0 -16
- package/test/fixtures/missing-property.config.json +0 -1
- package/test/fixtures/nested-directories/modules/catalogue/index.js +0 -11
- package/test/fixtures/nested-directories/modules/catalogue/routes/products.js +0 -14
- package/test/fixtures/nested-directories/modules/inventory/index.js +0 -33
- package/test/fixtures/nested-directories/modules/inventory/routes/product.js +0 -15
- package/test/fixtures/nested-directories/package.json +0 -3
- package/test/fixtures/nested-directories/platformatic.service.json +0 -23
- package/test/fixtures/nested-directories/plugins/decorator.js +0 -3
- package/test/fixtures/nested-directories/plugins/handlers.js +0 -17
- package/test/fixtures/not-load.js +0 -8
- package/test/fixtures/not-load.service.json +0 -13
- package/test/fixtures/other-side.js +0 -9
- package/test/fixtures/request-id.js +0 -9
- package/test/fixtures/root-endpoint-plugin.js +0 -8
- package/test/fixtures/throw-resolver.js +0 -16
- package/test/fixtures/typescript-autoload/platformatic.service.json +0 -16
- package/test/fixtures/typescript-autoload/routes/plugin.ts +0 -5
- package/test/fixtures/typescript-autoload/tsconfig.json +0 -22
- package/test/fixtures/typescript-compiled/compiled/plugin.js +0 -6
- package/test/fixtures/typescript-compiled/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-custom-flags/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin-custom-flags/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-custom-flags/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-custom-tsconfig/a-config-for-ts.json +0 -22
- package/test/fixtures/typescript-plugin-custom-tsconfig/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin-custom-tsconfig/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin-nocompile/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-nocompile-enabled/platformatic.service.json +0 -18
- package/test/fixtures/typescript-plugin-nocompile-enabled/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile-enabled/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-nocompile-string/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin-nocompile-string/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-nocompile-string/tsconfig.json +0 -22
- package/test/fixtures/typescript-plugin-string/platformatic.service.json +0 -16
- package/test/fixtures/typescript-plugin-string/plugin.ts +0 -5
- package/test/fixtures/typescript-plugin-string/tsconfig.json +0 -22
- package/test/fixtures/undici-plugin.js +0 -15
- package/test/graphql.test.js +0 -219
- package/test/healthcheck.test.js +0 -92
- package/test/helper.js +0 -30
- package/test/https.test.js +0 -64
- package/test/lambda.test.js +0 -103
- package/test/load-and-reload-files.test.js +0 -180
- package/test/load-plugin.test.js +0 -67
- package/test/metrics.test.js +0 -220
- package/test/routes.test.js +0 -230
- package/test/schema.test.js +0 -12
- package/test/tap-parallel-ok +0 -0
- package/test/telemetry.test.js +0 -87
- package/test/utils.test.js +0 -37
package/test/autoload.test.js
DELETED
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
require('./helper')
|
|
4
|
-
const { test } = require('tap')
|
|
5
|
-
const { buildServer } = require('..')
|
|
6
|
-
const { request } = require('undici')
|
|
7
|
-
const { join } = require('path')
|
|
8
|
-
|
|
9
|
-
test('autoload & filesystem based routing / watch disabled', async ({ teardown, equal }) => {
|
|
10
|
-
const config = {
|
|
11
|
-
server: {
|
|
12
|
-
hostname: '127.0.0.1',
|
|
13
|
-
port: 0
|
|
14
|
-
},
|
|
15
|
-
plugins: {
|
|
16
|
-
paths: [join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
17
|
-
},
|
|
18
|
-
watch: false,
|
|
19
|
-
metrics: false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const app = await buildServer(config)
|
|
23
|
-
teardown(async () => {
|
|
24
|
-
await app.close()
|
|
25
|
-
})
|
|
26
|
-
await app.start()
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
const res = await request(`${app.url}/`)
|
|
30
|
-
equal(res.statusCode, 200, 'status code')
|
|
31
|
-
const body = await res.body.json()
|
|
32
|
-
equal(body.hello, 'from root', 'body')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
const res = await request(`${app.url}/foo/bar`)
|
|
37
|
-
equal(res.statusCode, 200, 'status code')
|
|
38
|
-
const body = await res.body.json()
|
|
39
|
-
equal(body.hello, 'from bar', 'body')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
44
|
-
equal(res.statusCode, 200, 'status code')
|
|
45
|
-
const body = await res.body.json()
|
|
46
|
-
equal(body.hello, 'from baz', 'body')
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('multiple files / watch false', async ({ teardown, equal }) => {
|
|
51
|
-
const config = {
|
|
52
|
-
server: {
|
|
53
|
-
hostname: '127.0.0.1',
|
|
54
|
-
port: 0
|
|
55
|
-
},
|
|
56
|
-
plugins: {
|
|
57
|
-
paths: [{
|
|
58
|
-
path: join(__dirname, 'fixtures', 'directories', 'plugins')
|
|
59
|
-
}, {
|
|
60
|
-
path: join(__dirname, 'fixtures', 'directories', 'routes')
|
|
61
|
-
}]
|
|
62
|
-
},
|
|
63
|
-
watch: false,
|
|
64
|
-
metrics: false
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const app = await buildServer(config)
|
|
68
|
-
teardown(async () => {
|
|
69
|
-
await app.close()
|
|
70
|
-
})
|
|
71
|
-
await app.start()
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
const res = await request(`${app.url}/`)
|
|
75
|
-
equal(res.statusCode, 200, 'status code')
|
|
76
|
-
const body = await res.body.json()
|
|
77
|
-
equal(body.hello, 'from root', 'body')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
const res = await request(`${app.url}/foo/bar`)
|
|
82
|
-
equal(res.statusCode, 200, 'status code')
|
|
83
|
-
const body = await res.body.json()
|
|
84
|
-
equal(body.hello, 'from bar', 'body')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
89
|
-
equal(res.statusCode, 200, 'status code')
|
|
90
|
-
const body = await res.body.json()
|
|
91
|
-
equal(body.hello, 'from baz', 'body')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
const res = await request(`${app.url}/foo/with-decorator`)
|
|
96
|
-
equal(res.statusCode, 200, 'status code')
|
|
97
|
-
const body = await res.body.json()
|
|
98
|
-
equal(body.hello, 'bar', 'body')
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('autoload & filesystem based routing / watch disabled / no object', async ({ teardown, equal }) => {
|
|
103
|
-
const config = {
|
|
104
|
-
server: {
|
|
105
|
-
hostname: '127.0.0.1',
|
|
106
|
-
port: 0
|
|
107
|
-
},
|
|
108
|
-
plugins: {
|
|
109
|
-
paths: [join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
110
|
-
},
|
|
111
|
-
watch: false,
|
|
112
|
-
metrics: false
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const app = await buildServer(config)
|
|
116
|
-
teardown(async () => {
|
|
117
|
-
await app.close()
|
|
118
|
-
})
|
|
119
|
-
await app.start()
|
|
120
|
-
|
|
121
|
-
{
|
|
122
|
-
const res = await request(`${app.url}/`)
|
|
123
|
-
equal(res.statusCode, 200, 'status code')
|
|
124
|
-
const body = await res.body.json()
|
|
125
|
-
equal(body.hello, 'from root', 'body')
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
{
|
|
129
|
-
const res = await request(`${app.url}/foo/bar`)
|
|
130
|
-
equal(res.statusCode, 200, 'status code')
|
|
131
|
-
const body = await res.body.json()
|
|
132
|
-
equal(body.hello, 'from bar', 'body')
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
{
|
|
136
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
137
|
-
equal(res.statusCode, 200, 'status code')
|
|
138
|
-
const body = await res.body.json()
|
|
139
|
-
equal(body.hello, 'from baz', 'body')
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test('multiple files / watch false / no object', async ({ teardown, equal }) => {
|
|
144
|
-
const config = {
|
|
145
|
-
server: {
|
|
146
|
-
hostname: '127.0.0.1',
|
|
147
|
-
port: 0
|
|
148
|
-
},
|
|
149
|
-
plugins: {
|
|
150
|
-
paths: [
|
|
151
|
-
join(__dirname, 'fixtures', 'directories', 'plugins'),
|
|
152
|
-
join(__dirname, 'fixtures', 'directories', 'routes')
|
|
153
|
-
]
|
|
154
|
-
},
|
|
155
|
-
watch: false,
|
|
156
|
-
metrics: false
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const app = await buildServer(config)
|
|
160
|
-
teardown(async () => {
|
|
161
|
-
await app.close()
|
|
162
|
-
})
|
|
163
|
-
await app.start()
|
|
164
|
-
|
|
165
|
-
{
|
|
166
|
-
const res = await request(`${app.url}/`)
|
|
167
|
-
equal(res.statusCode, 200, 'status code')
|
|
168
|
-
const body = await res.body.json()
|
|
169
|
-
equal(body.hello, 'from root', 'body')
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
{
|
|
173
|
-
const res = await request(`${app.url}/foo/bar`)
|
|
174
|
-
equal(res.statusCode, 200, 'status code')
|
|
175
|
-
const body = await res.body.json()
|
|
176
|
-
equal(body.hello, 'from bar', 'body')
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
{
|
|
180
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
181
|
-
equal(res.statusCode, 200, 'status code')
|
|
182
|
-
const body = await res.body.json()
|
|
183
|
-
equal(body.hello, 'from baz', 'body')
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
const res = await request(`${app.url}/foo/with-decorator`)
|
|
188
|
-
equal(res.statusCode, 200, 'status code')
|
|
189
|
-
const body = await res.body.json()
|
|
190
|
-
equal(body.hello, 'bar', 'body')
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
test('nested directories', async ({ teardown, equal, same }) => {
|
|
195
|
-
const config = {
|
|
196
|
-
server: {
|
|
197
|
-
hostname: '127.0.0.1',
|
|
198
|
-
port: 0,
|
|
199
|
-
// Windows CI is slow
|
|
200
|
-
pluginTimeout: 60 * 1000
|
|
201
|
-
},
|
|
202
|
-
service: {
|
|
203
|
-
openapi: true
|
|
204
|
-
},
|
|
205
|
-
plugins: {
|
|
206
|
-
paths: [{
|
|
207
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'plugins'),
|
|
208
|
-
encapsulate: false
|
|
209
|
-
}, {
|
|
210
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'modules'),
|
|
211
|
-
encapsulate: false,
|
|
212
|
-
maxDepth: 1
|
|
213
|
-
}]
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const app = await buildServer(config)
|
|
218
|
-
teardown(async () => {
|
|
219
|
-
await app.close()
|
|
220
|
-
})
|
|
221
|
-
await app.start()
|
|
222
|
-
|
|
223
|
-
{
|
|
224
|
-
const res = await request(`${app.url}/inventory/product/42`)
|
|
225
|
-
equal(res.statusCode, 200, 'status code')
|
|
226
|
-
const body = await res.body.json()
|
|
227
|
-
same(body, { sku: 42, inStore: 2 }, 'body')
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
{
|
|
231
|
-
const res = await request(`${app.url}/catalogue/products`)
|
|
232
|
-
equal(res.statusCode, 200, 'status code')
|
|
233
|
-
const body = await res.body.json()
|
|
234
|
-
same(body, [{ sku: 42, name: 'foo', inStore: 2 }, { sku: 43, name: 'bar', inStore: 0 }], 'body')
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
{
|
|
238
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
239
|
-
equal(res.statusCode, 404, 'status code')
|
|
240
|
-
const body = await res.body.text()
|
|
241
|
-
equal(body, 'I\'m sorry, I couldn\'t find what you were looking for.')
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
const res = await request(`${app.url}/catalogue/error`)
|
|
246
|
-
equal(res.statusCode, 500, 'status code')
|
|
247
|
-
const body = await res.body.text()
|
|
248
|
-
equal(body, 'I\'m sorry, there was an error processing your request.')
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
test('disable encapsulation for a single file', async ({ teardown, equal, same }) => {
|
|
253
|
-
const config = {
|
|
254
|
-
server: {
|
|
255
|
-
hostname: '127.0.0.1',
|
|
256
|
-
port: 0,
|
|
257
|
-
// Windows CI is slow
|
|
258
|
-
pluginTimeout: 60 * 1000
|
|
259
|
-
},
|
|
260
|
-
service: {
|
|
261
|
-
openapi: true
|
|
262
|
-
},
|
|
263
|
-
plugins: {
|
|
264
|
-
paths: [{
|
|
265
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'plugins', 'decorator.js'),
|
|
266
|
-
encapsulate: false
|
|
267
|
-
}, {
|
|
268
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'plugins', 'handlers.js'),
|
|
269
|
-
encapsulate: false
|
|
270
|
-
}, {
|
|
271
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'modules'),
|
|
272
|
-
encapsulate: false,
|
|
273
|
-
maxDepth: 1
|
|
274
|
-
}]
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const app = await buildServer(config)
|
|
279
|
-
teardown(async () => {
|
|
280
|
-
await app.close()
|
|
281
|
-
})
|
|
282
|
-
await app.start()
|
|
283
|
-
|
|
284
|
-
{
|
|
285
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
286
|
-
equal(res.statusCode, 404, 'status code')
|
|
287
|
-
const body = await res.body.text()
|
|
288
|
-
equal(body, 'I\'m sorry, I couldn\'t find what you were looking for.')
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
{
|
|
292
|
-
const res = await request(`${app.url}/foo`)
|
|
293
|
-
equal(res.statusCode, 200, 'status code')
|
|
294
|
-
const body = await res.body.text()
|
|
295
|
-
equal(body, 'bar')
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
test('disable encapsulation for a single file / different order', async ({ teardown, equal, same }) => {
|
|
300
|
-
const config = {
|
|
301
|
-
server: {
|
|
302
|
-
hostname: '127.0.0.1',
|
|
303
|
-
port: 0,
|
|
304
|
-
// Windows CI is slow
|
|
305
|
-
pluginTimeout: 60 * 1000
|
|
306
|
-
},
|
|
307
|
-
service: {
|
|
308
|
-
openapi: true
|
|
309
|
-
},
|
|
310
|
-
plugins: {
|
|
311
|
-
paths: [{
|
|
312
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'modules'),
|
|
313
|
-
encapsulate: false,
|
|
314
|
-
maxDepth: 1
|
|
315
|
-
}, {
|
|
316
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'plugins', 'decorator.js'),
|
|
317
|
-
encapsulate: false
|
|
318
|
-
}, {
|
|
319
|
-
path: join(__dirname, 'fixtures', 'nested-directories', 'plugins', 'handlers.js'),
|
|
320
|
-
encapsulate: false
|
|
321
|
-
}]
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const app = await buildServer(config)
|
|
326
|
-
teardown(async () => {
|
|
327
|
-
await app.close()
|
|
328
|
-
})
|
|
329
|
-
await app.start()
|
|
330
|
-
|
|
331
|
-
{
|
|
332
|
-
const res = await request(`${app.url}/foo/baz`)
|
|
333
|
-
equal(res.statusCode, 404, 'status code')
|
|
334
|
-
const body = await res.body.text()
|
|
335
|
-
equal(body, 'I\'m sorry, I couldn\'t find what you were looking for.')
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
{
|
|
339
|
-
const res = await request(`${app.url}/foo`)
|
|
340
|
-
equal(res.statusCode, 200, 'status code')
|
|
341
|
-
const body = await res.body.text()
|
|
342
|
-
equal(body, 'bar')
|
|
343
|
-
}
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
test('autoload with ignorePattern, indexPattern and autoHooksPattern options', async ({ teardown, equal }) => {
|
|
347
|
-
const config = {
|
|
348
|
-
server: {
|
|
349
|
-
hostname: '127.0.0.1',
|
|
350
|
-
port: 0
|
|
351
|
-
},
|
|
352
|
-
plugins: {
|
|
353
|
-
paths: [
|
|
354
|
-
{
|
|
355
|
-
path: join(__dirname, 'fixtures', 'directories', 'routes'),
|
|
356
|
-
|
|
357
|
-
// Ignore the bar.js which should return a 404 for requests made to /bar
|
|
358
|
-
ignorePattern: '^.*(?:bar).js$',
|
|
359
|
-
|
|
360
|
-
// Set index2.js as the index file which sets the root as /index2
|
|
361
|
-
indexPattern: '^index2(?:.js)$',
|
|
362
|
-
|
|
363
|
-
// Override default autohooks.js with auto.hooks.js which overrides
|
|
364
|
-
// the response body
|
|
365
|
-
autoHooksPattern: '^auto.hooks.js$',
|
|
366
|
-
autoHooks: true
|
|
367
|
-
}
|
|
368
|
-
]
|
|
369
|
-
},
|
|
370
|
-
watch: false,
|
|
371
|
-
metrics: false
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const app = await buildServer(config)
|
|
375
|
-
teardown(async () => {
|
|
376
|
-
await app.close()
|
|
377
|
-
})
|
|
378
|
-
await app.start()
|
|
379
|
-
|
|
380
|
-
{
|
|
381
|
-
const res = await request(`${app.url}/`)
|
|
382
|
-
equal(res.statusCode, 200, 'status code')
|
|
383
|
-
const body = await res.body.json()
|
|
384
|
-
equal(body.hello, 'from root', 'body')
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
{
|
|
388
|
-
const res = await request(`${app.url}/foo/bar`)
|
|
389
|
-
equal(res.statusCode, 404, 'status code')
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
{
|
|
393
|
-
const res = await request(`${app.url}/foo/baz/index2`)
|
|
394
|
-
equal(res.statusCode, 200, 'status code')
|
|
395
|
-
const body = await res.body.json()
|
|
396
|
-
equal(body.hello, 'from baz with index2.js', 'body')
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
{
|
|
400
|
-
const res = await request(`${app.url}/oof`)
|
|
401
|
-
equal(res.statusCode, 200, 'status code')
|
|
402
|
-
const body = await res.body.json()
|
|
403
|
-
equal(body.hello, 'from auto.hooks.js', 'body')
|
|
404
|
-
}
|
|
405
|
-
})
|
|
406
|
-
|
|
407
|
-
test('autoload with INVALID ignorePattern, indexPattern and autoHooksPattern options', async ({ teardown, equal }) => {
|
|
408
|
-
const config = {
|
|
409
|
-
server: {
|
|
410
|
-
hostname: '127.0.0.1',
|
|
411
|
-
port: 0
|
|
412
|
-
},
|
|
413
|
-
plugins: {
|
|
414
|
-
paths: [
|
|
415
|
-
{
|
|
416
|
-
path: join(__dirname, 'fixtures', 'directories', 'routes'),
|
|
417
|
-
ignorePattern: '***',
|
|
418
|
-
indexPattern: '***terrible)))_pattern',
|
|
419
|
-
autoHooksPattern: ''
|
|
420
|
-
}
|
|
421
|
-
]
|
|
422
|
-
},
|
|
423
|
-
watch: false,
|
|
424
|
-
metrics: false
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const app = await buildServer(config)
|
|
428
|
-
teardown(async () => {
|
|
429
|
-
await app.close()
|
|
430
|
-
})
|
|
431
|
-
await app.start()
|
|
432
|
-
|
|
433
|
-
{
|
|
434
|
-
const res = await request(`${app.url}/`)
|
|
435
|
-
equal(res.statusCode, 200, 'status code')
|
|
436
|
-
}
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
test('loads encapsulated plugin twice', async ({ teardown, equal, strictSame }) => {
|
|
440
|
-
const config = {
|
|
441
|
-
server: {
|
|
442
|
-
hostname: '127.0.0.1',
|
|
443
|
-
port: 0,
|
|
444
|
-
// Windows CI is slow
|
|
445
|
-
pluginTimeout: 60 * 1000
|
|
446
|
-
},
|
|
447
|
-
service: {
|
|
448
|
-
openapi: true
|
|
449
|
-
},
|
|
450
|
-
plugins: {
|
|
451
|
-
paths: [{
|
|
452
|
-
path: join(__dirname, 'fixtures', 'directories', 'routes')
|
|
453
|
-
}, {
|
|
454
|
-
path: join(__dirname, 'fixtures', 'directories', 'plugins', 'decorator.js')
|
|
455
|
-
}]
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
{
|
|
460
|
-
// First time plugin is loaded from file
|
|
461
|
-
const app = await buildServer(config)
|
|
462
|
-
teardown(async () => {
|
|
463
|
-
await app.close()
|
|
464
|
-
})
|
|
465
|
-
await app.start()
|
|
466
|
-
|
|
467
|
-
const res = await request(`${app.url}/foo/with-decorator`)
|
|
468
|
-
equal(res.statusCode, 200, 'status code')
|
|
469
|
-
const body = await res.body.json()
|
|
470
|
-
strictSame(body, { hello: 'bar' })
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
{
|
|
474
|
-
// Second time plugin is loaded from cache
|
|
475
|
-
const app = await buildServer(config)
|
|
476
|
-
teardown(async () => {
|
|
477
|
-
await app.close()
|
|
478
|
-
})
|
|
479
|
-
await app.start()
|
|
480
|
-
|
|
481
|
-
const res = await request(`${app.url}/foo/with-decorator`)
|
|
482
|
-
equal(res.statusCode, 200, 'status code')
|
|
483
|
-
const body = await res.body.json()
|
|
484
|
-
strictSame(body, { hello: 'bar' })
|
|
485
|
-
}
|
|
486
|
-
})
|