@platformatic/service 0.46.1 → 0.47.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.
Files changed (125) hide show
  1. package/.c8rc +6 -0
  2. package/config.d.ts +0 -1
  3. package/index.d.ts +25 -0
  4. package/index.js +1 -0
  5. package/index.test-d.ts +24 -1
  6. package/lib/schema.js +0 -3
  7. package/package.json +9 -7
  8. package/fixtures/hello/no-server-logger.json +0 -13
  9. package/fixtures/hello/platformatic.service.json +0 -18
  10. package/fixtures/hello/plugin.js +0 -7
  11. package/fixtures/hello/warn-log.service.json +0 -18
  12. package/fixtures/hello-client/hello/hello.cjs +0 -21
  13. package/fixtures/hello-client/hello/hello.d.ts +0 -34
  14. package/fixtures/hello-client/hello/hello.openapi.json +0 -22
  15. package/fixtures/hello-client/hello/package.json +0 -5
  16. package/fixtures/hello-client/platformatic.service.json +0 -19
  17. package/fixtures/hello-client/plugin.js +0 -8
  18. package/fixtures/hello-client-ts/hello/hello.cjs +0 -21
  19. package/fixtures/hello-client-ts/hello/hello.d.ts +0 -34
  20. package/fixtures/hello-client-ts/hello/hello.openapi.json +0 -22
  21. package/fixtures/hello-client-ts/hello/package.json +0 -5
  22. package/fixtures/hello-client-ts/platformatic.service.json +0 -21
  23. package/fixtures/hello-client-ts/plugin.ts +0 -8
  24. package/fixtures/hello-client-ts/tsconfig.json +0 -23
  25. package/fixtures/hello-client-ts-without-deps/hello.d.ts +0 -34
  26. package/fixtures/hello-client-ts-without-deps/hello.openapi.json +0 -22
  27. package/fixtures/hello-client-ts-without-deps/platformatic.service.json +0 -23
  28. package/fixtures/hello-client-ts-without-deps/plugin.ts +0 -8
  29. package/fixtures/hello-client-ts-without-deps/tsconfig.json +0 -22
  30. package/fixtures/hello-client-without-deps/hello.d.ts +0 -34
  31. package/fixtures/hello-client-without-deps/hello.openapi.json +0 -22
  32. package/fixtures/hello-client-without-deps/platformatic.service.json +0 -21
  33. package/fixtures/hello-client-without-deps/plugin.js +0 -8
  34. package/fixtures/https/embedded-pem.json +0 -20
  35. package/fixtures/https/https.crt +0 -25
  36. package/fixtures/https/https.key +0 -27
  37. package/fixtures/https/pem-path.json +0 -20
  38. package/fixtures/https/plugin.js +0 -7
  39. package/fixtures/options/platformatic.service.yml +0 -9
  40. package/fixtures/options/plugin.js +0 -7
  41. package/test/autoload.test.js +0 -486
  42. package/test/cli/compile-1.test.mjs +0 -352
  43. package/test/cli/compile-2.test.mjs +0 -310
  44. package/test/cli/gen-schema.test.mjs +0 -44
  45. package/test/cli/gen-types.test.mjs +0 -30
  46. package/test/cli/helper.mjs +0 -67
  47. package/test/cli/start.test.mjs +0 -126
  48. package/test/cli/tap-parallel-not-ok +0 -0
  49. package/test/cli/validations.test.mjs +0 -33
  50. package/test/clients.test.js +0 -87
  51. package/test/config.test.js +0 -316
  52. package/test/cors.test.js +0 -291
  53. package/test/fixtures/bad-typescript-plugin/platformatic.service.json +0 -16
  54. package/test/fixtures/bad-typescript-plugin/plugin.ts +0 -5
  55. package/test/fixtures/bad-typescript-plugin/tsconfig.json +0 -22
  56. package/test/fixtures/custom-port-placeholder.json +0 -10
  57. package/test/fixtures/default-env-var-names.json +0 -7
  58. package/test/fixtures/directories/platformatic.service.json +0 -13
  59. package/test/fixtures/directories/plugins/decorator.js +0 -7
  60. package/test/fixtures/directories/routes/foo/bar.js +0 -11
  61. package/test/fixtures/directories/routes/foo/baz/index.js +0 -7
  62. package/test/fixtures/directories/routes/foo/baz/index2.js +0 -11
  63. package/test/fixtures/directories/routes/oof/auto.hooks.js +0 -5
  64. package/test/fixtures/directories/routes/oof/index.js +0 -7
  65. package/test/fixtures/directories/routes/root.js +0 -7
  66. package/test/fixtures/hello-ts-with-config/global.d.ts +0 -8
  67. package/test/fixtures/hello-ts-with-config/platformatic.service.json +0 -16
  68. package/test/fixtures/hello-ts-with-config/plugin.ts +0 -8
  69. package/test/fixtures/hello-ts-with-config/tsconfig.json +0 -23
  70. package/test/fixtures/hello-world-resolver.js +0 -16
  71. package/test/fixtures/missing-property.config.json +0 -1
  72. package/test/fixtures/nested-directories/modules/catalogue/index.js +0 -11
  73. package/test/fixtures/nested-directories/modules/catalogue/routes/products.js +0 -14
  74. package/test/fixtures/nested-directories/modules/inventory/index.js +0 -33
  75. package/test/fixtures/nested-directories/modules/inventory/routes/product.js +0 -15
  76. package/test/fixtures/nested-directories/package.json +0 -3
  77. package/test/fixtures/nested-directories/platformatic.service.json +0 -23
  78. package/test/fixtures/nested-directories/plugins/decorator.js +0 -3
  79. package/test/fixtures/nested-directories/plugins/handlers.js +0 -17
  80. package/test/fixtures/not-load.js +0 -8
  81. package/test/fixtures/not-load.service.json +0 -13
  82. package/test/fixtures/other-side.js +0 -9
  83. package/test/fixtures/request-id.js +0 -9
  84. package/test/fixtures/root-endpoint-plugin.js +0 -8
  85. package/test/fixtures/throw-resolver.js +0 -16
  86. package/test/fixtures/typescript-autoload/platformatic.service.json +0 -16
  87. package/test/fixtures/typescript-autoload/routes/plugin.ts +0 -5
  88. package/test/fixtures/typescript-autoload/tsconfig.json +0 -22
  89. package/test/fixtures/typescript-compiled/compiled/plugin.js +0 -6
  90. package/test/fixtures/typescript-compiled/platformatic.service.json +0 -18
  91. package/test/fixtures/typescript-plugin/platformatic.service.json +0 -16
  92. package/test/fixtures/typescript-plugin/plugin.ts +0 -5
  93. package/test/fixtures/typescript-plugin/tsconfig.json +0 -22
  94. package/test/fixtures/typescript-plugin-custom-flags/platformatic.service.json +0 -18
  95. package/test/fixtures/typescript-plugin-custom-flags/plugin.ts +0 -5
  96. package/test/fixtures/typescript-plugin-custom-flags/tsconfig.json +0 -22
  97. package/test/fixtures/typescript-plugin-custom-tsconfig/a-config-for-ts.json +0 -22
  98. package/test/fixtures/typescript-plugin-custom-tsconfig/platformatic.service.json +0 -18
  99. package/test/fixtures/typescript-plugin-custom-tsconfig/plugin.ts +0 -5
  100. package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +0 -16
  101. package/test/fixtures/typescript-plugin-nocompile/plugin.ts +0 -5
  102. package/test/fixtures/typescript-plugin-nocompile/tsconfig.json +0 -22
  103. package/test/fixtures/typescript-plugin-nocompile-enabled/platformatic.service.json +0 -18
  104. package/test/fixtures/typescript-plugin-nocompile-enabled/plugin.ts +0 -5
  105. package/test/fixtures/typescript-plugin-nocompile-enabled/tsconfig.json +0 -22
  106. package/test/fixtures/typescript-plugin-nocompile-string/platformatic.service.json +0 -16
  107. package/test/fixtures/typescript-plugin-nocompile-string/plugin.ts +0 -5
  108. package/test/fixtures/typescript-plugin-nocompile-string/tsconfig.json +0 -22
  109. package/test/fixtures/typescript-plugin-string/platformatic.service.json +0 -16
  110. package/test/fixtures/typescript-plugin-string/plugin.ts +0 -5
  111. package/test/fixtures/typescript-plugin-string/tsconfig.json +0 -22
  112. package/test/fixtures/undici-plugin.js +0 -15
  113. package/test/graphql.test.js +0 -219
  114. package/test/healthcheck.test.js +0 -92
  115. package/test/helper.js +0 -30
  116. package/test/https.test.js +0 -64
  117. package/test/lambda.test.js +0 -103
  118. package/test/load-and-reload-files.test.js +0 -180
  119. package/test/load-plugin.test.js +0 -67
  120. package/test/metrics.test.js +0 -220
  121. package/test/routes.test.js +0 -230
  122. package/test/schema.test.js +0 -12
  123. package/test/tap-parallel-ok +0 -0
  124. package/test/telemetry.test.js +0 -87
  125. package/test/utils.test.js +0 -37
