@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,532 +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('start command should not compile typescript if `typescript` is false', async (t) => {
226
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
227
- const cwd = await getCWD(t)
228
-
229
- await cp(testDir, cwd, { recursive: true })
230
-
231
- const child = execa('node', [cliPath, 'start'], { cwd })
232
- t.teardown(exitOnTeardown(child))
233
-
234
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
235
- try {
236
- await access(jsPluginPath)
237
- t.fail("should not have created 'dist/plugin.js'")
238
- } catch (err) {
239
- // cannot start because the plugin is not compiled
240
- t.equal(err.code, 'ENOENT')
241
- t.equal(err.path, jsPluginPath)
242
- t.pass()
243
- }
244
- })
245
-
246
- t.test('should compile typescript plugin with start command with different cwd', async (t) => {
247
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
248
- const dest = path.join(urlDirname(import.meta.url), '..', 'tmp', `typescript-plugin-clone-${count++}`)
249
-
250
- await cp(testDir, dest, { recursive: true })
251
-
252
- const child = execa('node', [cliPath, 'start', '-c', path.join(dest, 'platformatic.service.json')])
253
-
254
- t.teardown(exitOnTeardown(child))
255
-
256
- const splitter = split()
257
- child.stdout.pipe(splitter)
258
- child.stderr.pipe(process.stderr)
259
-
260
- for await (const data of splitter) {
261
- const sanitized = stripAnsi(data)
262
- if (sanitized.includes('Typescript plugin loaded')) {
263
- t.pass()
264
- return
265
- }
266
- }
267
- t.fail('should compile typescript plugin with start command')
268
- })
269
-
270
- t.test('valid tsconfig file inside an inner folder', { skip: isWin }, async (t) => {
271
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
272
- const cwd = await getCWD(t)
273
-
274
- await cp(testDir, cwd, { recursive: true })
275
-
276
- try {
277
- await execa('node', [cliPath, 'compile'], { cwd, stdio: 'inherit' })
278
- } catch (err) {
279
- t.fail('should not catch any error')
280
- }
281
-
282
- t.pass()
283
- })
284
-
285
- t.test('should compile typescript plugin with start command from a folder', async (t) => {
286
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-autoload')
287
- const cwd = await getCWD(t)
288
-
289
- await cp(testDir, cwd, { recursive: true })
290
-
291
- const child = execa('node', [cliPath, 'start'], { cwd })
292
-
293
- t.teardown(exitOnTeardown(child))
294
-
295
- const splitter = split()
296
- child.stdout.pipe(splitter)
297
-
298
- for await (const data of splitter) {
299
- const sanitized = stripAnsi(data)
300
- if (sanitized.includes('Typescript plugin loaded')) {
301
- t.pass()
302
- return
303
- }
304
- }
305
- t.fail('should compile typescript plugin with start command')
306
- })
307
-
308
- t.test('should start the service if it was precompiled and typescript is `false`', async (t) => {
309
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
310
- const cwd = await getCWD(t)
311
-
312
- await cp(testDir, cwd, { recursive: true })
313
-
314
- await execa('node', [cliPath, 'compile'], { cwd })
315
-
316
- const child = execa('node', [cliPath, 'start'], { cwd })
317
-
318
- const splitter = split()
319
- child.stdout.pipe(splitter)
320
-
321
- for await (const data of splitter) {
322
- const sanitized = stripAnsi(data)
323
- if (sanitized.includes('Typescript plugin loaded')) {
324
- t.pass()
325
- return
326
- }
327
- }
328
- t.fail('should load the typescript plugin without compiling it')
329
- })
330
-
331
- t.test('should not start the service if it was not precompiled and typescript is `false`', async (t) => {
332
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
333
- const cwd = await getCWD(t)
334
-
335
- await cp(testDir, cwd, { recursive: true })
336
-
337
- const child = execa('node', [cliPath, 'start'], { cwd })
338
-
339
- const splitter = split()
340
- child.stdout.pipe(splitter)
341
- child.stderr.pipe(splitter)
342
-
343
- for await (const data of splitter) {
344
- const sanitized = stripAnsi(data)
345
- if (sanitized.includes('Unknown file extension ".ts" for')) {
346
- t.pass()
347
- return
348
- }
349
- }
350
- t.fail('should load the typescript plugin without compiling it')
351
- })
352
-
353
- t.test('should compile typescript plugin with string config', async (t) => {
354
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-string')
355
- const cwd = await getCWD(t)
356
-
357
- await cp(testDir, cwd, { recursive: true })
358
-
359
- const child = execa('node', [cliPath, 'compile'], { cwd })
360
-
361
- t.teardown(exitOnTeardown(child))
362
-
363
- const splitter = split()
364
- child.stdout.pipe(splitter)
365
-
366
- for await (const data of splitter) {
367
- const sanitized = stripAnsi(data)
368
- if (sanitized.includes('Typescript compilation completed successfully.')) {
369
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
370
- try {
371
- await access(jsPluginPath)
372
- } catch (err) {
373
- t.fail(err)
374
- }
375
-
376
- t.pass()
377
- return
378
- }
379
- }
380
- t.fail('should compile typescript plugin with a compile command')
381
- })
382
-
383
- t.test('should not start the service if it was not precompiled and typescript is `"false"`', async (t) => {
384
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
385
- const cwd = await getCWD(t)
386
-
387
- await cp(testDir, cwd, { recursive: true })
388
-
389
- const child = execa('node', [cliPath, 'start'], { cwd })
390
-
391
- const splitter = split()
392
- child.stdout.pipe(splitter)
393
- child.stderr.pipe(splitter)
394
-
395
- for await (const data of splitter) {
396
- const sanitized = stripAnsi(data)
397
- if (sanitized.includes('Unknown file extension ".ts" for')) {
398
- t.pass()
399
- return
400
- }
401
- }
402
- t.fail('should load the typescript plugin without compiling it')
403
- })
404
-
405
- t.test('should not compile bad typescript plugin', async (t) => {
406
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
407
- const cwd = await getCWD(t)
408
- await cp(testDir, cwd, { recursive: true })
409
-
410
- try {
411
- await execa('node', [cliPath, 'compile'], { cwd })
412
- t.fail('should not compile bad typescript plugin')
413
- } catch (err) {
414
- t.comment(err.stdout)
415
- t.comment(err.stderr)
416
- t.equal(err.stdout.includes('Found 1 error in plugin.ts'), true)
417
- }
418
-
419
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
420
- try {
421
- await access(jsPluginPath)
422
- t.fail('should not compile bad typescript plugin')
423
- } catch (err) {
424
- t.pass(err)
425
- }
426
- })
427
-
428
- t.test('missing tsconfig file', async (t) => {
429
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
430
- const cwd = await getCWD(t)
431
-
432
- await cp(testDir, cwd, { recursive: true })
433
-
434
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
435
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
436
-
437
- await rename(pathToTSConfig, pathToTSConfigBackup)
438
-
439
- try {
440
- await execa('node', [cliPath, 'compile'], { cwd })
441
- t.fail('should not compile typescript plugin')
442
- } catch (err) {
443
- t.comment(err.stdout)
444
- t.comment(err.stderr)
445
- t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
446
- }
447
-
448
- t.pass()
449
- })
450
-
451
- t.test('start command should not compile typescript plugin with errors', async (t) => {
452
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'bad-typescript-plugin')
453
- const cwd = await getCWD(t)
454
- await cp(testDir, cwd, { recursive: true })
455
-
456
- const childProcess = execa('node', [cliPath, 'start'], { cwd })
457
-
458
- t.teardown(exitOnTeardown(childProcess))
459
-
460
- try {
461
- await childProcess
462
- t.fail('should not compile bad typescript plugin')
463
- } catch (err) {
464
- if (!err.stdout.includes('Found 1 error')) {
465
- t.comment(err.stdout)
466
- t.comment(err.stderr)
467
- console.error(err)
468
- t.fail('should throw one ts error')
469
- }
470
- safeKill(childProcess)
471
- }
472
-
473
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
474
- try {
475
- await access(jsPluginPath)
476
- t.fail('should not compile bad typescript plugin')
477
- } catch (err) {
478
- t.pass(err)
479
- }
480
- })
481
-
482
- t.test('should not compile typescript plugin with start without tsconfig', async (t) => {
483
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
484
- const cwd = await getCWD(t)
485
-
486
- await cp(testDir, cwd, { recursive: true })
487
-
488
- const pathToTSConfig = path.join(cwd, 'tsconfig.json')
489
- const pathToTSConfigBackup = path.join(cwd, 'tsconfig.json.backup')
490
-
491
- await rename(pathToTSConfig, pathToTSConfigBackup)
492
-
493
- try {
494
- const child = await execa('node', [cliPath, 'start'], { cwd })
495
- t.teardown(exitOnTeardown(child))
496
- t.fail('should not compile typescript plugin with start without tsconfig')
497
- } catch (err) {
498
- t.comment(err.stdout)
499
- t.equal(err.stdout.includes('No typescript configuration file was found, skipping compilation.'), true)
500
- }
501
- })
502
-
503
- t.test('should compile ts app with config', async (t) => {
504
- const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'hello-ts-with-config')
505
- const cwd = await getCWD(t)
506
-
507
- await cp(testDir, cwd, { recursive: true })
508
-
509
- const child = execa('node', [cliPath, 'compile'], { cwd })
510
-
511
- t.teardown(exitOnTeardown(child))
512
-
513
- const splitter = split()
514
- child.stdout.pipe(splitter)
515
-
516
- for await (const data of splitter) {
517
- const sanitized = stripAnsi(data)
518
- if (sanitized.includes('Typescript compilation completed successfully.')) {
519
- const jsPluginPath = path.join(cwd, 'dist', 'plugin.js')
520
- try {
521
- await access(jsPluginPath)
522
- } catch (err) {
523
- t.fail(err)
524
- }
525
-
526
- t.pass()
527
- return
528
- }
529
- }
530
-
531
- t.fail('should compile typescript plugin with a compile command')
532
- })