@platformatic/service 0.21.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fixtures/hello/warn-log.service.json +19 -0
- package/fixtures/hello-client/platformatic.service.json +1 -1
- package/fixtures/hello-client-ts/platformatic.service.json +3 -2
- package/index.js +139 -229
- package/lib/compile.js +9 -5
- package/lib/load-config.js +13 -15
- package/lib/plugins/clients.js +12 -0
- package/lib/plugins/cors.js +29 -0
- package/lib/plugins/file-watcher.js +44 -0
- package/lib/plugins/health-check.js +17 -0
- package/lib/plugins/plugins.js +56 -0
- package/lib/plugins/typescript.js +46 -0
- package/lib/root-endpoint/index.js +1 -0
- package/lib/schema.js +8 -1
- package/lib/start.mjs +27 -135
- package/lib/utils.js +2 -11
- package/package.json +24 -23
- package/test/autoload.test.js +77 -59
- package/test/cli/compile.test.mjs +45 -36
- package/test/cli/start.test.mjs +13 -1
- package/test/cli/watch.test.mjs +40 -2
- package/test/clients.test.js +25 -18
- package/test/config.test.js +67 -27
- package/test/cors.test.js +48 -30
- package/test/fixtures/bad-typescript-plugin/platformatic.service.json +3 -1
- package/test/fixtures/custom-port-placeholder.json +10 -0
- package/test/fixtures/typescript-autoload/platformatic.service.json +3 -1
- package/test/fixtures/typescript-plugin/platformatic.service.json +3 -1
- package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +2 -1
- package/test/graphql.test.js +18 -14
- package/test/healthcheck.test.js +22 -13
- package/test/https.test.js +13 -11
- package/test/lambda.test.js +103 -0
- package/test/load-and-reload-files.test.js +98 -109
- package/test/load-plugin.test.js +8 -4
- package/test/metrics.test.js +59 -39
- package/test/routes.test.js +43 -25
- package/test/utils.test.js +6 -15
- package/test/watch.test.js +182 -0
- /package/lib/{graphql.js → plugins/graphql.js} +0 -0
- /package/lib/{metrics-plugin.js → plugins/metrics.js} +0 -0
- /package/lib/{openapi.js → plugins/openapi.js} +0 -0
- /package/lib/{sandbox-wrapper.js → plugins/sandbox-wrapper.js} +0 -0
package/test/autoload.test.js
CHANGED
|
@@ -19,26 +19,28 @@ test('autoload & filesystem based routing / watch disabled', async ({ teardown,
|
|
|
19
19
|
metrics: false
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
teardown(
|
|
24
|
-
|
|
22
|
+
const app = await buildServer(config)
|
|
23
|
+
teardown(async () => {
|
|
24
|
+
await app.close()
|
|
25
|
+
})
|
|
26
|
+
await app.start()
|
|
25
27
|
|
|
26
28
|
{
|
|
27
|
-
const res = await request(`${
|
|
29
|
+
const res = await request(`${app.url}/`)
|
|
28
30
|
equal(res.statusCode, 200, 'status code')
|
|
29
31
|
const body = await res.body.json()
|
|
30
32
|
equal(body.hello, 'from root', 'body')
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
{
|
|
34
|
-
const res = await request(`${
|
|
36
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
35
37
|
equal(res.statusCode, 200, 'status code')
|
|
36
38
|
const body = await res.body.json()
|
|
37
39
|
equal(body.hello, 'from bar', 'body')
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
{
|
|
41
|
-
const res = await request(`${
|
|
43
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
42
44
|
equal(res.statusCode, 200, 'status code')
|
|
43
45
|
const body = await res.body.json()
|
|
44
46
|
equal(body.hello, 'from baz', 'body')
|
|
@@ -58,26 +60,28 @@ test('autoload & filesystem based routing / watch enabled', async ({ teardown, e
|
|
|
58
60
|
metrics: false
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
const
|
|
62
|
-
teardown(
|
|
63
|
-
|
|
63
|
+
const app = await buildServer(config)
|
|
64
|
+
teardown(async () => {
|
|
65
|
+
await app.close()
|
|
66
|
+
})
|
|
67
|
+
await app.start()
|
|
64
68
|
|
|
65
69
|
{
|
|
66
|
-
const res = await request(`${
|
|
70
|
+
const res = await request(`${app.url}/`)
|
|
67
71
|
equal(res.statusCode, 200, 'status code')
|
|
68
72
|
const body = await res.body.json()
|
|
69
73
|
equal(body.hello, 'from root', 'body')
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
{
|
|
73
|
-
const res = await request(`${
|
|
77
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
74
78
|
equal(res.statusCode, 200, 'status code')
|
|
75
79
|
const body = await res.body.json()
|
|
76
80
|
equal(body.hello, 'from bar', 'body')
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
{
|
|
80
|
-
const res = await request(`${
|
|
84
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
81
85
|
equal(res.statusCode, 200, 'status code')
|
|
82
86
|
const body = await res.body.json()
|
|
83
87
|
equal(body.hello, 'from baz', 'body')
|
|
@@ -101,33 +105,35 @@ test('multiple files', async ({ teardown, equal }) => {
|
|
|
101
105
|
metrics: false
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
const
|
|
105
|
-
teardown(
|
|
106
|
-
|
|
108
|
+
const app = await buildServer(config)
|
|
109
|
+
teardown(async () => {
|
|
110
|
+
await app.close()
|
|
111
|
+
})
|
|
112
|
+
await app.start()
|
|
107
113
|
|
|
108
114
|
{
|
|
109
|
-
const res = await request(`${
|
|
115
|
+
const res = await request(`${app.url}/`)
|
|
110
116
|
equal(res.statusCode, 200, 'status code')
|
|
111
117
|
const body = await res.body.json()
|
|
112
118
|
equal(body.hello, 'from root', 'body')
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
{
|
|
116
|
-
const res = await request(`${
|
|
122
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
117
123
|
equal(res.statusCode, 200, 'status code')
|
|
118
124
|
const body = await res.body.json()
|
|
119
125
|
equal(body.hello, 'from bar', 'body')
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
{
|
|
123
|
-
const res = await request(`${
|
|
129
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
124
130
|
equal(res.statusCode, 200, 'status code')
|
|
125
131
|
const body = await res.body.json()
|
|
126
132
|
equal(body.hello, 'from baz', 'body')
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
{
|
|
130
|
-
const res = await request(`${
|
|
136
|
+
const res = await request(`${app.url}/foo/with-decorator`)
|
|
131
137
|
equal(res.statusCode, 200, 'status code')
|
|
132
138
|
const body = await res.body.json()
|
|
133
139
|
equal(body.hello, 'bar', 'body')
|
|
@@ -151,33 +157,35 @@ test('multiple files / watch false', async ({ teardown, equal }) => {
|
|
|
151
157
|
metrics: false
|
|
152
158
|
}
|
|
153
159
|
|
|
154
|
-
const
|
|
155
|
-
teardown(
|
|
156
|
-
|
|
160
|
+
const app = await buildServer(config)
|
|
161
|
+
teardown(async () => {
|
|
162
|
+
await app.close()
|
|
163
|
+
})
|
|
164
|
+
await app.start()
|
|
157
165
|
|
|
158
166
|
{
|
|
159
|
-
const res = await request(`${
|
|
167
|
+
const res = await request(`${app.url}/`)
|
|
160
168
|
equal(res.statusCode, 200, 'status code')
|
|
161
169
|
const body = await res.body.json()
|
|
162
170
|
equal(body.hello, 'from root', 'body')
|
|
163
171
|
}
|
|
164
172
|
|
|
165
173
|
{
|
|
166
|
-
const res = await request(`${
|
|
174
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
167
175
|
equal(res.statusCode, 200, 'status code')
|
|
168
176
|
const body = await res.body.json()
|
|
169
177
|
equal(body.hello, 'from bar', 'body')
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
{
|
|
173
|
-
const res = await request(`${
|
|
181
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
174
182
|
equal(res.statusCode, 200, 'status code')
|
|
175
183
|
const body = await res.body.json()
|
|
176
184
|
equal(body.hello, 'from baz', 'body')
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
{
|
|
180
|
-
const res = await request(`${
|
|
188
|
+
const res = await request(`${app.url}/foo/with-decorator`)
|
|
181
189
|
equal(res.statusCode, 200, 'status code')
|
|
182
190
|
const body = await res.body.json()
|
|
183
191
|
equal(body.hello, 'bar', 'body')
|
|
@@ -197,26 +205,28 @@ test('autoload & filesystem based routing / watch disabled / no object', async (
|
|
|
197
205
|
metrics: false
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
const
|
|
201
|
-
teardown(
|
|
202
|
-
|
|
208
|
+
const app = await buildServer(config)
|
|
209
|
+
teardown(async () => {
|
|
210
|
+
await app.close()
|
|
211
|
+
})
|
|
212
|
+
await app.start()
|
|
203
213
|
|
|
204
214
|
{
|
|
205
|
-
const res = await request(`${
|
|
215
|
+
const res = await request(`${app.url}/`)
|
|
206
216
|
equal(res.statusCode, 200, 'status code')
|
|
207
217
|
const body = await res.body.json()
|
|
208
218
|
equal(body.hello, 'from root', 'body')
|
|
209
219
|
}
|
|
210
220
|
|
|
211
221
|
{
|
|
212
|
-
const res = await request(`${
|
|
222
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
213
223
|
equal(res.statusCode, 200, 'status code')
|
|
214
224
|
const body = await res.body.json()
|
|
215
225
|
equal(body.hello, 'from bar', 'body')
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
{
|
|
219
|
-
const res = await request(`${
|
|
229
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
220
230
|
equal(res.statusCode, 200, 'status code')
|
|
221
231
|
const body = await res.body.json()
|
|
222
232
|
equal(body.hello, 'from baz', 'body')
|
|
@@ -236,26 +246,28 @@ test('autoload & filesystem based routing / watch enabled / no object', async ({
|
|
|
236
246
|
metrics: false
|
|
237
247
|
}
|
|
238
248
|
|
|
239
|
-
const
|
|
240
|
-
teardown(
|
|
241
|
-
|
|
249
|
+
const app = await buildServer(config)
|
|
250
|
+
teardown(async () => {
|
|
251
|
+
await app.close()
|
|
252
|
+
})
|
|
253
|
+
await app.start()
|
|
242
254
|
|
|
243
255
|
{
|
|
244
|
-
const res = await request(`${
|
|
256
|
+
const res = await request(`${app.url}/`)
|
|
245
257
|
equal(res.statusCode, 200, 'status code')
|
|
246
258
|
const body = await res.body.json()
|
|
247
259
|
equal(body.hello, 'from root', 'body')
|
|
248
260
|
}
|
|
249
261
|
|
|
250
262
|
{
|
|
251
|
-
const res = await request(`${
|
|
263
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
252
264
|
equal(res.statusCode, 200, 'status code')
|
|
253
265
|
const body = await res.body.json()
|
|
254
266
|
equal(body.hello, 'from bar', 'body')
|
|
255
267
|
}
|
|
256
268
|
|
|
257
269
|
{
|
|
258
|
-
const res = await request(`${
|
|
270
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
259
271
|
equal(res.statusCode, 200, 'status code')
|
|
260
272
|
const body = await res.body.json()
|
|
261
273
|
equal(body.hello, 'from baz', 'body')
|
|
@@ -275,33 +287,35 @@ test('multiple files / no object', async ({ teardown, equal }) => {
|
|
|
275
287
|
metrics: false
|
|
276
288
|
}
|
|
277
289
|
|
|
278
|
-
const
|
|
279
|
-
teardown(
|
|
280
|
-
|
|
290
|
+
const app = await buildServer(config)
|
|
291
|
+
teardown(async () => {
|
|
292
|
+
await app.close()
|
|
293
|
+
})
|
|
294
|
+
await app.start()
|
|
281
295
|
|
|
282
296
|
{
|
|
283
|
-
const res = await request(`${
|
|
297
|
+
const res = await request(`${app.url}/`)
|
|
284
298
|
equal(res.statusCode, 200, 'status code')
|
|
285
299
|
const body = await res.body.json()
|
|
286
300
|
equal(body.hello, 'from root', 'body')
|
|
287
301
|
}
|
|
288
302
|
|
|
289
303
|
{
|
|
290
|
-
const res = await request(`${
|
|
304
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
291
305
|
equal(res.statusCode, 200, 'status code')
|
|
292
306
|
const body = await res.body.json()
|
|
293
307
|
equal(body.hello, 'from bar', 'body')
|
|
294
308
|
}
|
|
295
309
|
|
|
296
310
|
{
|
|
297
|
-
const res = await request(`${
|
|
311
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
298
312
|
equal(res.statusCode, 200, 'status code')
|
|
299
313
|
const body = await res.body.json()
|
|
300
314
|
equal(body.hello, 'from baz', 'body')
|
|
301
315
|
}
|
|
302
316
|
|
|
303
317
|
{
|
|
304
|
-
const res = await request(`${
|
|
318
|
+
const res = await request(`${app.url}/foo/with-decorator`)
|
|
305
319
|
equal(res.statusCode, 200, 'status code')
|
|
306
320
|
const body = await res.body.json()
|
|
307
321
|
equal(body.hello, 'bar', 'body')
|
|
@@ -324,33 +338,35 @@ test('multiple files / watch false / no object', async ({ teardown, equal }) =>
|
|
|
324
338
|
metrics: false
|
|
325
339
|
}
|
|
326
340
|
|
|
327
|
-
const
|
|
328
|
-
teardown(
|
|
329
|
-
|
|
341
|
+
const app = await buildServer(config)
|
|
342
|
+
teardown(async () => {
|
|
343
|
+
await app.close()
|
|
344
|
+
})
|
|
345
|
+
await app.start()
|
|
330
346
|
|
|
331
347
|
{
|
|
332
|
-
const res = await request(`${
|
|
348
|
+
const res = await request(`${app.url}/`)
|
|
333
349
|
equal(res.statusCode, 200, 'status code')
|
|
334
350
|
const body = await res.body.json()
|
|
335
351
|
equal(body.hello, 'from root', 'body')
|
|
336
352
|
}
|
|
337
353
|
|
|
338
354
|
{
|
|
339
|
-
const res = await request(`${
|
|
355
|
+
const res = await request(`${app.url}/foo/bar`)
|
|
340
356
|
equal(res.statusCode, 200, 'status code')
|
|
341
357
|
const body = await res.body.json()
|
|
342
358
|
equal(body.hello, 'from bar', 'body')
|
|
343
359
|
}
|
|
344
360
|
|
|
345
361
|
{
|
|
346
|
-
const res = await request(`${
|
|
362
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
347
363
|
equal(res.statusCode, 200, 'status code')
|
|
348
364
|
const body = await res.body.json()
|
|
349
365
|
equal(body.hello, 'from baz', 'body')
|
|
350
366
|
}
|
|
351
367
|
|
|
352
368
|
{
|
|
353
|
-
const res = await request(`${
|
|
369
|
+
const res = await request(`${app.url}/foo/with-decorator`)
|
|
354
370
|
equal(res.statusCode, 200, 'status code')
|
|
355
371
|
const body = await res.body.json()
|
|
356
372
|
equal(body.hello, 'bar', 'body')
|
|
@@ -380,33 +396,35 @@ test('nested directories', async ({ teardown, equal, same }) => {
|
|
|
380
396
|
}
|
|
381
397
|
}
|
|
382
398
|
|
|
383
|
-
const
|
|
384
|
-
teardown(
|
|
385
|
-
|
|
399
|
+
const app = await buildServer(config)
|
|
400
|
+
teardown(async () => {
|
|
401
|
+
await app.close()
|
|
402
|
+
})
|
|
403
|
+
await app.start()
|
|
386
404
|
|
|
387
405
|
{
|
|
388
|
-
const res = await request(`${
|
|
406
|
+
const res = await request(`${app.url}/inventory/product/42`)
|
|
389
407
|
equal(res.statusCode, 200, 'status code')
|
|
390
408
|
const body = await res.body.json()
|
|
391
409
|
same(body, { sku: 42, inStore: 2 }, 'body')
|
|
392
410
|
}
|
|
393
411
|
|
|
394
412
|
{
|
|
395
|
-
const res = await request(`${
|
|
413
|
+
const res = await request(`${app.url}/catalogue/products`)
|
|
396
414
|
equal(res.statusCode, 200, 'status code')
|
|
397
415
|
const body = await res.body.json()
|
|
398
416
|
same(body, [{ sku: 42, name: 'foo', inStore: 2 }, { sku: 43, name: 'bar', inStore: 0 }], 'body')
|
|
399
417
|
}
|
|
400
418
|
|
|
401
419
|
{
|
|
402
|
-
const res = await request(`${
|
|
420
|
+
const res = await request(`${app.url}/foo/baz`)
|
|
403
421
|
equal(res.statusCode, 404, 'status code')
|
|
404
422
|
const body = await res.body.text()
|
|
405
423
|
equal(body, 'I\'m sorry, I couldn\'t find what you were looking for.')
|
|
406
424
|
}
|
|
407
425
|
|
|
408
426
|
{
|
|
409
|
-
const res = await request(`${
|
|
427
|
+
const res = await request(`${app.url}/catalogue/error`)
|
|
410
428
|
equal(res.statusCode, 500, 'status code')
|
|
411
429
|
const body = await res.body.text()
|
|
412
430
|
equal(body, 'I\'m sorry, there was an error processing your request.')
|
|
@@ -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
|
-
|
|
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
|
-
|
|
45
|
-
try {
|
|
46
|
-
await access(jsPluginPath)
|
|
47
|
-
} catch (err) {
|
|
48
|
-
t.fail(err)
|
|
49
|
-
}
|
|
37
|
+
t.teardown(exitOnTeardown(child))
|
|
50
38
|
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
try {
|
|
71
|
-
await access(jsPluginPath)
|
|
72
|
-
} catch (err) {
|
|
73
|
-
t.fail(err)
|
|
74
|
-
}
|
|
67
|
+
t.teardown(exitOnTeardown(child))
|
|
75
68
|
|
|
76
|
-
|
|
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,14 +94,10 @@ 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
|
-
child.stderr.pipe(process.stderr)
|
|
92
99
|
|
|
93
100
|
for await (const data of splitter) {
|
|
94
|
-
console.log(data)
|
|
95
101
|
const sanitized = stripAnsi(data)
|
|
96
102
|
if (sanitized.includes('Typescript plugin loaded')) {
|
|
97
103
|
t.pass()
|
|
@@ -158,7 +164,11 @@ t.test('start command should not compile typescript plugin with errors', async (
|
|
|
158
164
|
await childProcess
|
|
159
165
|
t.fail('should not compile bad typescript plugin')
|
|
160
166
|
} catch (err) {
|
|
161
|
-
|
|
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
|
+
}
|
|
162
172
|
childProcess.kill('SIGINT')
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -228,7 +238,6 @@ t.test('should compile typescript plugin with start command with different cwd',
|
|
|
228
238
|
child.stderr.pipe(process.stderr)
|
|
229
239
|
|
|
230
240
|
for await (const data of splitter) {
|
|
231
|
-
console.log(data)
|
|
232
241
|
const sanitized = stripAnsi(data)
|
|
233
242
|
if (sanitized.includes('Typescript plugin loaded')) {
|
|
234
243
|
t.pass()
|
package/test/cli/start.test.mjs
CHANGED
|
@@ -30,6 +30,19 @@ test('start command', async ({ equal, same, match, teardown }) => {
|
|
|
30
30
|
child.kill('SIGINT')
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
+
test('allow custom env properties', async ({ equal, same, match, teardown }) => {
|
|
34
|
+
process.env.A_CUSTOM_PORT = '11111'
|
|
35
|
+
const { child, url } = await start('start', '-c', join(import.meta.url, '..', 'fixtures', 'custom-port-placeholder.json'), '--allow-env=A_CUSTOM_PORT')
|
|
36
|
+
equal(url, 'http://127.0.0.1:11111', 'A_CUSTOM_PORT env variable has been used')
|
|
37
|
+
const res = await request(`${url}`)
|
|
38
|
+
equal(res.statusCode, 200)
|
|
39
|
+
const body = await res.body.json()
|
|
40
|
+
match(body, {}, 'response')
|
|
41
|
+
|
|
42
|
+
child.kill('SIGINT')
|
|
43
|
+
delete process.env.A_CUSTOM_PORT
|
|
44
|
+
})
|
|
45
|
+
|
|
33
46
|
test('default logger', async ({ equal, same, match, teardown }) => {
|
|
34
47
|
const { child, url } = await start('-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'no-server-logger.json'))
|
|
35
48
|
match(url, /http:\/\/127.0.0.1:[0-9]+/)
|
|
@@ -38,7 +51,6 @@ test('default logger', async ({ equal, same, match, teardown }) => {
|
|
|
38
51
|
|
|
39
52
|
test('plugin options', async ({ equal, same, match, teardown }) => {
|
|
40
53
|
const { child, url } = await start('-c', join(import.meta.url, '..', '..', 'fixtures', 'options', 'platformatic.service.yml'))
|
|
41
|
-
|
|
42
54
|
const res = await request(`${url}`)
|
|
43
55
|
equal(res.statusCode, 200)
|
|
44
56
|
const body = await res.body.json()
|
package/test/cli/watch.test.mjs
CHANGED
|
@@ -11,6 +11,7 @@ t.jobs = 5
|
|
|
11
11
|
function createLoggingPlugin (text, reloaded = false) {
|
|
12
12
|
return `\
|
|
13
13
|
module.exports = async (app) => {
|
|
14
|
+
app.log.info({ reloaded: ${reloaded}, text: '${text}' }, 'debugme')
|
|
14
15
|
if (${reloaded}) {
|
|
15
16
|
app.log.info('RELOADED')
|
|
16
17
|
}
|
|
@@ -45,8 +46,6 @@ test('should watch js files by default', async ({ equal, teardown, comment }) =>
|
|
|
45
46
|
])
|
|
46
47
|
|
|
47
48
|
const { child, url } = await start('-c', configFilePath)
|
|
48
|
-
child.stdout.pipe(process.stderr)
|
|
49
|
-
child.stderr.pipe(process.stderr)
|
|
50
49
|
teardown(() => child.kill('SIGINT'))
|
|
51
50
|
|
|
52
51
|
await writeFile(pluginFilePath, createLoggingPlugin('v2', true))
|
|
@@ -292,3 +291,42 @@ test('should not hot reload files with `--hot-reload false`', async ({ teardown,
|
|
|
292
291
|
equal(version, 'v1')
|
|
293
292
|
}
|
|
294
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
|
+
})
|
package/test/clients.test.js
CHANGED
|
@@ -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,
|
|
12
|
-
const
|
|
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
|
-
|
|
14
|
+
teardown(async () => {
|
|
15
|
+
await app1.close()
|
|
16
|
+
})
|
|
17
|
+
await app1.start()
|
|
16
18
|
|
|
17
|
-
|
|
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
|
|
21
|
-
await server1.stop()
|
|
24
|
+
await app2.close()
|
|
22
25
|
})
|
|
23
|
-
await
|
|
24
|
-
|
|
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
|
|
32
|
-
|
|
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 =
|
|
42
|
+
process.env.PLT_CLIENT_URL = app1.url
|
|
35
43
|
|
|
36
44
|
const targetDir = join(__dirname, '..', 'fixtures', 'hello-client-ts')
|
|
37
45
|
|
|
@@ -39,16 +47,15 @@ test('client is loaded (ts)', async ({ teardown, equal, pass, same }) => {
|
|
|
39
47
|
await rmdir(join(targetDir, 'dist'))
|
|
40
48
|
} catch {}
|
|
41
49
|
|
|
42
|
-
await compile(targetDir)
|
|
50
|
+
await compile(targetDir, { server: { logger: { level: 'warn' } } })
|
|
43
51
|
|
|
44
|
-
const
|
|
52
|
+
const app2 = await buildServer(join(targetDir, 'platformatic.service.json'))
|
|
45
53
|
teardown(async () => {
|
|
46
|
-
await
|
|
47
|
-
await server1.stop()
|
|
54
|
+
await app2.close()
|
|
48
55
|
})
|
|
49
|
-
await
|
|
56
|
+
await app2.start()
|
|
50
57
|
|
|
51
|
-
const res = await request(`${
|
|
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' })
|