@@ -1,352 +0,0 @@
1
- import path from 'path'
2
- import os from 'os'
3
- import { access, rename, 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
- const isWin = os.platform() === 'win32'
13
-
14
- if (!isWin) {
15
- t.jobs = 5
16
- }
17
- t.setTimeout(360000)
18
-
19
- function urlDirname (url) {
20
- return path.dirname(fileURLToPath(url))
21
- }
22
-
23
- async function getCWD (t) {
24
- const dir = path.join(urlDirname(import.meta.url), '..', 'tmp', `typescript-plugin-clone-${count++}`)
25
- try {
26
- await rm(dir, { recursive: true })
27
- } catch {}
28
-
29
- await mkdir(dir, { recursive: true })
30
-
31
- t.teardown(async () => {
32
- try {
33
- await rm(dir, { recursive: true })
34
- } catch {}
35
- })
36
- return dir
37
- }
38
-
39
- function exitOnTeardown (child) {
40
- return async () => {
41
- await safeKill(child)
42
- }
43
- }
44
-
45
- t.test('should compile typescript plugin', async (t) => {
46
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
47
- const cwd = await getCWD(t)
48
-
49
- await cp(testDir, cwd, { recursive: true })
50
-
51
- const child = execa('node', [cliPath, 'compile'], { cwd })
52
-
53
- t.teardown(exitOnTeardown(child))
54
-
55
- const splitter = split()
56
- child.stdout.pipe(splitter)
57
-
58
- for await (const data of splitter) {
59
- const sanitized = stripAnsi(data)
60
- if (sanitized.includes('Typescript compilation completed successfully.')) {
61
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
62
- try {
63
- await access(jsPluginPath)
64
- } catch (err) {
65
- t.fail(err)
66
- }
67
-
68
- t.pass()
69
- return
70
- }
71
- }
72
- t.fail('should compile typescript plugin with a compile command')
73
- })
74
-
75
- t.test('should compile typescript plugin even if typescript is `false`', async (t) => {
76
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
77
- const cwd = await getCWD(t)
78
-
79
- await cp(testDir, cwd, { recursive: true })
80
-
81
- const child = execa('node', [cliPath, 'compile'], { cwd })
82
-
83
- t.teardown(exitOnTeardown(child))
84
-
85
- const splitter = split()
86
- child.stdout.pipe(splitter)
87
-
88
- for await (const data of splitter) {
89
- const sanitized = stripAnsi(data)
90
- if (sanitized.includes('Typescript compilation completed successfully.')) {
91
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
92
- try {
93
- await access(jsPluginPath)
94
- } catch (err) {
95
- t.fail(err)
96
- }
97
-
98
- t.pass()
99
- return
100
- }
101
- }
102
- t.fail('should compile typescript plugin with a compile command')
103
- })
104
-
105
- t.test('should compile typescript plugin with start command', async (t) => {
106
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
107
- const cwd = await getCWD(t)
108
-
109
- await cp(testDir, cwd, { recursive: true })
110
-
111
- const child = execa('node', [cliPath, 'start'], { cwd })
112
-
113
- const splitter = split()
114
- child.stdout.pipe(splitter)
115
-
116
- for await (const data of splitter) {
117
- const sanitized = stripAnsi(data)
118
- if (sanitized.includes('Typescript plugin loaded')) {
119
- t.pass()
120
- return
121
- }
122
- }
123
- t.fail('should compile typescript plugin with start command')
124
- })
125
-
126
- t.test('should not compile bad typescript plugin', async (t) => {
127
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
128
- const cwd = await getCWD(t)
129
- await cp(testDir, cwd, { recursive: true })
130
-
131
- try {
132
- await execa('node', [cliPath, 'compile'], { cwd })
133
- t.fail('should not compile bad typescript plugin')
134
- } catch (err) {
135
- t.comment(err.stdout)
136
- t.comment(err.stderr)
137
- t.equal(err.stdout.includes('Found 1 error in plugin.ts'), true)
138
- }
139
-
140
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
141
- try {
142
- await access(jsPluginPath)
143
- t.fail('should not compile bad typescript plugin')
144
- } catch (err) {
145
- t.pass(err)
146
- }
147
- })
148
-
149
- t.test('missing tsconfig file', async (t) => {
150
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
151
- const cwd = await getCWD(t)
152
-
153
- await cp(testDir, cwd, { recursive: true })
154
-
155
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
156
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
157
-
158
- await rename(pathToTSConfig, pathToTSConfigBackup)
159
-
160
- try {
161
- await execa('node', [cliPath, 'compile'], { cwd })
162
- t.fail('should not compile typescript plugin')
163
- } catch (err) {
164
- t.comment(err.stdout)
165
- t.comment(err.stderr)
166
- t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
167
- }
168
-
169
- t.pass()
170
- })
171
-
172
- t.test('start command should not compile typescript plugin with errors', async (t) => {
173
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
174
- const cwd = await getCWD(t)
175
-
176
- await cp(testDir, cwd, { recursive: true })
177
-
178
- const childProcess = execa('node', [cliPath, 'start'], { cwd })
179
-
180
- t.teardown(exitOnTeardown(childProcess))
181
-
182
- try {
183
- await childProcess
184
- t.fail('should not compile bad typescript plugin')
185
- } catch (err) {
186
- if (!err.stdout.includes('Found 1 error')) {
187
- t.comment(err.stdout)
188
- t.comment(err.stderr)
189
- console.error(err)
190
- t.fail('should throw one ts error')
191
- }
192
- await safeKill(childProcess)
193
- }
194
-
195
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
196
- try {
197
- await access(jsPluginPath)
198
- t.fail('should not compile bad typescript plugin')
199
- } catch (err) {
200
- t.pass(err)
201
- }
202
- })
203
-
204
- t.test('should not compile typescript plugin with start without tsconfig', async (t) => {
205
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
206
- const cwd = await getCWD(t)
207
-
208
- await cp(testDir, cwd, { recursive: true })
209
-
210
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
211
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
212
-
213
- await rename(pathToTSConfig, pathToTSConfigBackup)
214
-
215
- try {
216
- const child = await execa('node', [cliPath, 'start'], { cwd })
217
- t.teardown(exitOnTeardown(child))
218
- t.fail('should not compile typescript plugin with start without tsconfig')
219
- } catch (err) {
220
- t.comment(err.stdout)
221
- t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
222
- }
223
- })
224
-
225
- t.test('should not compile bad typescript plugin', async (t) => {
226
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
227
- const cwd = await getCWD(t)
228
- await cp(testDir, cwd, { recursive: true })
229
-
230
- try {
231
- await execa('node', [cliPath, 'compile'], { cwd })
232
- t.fail('should not compile bad typescript plugin')
233
- } catch (err) {
234
- t.comment(err.stdout)
235
- t.comment(err.stderr)
236
- t.equal(err.stdout.includes('Found 1 error in plugin.ts'), true)
237
- }
238
-
239
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
240
- try {
241
- await access(jsPluginPath)
242
- t.fail('should not compile bad typescript plugin')
243
- } catch (err) {
244
- t.pass(err)
245
- }
246
- })
247
-
248
- t.test('missing tsconfig file', async (t) => {
249
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
250
- const cwd = await getCWD(t)
251
-
252
- await cp(testDir, cwd, { recursive: true })
253
-
254
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
255
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
256
-
257
- await rename(pathToTSConfig, pathToTSConfigBackup)
258
-
259
- try {
260
- await execa('node', [cliPath, 'compile'], { cwd })
261
- t.fail('should not compile typescript plugin')
262
- } catch (err) {
263
- t.comment(err.stdout)
264
- t.comment(err.stderr)
265
- t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
266
- }
267
-
268
- t.pass()
269
- })
270
-
271
- t.test('start command should not compile typescript plugin with errors', async (t) => {
272
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
273
- const cwd = await getCWD(t)
274
- await cp(testDir, cwd, { recursive: true })
275
-
276
- const childProcess = execa('node', [cliPath, 'start'], { cwd })
277
-
278
- t.teardown(exitOnTeardown(childProcess))
279
-
280
- try {
281
- await childProcess
282
- t.fail('should not compile bad typescript plugin')
283
- } catch (err) {
284
- if (!err.stdout.includes('Found 1 error')) {
285
- t.comment(err.stdout)
286
- t.comment(err.stderr)
287
- console.error(err)
288
- t.fail('should throw one ts error')
289
- }
290
- safeKill(childProcess)
291
- }
292
-
293
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
294
- try {
295
- await access(jsPluginPath)
296
- t.fail('should not compile bad typescript plugin')
297
- } catch (err) {
298
- t.pass(err)
299
- }
300
- })
301
-
302
- t.test('should not compile typescript plugin with start without tsconfig', async (t) => {
303
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
304
- const cwd = await getCWD(t)
305
-
306
- await cp(testDir, cwd, { recursive: true })
307
-
308
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
309
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
310
-
311
- await rename(pathToTSConfig, pathToTSConfigBackup)
312
-
313
- try {
314
- const child = await execa('node', [cliPath, 'start'], { cwd })
315
- t.teardown(exitOnTeardown(child))
316
- t.fail('should not compile typescript plugin with start without tsconfig')
317
- } catch (err) {
318
- t.comment(err.stdout)
319
- t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
320
- }
321
- })
322
-
323
- t.test('should compile ts app with config', async (t) => {
324
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'hello-ts-with-config')
325
- const cwd = await getCWD(t)
326
-
327
- await cp(testDir, cwd, { recursive: true })
328
-
329
- const child = execa('node', [cliPath, 'compile'], { cwd })
330
-
331
- t.teardown(exitOnTeardown(child))
332
-
333
- const splitter = split()
334
- child.stdout.pipe(splitter)
335
-
336
- for await (const data of splitter) {
337
- const sanitized = stripAnsi(data)
338
- if (sanitized.includes('Typescript compilation completed successfully.')) {
339
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
340
- try {
341
- await access(jsPluginPath)
342
- } catch (err) {
343
- t.fail(err)
344
- }
345
-
346
- t.pass()
347
- return
348
- }
349
- }
350
-
351
- t.fail('should compile typescript plugin with a compile command')
352
- })
@@ -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
- })