@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,310 +0,0 @@
1
- import path from 'path'
2
- import os from 'os'
3
- import { access, cp, rm, mkdir } from 'fs/promises'
4
- import t from 'tap'
5
- import { execa } from 'execa'
6
- import stripAnsi from 'strip-ansi'
7
- import split from 'split2'
8
- import { cliPath, safeKill } from './helper.mjs'
9
- import { fileURLToPath } from 'url'
10
-
11
- let count = 0
12
-
13
- if (os.platform() !== 'win32') {
14
- t.jobs = 5
15
- }
16
- t.setTimeout(360000)
17
-
18
- function urlDirname (url) {
19
- return path.dirname(fileURLToPath(url))
20
- }
21
-
22
- async function getCWD (t) {
23
- const dir = path.join(urlDirname(import.meta.url), '..', 'tmp', `typescript-plugin-clone2-${count++}`)
24
- try {
25
- await rm(dir, { recursive: true })
26
- } catch {}
27
-
28
- await mkdir(dir, { recursive: true })
29
-
30
- t.teardown(async () => {
31
- try {
32
- await rm(dir, { recursive: true })
33
- } catch {}
34
- })
35
- return dir
36
- }
37
-
38
- function exitOnTeardown (child) {
39
- return async () => {
40
- await safeKill(child)
41
- }
42
- }
43
-
44
- t.test('start command should not compile typescript if `typescript` is false', async (t) => {
45
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
46
- const cwd = await getCWD(t)
47
-
48
- await cp(testDir, cwd, { recursive: true })
49
-
50
- const child = execa('node', [cliPath, 'start'], { cwd })
51
- t.teardown(exitOnTeardown(child))
52
-
53
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
54
- try {
55
- await access(jsPluginPath)
56
- t.fail("should not have created 'dist/plugin.js'")
57
- } catch (err) {
58
- // cannot start because the plugin is not compiled
59
- t.equal(err.code, 'ENOENT')
60
- t.equal(err.path, jsPluginPath)
61
- t.pass()
62
- }
63
- })
64
-
65
- t.test('should compile typescript plugin with start command with different cwd', async (t) => {
66
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
67
- const dest = path.join(urlDirname(import.meta.url), '..', 'tmp', `typescript-plugin-clone-${count++}`)
68
-
69
- await cp(testDir, dest, { recursive: true })
70
-
71
- const child = execa('node', [cliPath, 'start', '-c', path.join(dest, 'platformatic.service.json')])
72
-
73
- t.teardown(exitOnTeardown(child))
74
-
75
- const splitter = split()
76
- child.stdout.pipe(splitter)
77
- child.stderr.pipe(process.stderr)
78
-
79
- for await (const data of splitter) {
80
- const sanitized = stripAnsi(data)
81
- if (sanitized.includes('Typescript plugin loaded')) {
82
- t.pass()
83
- return
84
- }
85
- }
86
- t.fail('should compile typescript plugin with start command')
87
- })
88
-
89
- t.test('valid tsconfig file inside an inner folder', async (t) => {
90
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
91
- const cwd = await getCWD(t)
92
-
93
- await cp(testDir, cwd, { recursive: true })
94
-
95
- try {
96
- await execa('node', [cliPath, 'compile'], { cwd, stdio: 'inherit' })
97
- } catch (err) {
98
- t.fail('should not catch any error')
99
- }
100
-
101
- t.pass()
102
- })
103
-
104
- t.test('should compile typescript plugin with start command from a folder', async (t) => {
105
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-autoload')
106
- const cwd = await getCWD(t)
107
-
108
- await cp(testDir, cwd, { recursive: true })
109
-
110
- const child = execa('node', [cliPath, 'start'], { cwd })
111
-
112
- t.teardown(exitOnTeardown(child))
113
-
114
- const splitter = split()
115
- child.stdout.pipe(splitter)
116
-
117
- for await (const data of splitter) {
118
- const sanitized = stripAnsi(data)
119
- if (sanitized.includes('Typescript plugin loaded')) {
120
- t.pass()
121
- return
122
- }
123
- }
124
- t.fail('should compile typescript plugin with start command')
125
- })
126
-
127
- t.test('should start the service if it was precompiled and typescript is `false`', async (t) => {
128
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
129
- const cwd = await getCWD(t)
130
-
131
- await cp(testDir, cwd, { recursive: true })
132
-
133
- await execa('node', [cliPath, 'compile'], { cwd })
134
-
135
- const child = execa('node', [cliPath, 'start'], { cwd })
136
-
137
- const splitter = split()
138
- child.stdout.pipe(splitter)
139
-
140
- for await (const data of splitter) {
141
- const sanitized = stripAnsi(data)
142
- if (sanitized.includes('Typescript plugin loaded')) {
143
- t.pass()
144
- return
145
- }
146
- }
147
- t.fail('should load the typescript plugin without compiling it')
148
- })
149
-
150
- t.test('should not start the service if it was not precompiled and typescript is `false`', async (t) => {
151
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
152
- const cwd = await getCWD(t)
153
-
154
- await cp(testDir, cwd, { recursive: true })
155
-
156
- const child = execa('node', [cliPath, 'start'], { cwd })
157
-
158
- const splitter = split()
159
- child.stdout.pipe(splitter)
160
- child.stderr.pipe(splitter)
161
-
162
- for await (const data of splitter) {
163
- const sanitized = stripAnsi(data)
164
- if (sanitized.includes('Unknown file extension ".ts" for')) {
165
- t.pass()
166
- return
167
- }
168
- }
169
- t.fail('should load the typescript plugin without compiling it')
170
- })
171
-
172
- t.test('should compile typescript plugin with string config', async (t) => {
173
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-string')
174
- const cwd = await getCWD(t)
175
-
176
- await cp(testDir, cwd, { recursive: true })
177
-
178
- const child = execa('node', [cliPath, 'compile'], { cwd })
179
-
180
- t.teardown(exitOnTeardown(child))
181
-
182
- const splitter = split()
183
- child.stdout.pipe(splitter)
184
-
185
- for await (const data of splitter) {
186
- const sanitized = stripAnsi(data)
187
- if (sanitized.includes('Typescript compilation completed successfully.')) {
188
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
189
- try {
190
- await access(jsPluginPath)
191
- } catch (err) {
192
- t.fail(err)
193
- }
194
-
195
- t.pass()
196
- return
197
- }
198
- }
199
- t.fail('should compile typescript plugin with a compile command')
200
- })
201
-
202
- t.test('should not start the service if it was not precompiled and typescript is `"false"`', async (t) => {
203
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
204
- const cwd = await getCWD(t)
205
-
206
- await cp(testDir, cwd, { recursive: true })
207
-
208
- const child = execa('node', [cliPath, 'start'], { cwd })
209
-
210
- const splitter = split()
211
- child.stdout.pipe(splitter)
212
- child.stderr.pipe(splitter)
213
-
214
- for await (const data of splitter) {
215
- const sanitized = stripAnsi(data)
216
- if (sanitized.includes('Unknown file extension ".ts" for')) {
217
- t.pass()
218
- return
219
- }
220
- }
221
- t.fail('should load the typescript plugin without compiling it')
222
- })
223
-
224
- t.test('should compile typescript plugin with start command with custom tsconfig', async (t) => {
225
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-custom-tsconfig')
226
- const cwd = await getCWD(t)
227
-
228
- await cp(testDir, cwd, { recursive: true })
229
-
230
- const child = execa('node', [cliPath, 'start'], { cwd })
231
-
232
- const splitter = split()
233
- child.stdout.pipe(splitter)
234
- child.stderr.pipe(splitter)
235
-
236
- for await (const data of splitter) {
237
- const sanitized = stripAnsi(data)
238
- if (sanitized.includes('Typescript plugin loaded')) {
239
- t.pass()
240
- return
241
- }
242
- }
243
- t.fail('should compile typescript plugin with start command')
244
- })
245
-
246
- t.test('should not start the service if it was not precompiled and typescript is `false`', async (t) => {
247
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile-enabled')
248
- const cwd = await getCWD(t)
249
-
250
- await cp(testDir, cwd, { recursive: true })
251
-
252
- const child = execa('node', [cliPath, 'start'], { cwd })
253
-
254
- const splitter = split()
255
- child.stdout.pipe(splitter)
256
- child.stderr.pipe(splitter)
257
-
258
- for await (const data of splitter) {
259
- const sanitized = stripAnsi(data)
260
- if (sanitized.includes('Unknown file extension ".ts" for')) {
261
- t.pass()
262
- return
263
- }
264
- }
265
- t.fail('should load the typescript plugin without compiling it')
266
- })
267
-
268
- t.test('should start without a tsconfig but with a outDir configuration', async (t) => {
269
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-compiled')
270
- const cwd = await getCWD(t)
271
-
272
- await cp(testDir, cwd, { recursive: true })
273
-
274
- const child = execa('node', [cliPath, 'start'], { cwd })
275
-
276
- const splitter = split()
277
- child.stdout.pipe(splitter)
278
- child.stderr.pipe(splitter)
279
-
280
- for await (const data of splitter) {
281
- const sanitized = stripAnsi(data)
282
- if (sanitized.includes('Typescript plugin loaded')) {
283
- t.pass()
284
- return
285
- }
286
- }
287
- t.fail('should compile typescript plugin with start command')
288
- })
289
-
290
- t.test('should compile typescript plugin with start command with custom flags', async (t) => {
291
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-custom-flags')
292
- const cwd = await getCWD(t)
293
-
294
- await cp(testDir, cwd, { recursive: true })
295
-
296
- const child = execa('node', [cliPath, 'start'], { cwd })
297
-
298
- const splitter = split()
299
- child.stdout.pipe(splitter)
300
- child.stderr.pipe(splitter)
301
-
302
- for await (const data of splitter) {
303
- const sanitized = stripAnsi(data)
304
- if (sanitized.includes('Typescript plugin loaded')) {
305
- t.pass()
306
- return
307
- }
308
- }
309
- t.fail('should compile typescript plugin with start command')
310
- })
@@ -1,44 +0,0 @@
1
- import { test } from 'tap'
2
- import fs from 'fs/promises'
3
- import { mkdtempSync } from 'fs'
4
- import { tmpdir } from 'os'
5
- import { generateJsonSchemaConfig } from '../../lib/gen-schema.js'
6
- import { join } from 'path'
7
- import jsonLanguageService from 'vscode-json-languageservice'
8
-
9
- const pkg = JSON.parse(await fs.readFile('../../package.json', 'utf8'))
10
-
11
- test('generateJsonSchemaConfig generates the file', async (t) => {
12
- const tmpDir = await mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
13
- process.chdir(tmpDir)
14
- await generateJsonSchemaConfig()
15
-
16
- const configSchema = await fs.readFile('platformatic.service.schema.json', 'utf8')
17
- const schema = JSON.parse(configSchema)
18
- const { required } = schema
19
- t.has(required, ['server'])
20
- const { $id, type } = schema
21
- t.equal($id, `https://platformatic.dev/schemas/v${pkg.version}/service`)
22
- t.equal(type, 'object')
23
-
24
- const languageservice = jsonLanguageService.getLanguageService({
25
- async schemaRequestService (uri) {
26
- return configSchema
27
- }
28
- })
29
-
30
- languageservice.configure({ allowComments: false, schemas: [{ fileMatch: ['*.data.json'], uri: $id }] })
31
-
32
- const jsonContent = `{
33
- "$schema": "https://platformatic.dev/schemas/v${pkg.version}/service",
34
- "server": {
35
- "hostname": "127.0.0.1",
36
- "port": 3000
37
- }
38
- }`
39
- const jsonContentUri = 'foo://server/example.data.json'
40
- const textDocument = jsonLanguageService.TextDocument.create(jsonContentUri, 'json', 1, jsonContent)
41
- const jsonDocument = languageservice.parseJSONDocument(textDocument)
42
- const diagnostics = await languageservice.doValidation(textDocument, jsonDocument)
43
- t.equal(diagnostics.length, 0)
44
- })
@@ -1,30 +0,0 @@
1
- import { cliPath } from './helper.mjs'
2
- import { test } from 'tap'
3
- import { join } from 'desm'
4
- import { execa } from 'execa'
5
- import { readFile, unlink } from 'fs/promises'
6
-
7
- const GLOBAL_TYPES_TEMPLATE = `
8
- import { FastifyInstance } from 'fastify'
9
- import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
10
-
11
- declare module 'fastify' {
12
- interface FastifyInstance {
13
- platformatic: PlatformaticApp<PlatformaticServiceConfig>
14
- }
15
- }
16
- `
17
-
18
- test('generate global.d.ts', async ({ equal }) => {
19
- const fileNameOrThen = join(import.meta.url, '..', '..', 'fixtures', 'hello', 'global.d.ts')
20
- try {
21
- await unlink(fileNameOrThen)
22
- } catch {}
23
-
24
- await execa('node', [cliPath, 'types', '-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
25
-
26
- const data = await readFile(fileNameOrThen, 'utf-8')
27
- await unlink(fileNameOrThen)
28
-
29
- equal(data, GLOBAL_TYPES_TEMPLATE)
30
- })
@@ -1,67 +0,0 @@
1
- import { Agent, setGlobalDispatcher } from 'undici'
2
- import { on } from 'events'
3
- import { execa } from 'execa'
4
- import split from 'split2'
5
- import { join } from 'desm'
6
- import tap from 'tap'
7
- import os from 'node:os'
8
-
9
- setGlobalDispatcher(new Agent({
10
- keepAliveTimeout: 10,
11
- keepAliveMaxTimeout: 10,
12
- tls: {
13
- rejectUnauthorized: false
14
- }
15
- }))
16
-
17
- // This should not be needed, but a weird combination
18
- // of node-tap, Windows, c8 and ESM makes this necessary.
19
- tap.teardown(() => {
20
- process.exit(0)
21
- })
22
-
23
- export const cliPath = join(import.meta.url, '..', '..', 'service.mjs')
24
-
25
- export async function start (commandOpts, exacaOpts = {}) {
26
- const child = execa('node', [cliPath, 'start', ...commandOpts], exacaOpts)
27
- child.stderr.pipe(process.stdout)
28
-
29
- const output = child.stdout.pipe(split(function (line) {
30
- try {
31
- const obj = JSON.parse(line)
32
- return obj
33
- } catch (err) {
34
- console.log(line)
35
- }
36
- }))
37
- child.ndj = output
38
-
39
- const errorTimeout = setTimeout(() => {
40
- throw new Error('Couldn\'t start server')
41
- }, 30000)
42
-
43
- for await (const messages of on(output, 'data')) {
44
- for (const message of messages) {
45
- const text = message.msg
46
- if (text && text.includes('Server listening at')) {
47
- const url = text.match(/Server listening at (.*)/)[1]
48
- clearTimeout(errorTimeout)
49
- return { child, url, output }
50
- }
51
- }
52
- }
53
- }
54
-
55
- export async function safeKill (child) {
56
- child.kill('SIGINT')
57
- if (os.platform() === 'win32') {
58
- try {
59
- await execa('taskkill', ['/pid', child.pid, '/f', '/t'])
60
- } catch (err) {
61
- if (err.stderr.indexOf('not found') === 0) {
62
- console.error(`Failed to kill process ${child.pid}`)
63
- console.error(err)
64
- }
65
- }
66
- }
67
- }
@@ -1,126 +0,0 @@
1
- import { start, cliPath } from './helper.mjs'
2
- import { test } from 'tap'
3
- import { join } from 'desm'
4
- import { request } from 'undici'
5
- import { execa } from 'execa'
6
-
7
- test('autostart', async ({ equal, same, match, teardown }) => {
8
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
9
-
10
- const res = await request(`${url}`)
11
- equal(res.statusCode, 200)
12
- const body = await res.body.json()
13
- match(body, {
14
- hello: 'world'
15
- }, 'response')
16
-
17
- child.kill('SIGINT')
18
- })
19
-
20
- test('start command', async ({ equal, same, match, teardown }) => {
21
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'platformatic.service.json')])
22
-
23
- const res = await request(`${url}`)
24
- equal(res.statusCode, 200)
25
- const body = await res.body.json()
26
- match(body, {
27
- hello: 'world'
28
- }, 'response')
29
-
30
- child.kill('SIGINT')
31
- })
32
-
33
- test('allow custom env properties', async ({ equal, same, match, teardown }) => {
34
- const { child, url } = await start(
35
- [
36
- '-c', join(import.meta.url, '..', 'fixtures', 'custom-port-placeholder.json'),
37
- '--allow-env', 'A_CUSTOM_PORT'
38
- ],
39
- {
40
- env: {
41
- A_CUSTOM_PORT: '11111'
42
- }
43
- }
44
- )
45
- equal(url, 'http://127.0.0.1:11111', 'A_CUSTOM_PORT env variable has been used')
46
- const res = await request(`${url}`)
47
- equal(res.statusCode, 200)
48
- const body = await res.body.json()
49
- match(body, {}, 'response')
50
-
51
- child.kill('SIGINT')
52
- delete process.env.A_CUSTOM_PORT
53
- })
54
-
55
- test('use default env variables names', async ({ equal, match }) => {
56
- const { child, url } = await start(
57
- [
58
- '-c', join(import.meta.url, '..', 'fixtures', 'default-env-var-names.json')
59
- ],
60
- {
61
- env: {
62
- PORT: '11111',
63
- HOSTNAME: '127.0.0.1'
64
- }
65
- }
66
- )
67
-
68
- equal(url, 'http://127.0.0.1:11111', 'default env variable names has been used')
69
- const res = await request(`${url}`)
70
- equal(res.statusCode, 200)
71
- const body = await res.body.json()
72
- match(body, {}, 'response')
73
-
74
- child.kill('SIGINT')
75
- delete process.env.A_CUSTOM_PORT
76
- })
77
-
78
- test('default logger', async ({ equal, same, match, teardown }) => {
79
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'hello', 'no-server-logger.json')])
80
- match(url, /http:\/\/127.0.0.1:[0-9]+/)
81
- child.kill('SIGINT')
82
- })
83
-
84
- test('plugin options', async ({ equal, same, match, teardown }) => {
85
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'options', 'platformatic.service.yml')])
86
- const res = await request(`${url}`)
87
- equal(res.statusCode, 200)
88
- const body = await res.body.json()
89
- match(body, {
90
- something: 'else'
91
- }, 'response')
92
-
93
- child.kill('SIGINT')
94
- })
95
-
96
- test('https embedded pem', async ({ equal, same, match, teardown }) => {
97
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'https', 'embedded-pem.json')])
98
-
99
- match(url, /https:\/\//)
100
- const res = await request(`${url}`)
101
- equal(res.statusCode, 200)
102
- const body = await res.body.json()
103
- match(body, {
104
- hello: 'world'
105
- }, 'response')
106
-
107
- child.kill('SIGINT')
108
- })
109
-
110
- test('https pem path', async ({ equal, same, match, teardown }) => {
111
- const { child, url } = await start(['-c', join(import.meta.url, '..', '..', 'fixtures', 'https', 'pem-path.json')])
112
-
113
- match(url, /https:\/\//)
114
- const res = await request(`${url}`)
115
- equal(res.statusCode, 200)
116
- const body = await res.body.json()
117
- match(body, {
118
- hello: 'world'
119
- }, 'response')
120
-
121
- child.kill('SIGINT')
122
- })
123
-
124
- test('not load', async ({ rejects }) => {
125
- await rejects(execa('node', [cliPath, 'start', '-c', join(import.meta.url, '..', 'fixtures', 'not-load.service.json')]))
126
- })
File without changes
@@ -1,33 +0,0 @@
1
- import { cliPath } from './helper.mjs'
2
- import { test } from 'tap'
3
- import { join } from 'desm'
4
- import { readFile } from 'fs/promises'
5
- import { execa } from 'execa'
6
- import stripAnsi from 'strip-ansi'
7
-
8
- const version = JSON.parse(await readFile(join(import.meta.url, '..', '..', 'package.json'))).version
9
-
10
- test('version', async (t) => {
11
- const { stdout } = await execa('node', [cliPath, '--version'])
12
- t.ok(stdout.includes('v' + version))
13
- })
14
-
15
- test('missing config', async (t) => {
16
- await t.rejects(execa('node', [cliPath, 'start']))
17
- })
18
-
19
- test('print validation errors', async ({ equal, plan }) => {
20
- plan(2)
21
- try {
22
- await execa('node', [cliPath, 'start', '--config', join(import.meta.url, '..', 'fixtures', 'missing-property.config.json')])
23
- } catch (err) {
24
- equal(err.exitCode, 1)
25
- equal(stripAnsi(err.stdout), `
26
- ┌─────────┬──────┬─────────────────────────────────────────────────────────────────────┐
27
- │ (index) │ path │ message │
28
- ├─────────┼──────┼─────────────────────────────────────────────────────────────────────┤
29
- │ 0 │ '/' │ \`must have required property 'server' {"missingProperty":"server"}\` │
30
- └─────────┴──────┴─────────────────────────────────────────────────────────────────────┘
31
- `.trim())
32
- }
33
- })