create-fluxstack 1.0.13 → 1.0.14

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 (214) hide show
  1. package/.env.example +29 -29
  2. package/app/client/README.md +69 -69
  3. package/app/client/index.html +14 -13
  4. package/app/client/src/App.tsx +157 -524
  5. package/app/client/src/components/ErrorBoundary.tsx +107 -0
  6. package/app/client/src/components/ErrorDisplay.css +365 -0
  7. package/app/client/src/components/ErrorDisplay.tsx +258 -0
  8. package/app/client/src/components/FluxStackConfig.tsx +1321 -0
  9. package/app/client/src/components/HybridLiveCounter.tsx +140 -0
  10. package/app/client/src/components/LiveClock.tsx +286 -0
  11. package/app/client/src/components/MainLayout.tsx +390 -0
  12. package/app/client/src/components/SidebarNavigation.tsx +391 -0
  13. package/app/client/src/components/StateDemo.tsx +178 -0
  14. package/app/client/src/components/SystemMonitor.tsx +1038 -0
  15. package/app/client/src/components/Teste.tsx +104 -0
  16. package/app/client/src/components/UserProfile.tsx +809 -0
  17. package/app/client/src/hooks/useAuth.ts +39 -0
  18. package/app/client/src/hooks/useNotifications.ts +56 -0
  19. package/app/client/src/lib/eden-api.ts +189 -53
  20. package/app/client/src/lib/errors.ts +340 -0
  21. package/app/client/src/lib/hooks/useErrorHandler.ts +258 -0
  22. package/app/client/src/lib/index.ts +45 -0
  23. package/app/client/src/main.tsx +3 -2
  24. package/app/client/src/pages/ApiDocs.tsx +182 -0
  25. package/app/client/src/pages/Demo.tsx +174 -0
  26. package/app/client/src/pages/HybridLive.tsx +263 -0
  27. package/app/client/src/pages/Overview.tsx +155 -0
  28. package/app/client/src/store/README.md +43 -0
  29. package/app/client/src/store/index.ts +16 -0
  30. package/app/client/src/store/slices/uiSlice.ts +151 -0
  31. package/app/client/src/store/slices/userSlice.ts +161 -0
  32. package/app/client/src/test/README.md +257 -0
  33. package/app/client/src/test/setup.ts +70 -0
  34. package/app/client/src/test/types.ts +12 -0
  35. package/app/client/src/vite-env.d.ts +1 -1
  36. package/app/client/tsconfig.app.json +44 -43
  37. package/app/client/tsconfig.json +7 -7
  38. package/app/client/tsconfig.node.json +25 -25
  39. package/app/client/zustand-setup.md +65 -0
  40. package/app/server/controllers/users.controller.ts +68 -68
  41. package/app/server/index.ts +9 -1
  42. package/app/server/live/CounterComponent.ts +191 -0
  43. package/app/server/live/FluxStackConfig.ts +529 -0
  44. package/app/server/live/LiveClockComponent.ts +214 -0
  45. package/app/server/live/SidebarNavigation.ts +156 -0
  46. package/app/server/live/SystemMonitor.ts +594 -0
  47. package/app/server/live/SystemMonitorIntegration.ts +151 -0
  48. package/app/server/live/TesteComponent.ts +87 -0
  49. package/app/server/live/UserProfileComponent.ts +135 -0
  50. package/app/server/live/register-components.ts +28 -0
  51. package/app/server/middleware/auth.ts +136 -0
  52. package/app/server/middleware/errorHandling.ts +250 -0
  53. package/app/server/middleware/index.ts +10 -0
  54. package/app/server/middleware/rateLimit.ts +193 -0
  55. package/app/server/middleware/requestLogging.ts +215 -0
  56. package/app/server/middleware/validation.ts +270 -0
  57. package/app/server/routes/index.ts +14 -2
  58. package/app/server/routes/upload.ts +92 -0
  59. package/app/server/routes/users.routes.ts +2 -9
  60. package/app/server/services/NotificationService.ts +302 -0
  61. package/app/server/services/UserService.ts +222 -0
  62. package/app/server/services/index.ts +46 -0
  63. package/core/cli/commands/plugin-deps.ts +263 -0
  64. package/core/cli/generators/README.md +339 -0
  65. package/core/cli/generators/component.ts +770 -0
  66. package/core/cli/generators/controller.ts +299 -0
  67. package/core/cli/generators/index.ts +144 -0
  68. package/core/cli/generators/interactive.ts +228 -0
  69. package/core/cli/generators/prompts.ts +83 -0
  70. package/core/cli/generators/route.ts +513 -0
  71. package/core/cli/generators/service.ts +465 -0
  72. package/core/cli/generators/template-engine.ts +154 -0
  73. package/core/cli/generators/types.ts +71 -0
  74. package/core/cli/generators/utils.ts +192 -0
  75. package/core/cli/index.ts +69 -0
  76. package/core/cli/plugin-discovery.ts +16 -85
  77. package/core/client/fluxstack.ts +17 -0
  78. package/core/client/hooks/index.ts +7 -0
  79. package/core/client/hooks/state-validator.ts +130 -0
  80. package/core/client/hooks/useAuth.ts +49 -0
  81. package/core/client/hooks/useChunkedUpload.ts +258 -0
  82. package/core/client/hooks/useHybridLiveComponent.ts +967 -0
  83. package/core/client/hooks/useWebSocket.ts +373 -0
  84. package/core/client/index.ts +47 -0
  85. package/core/client/state/createStore.ts +193 -0
  86. package/core/client/state/index.ts +15 -0
  87. package/core/config/env-dynamic.ts +1 -1
  88. package/core/config/env.ts +2 -1
  89. package/core/config/runtime-config.ts +3 -3
  90. package/core/config/schema.ts +84 -49
  91. package/core/framework/server.ts +30 -0
  92. package/core/index.ts +25 -0
  93. package/core/live/ComponentRegistry.ts +399 -0
  94. package/core/live/types.ts +164 -0
  95. package/core/plugins/built-in/live-components/commands/create-live-component.ts +1201 -0
  96. package/core/plugins/built-in/live-components/index.ts +27 -0
  97. package/core/plugins/built-in/logger/index.ts +1 -1
  98. package/core/plugins/built-in/monitoring/index.ts +1 -1
  99. package/core/plugins/built-in/static/index.ts +1 -1
  100. package/core/plugins/built-in/swagger/index.ts +1 -1
  101. package/core/plugins/built-in/vite/index.ts +1 -1
  102. package/core/plugins/dependency-manager.ts +384 -0
  103. package/core/plugins/index.ts +5 -1
  104. package/core/plugins/manager.ts +7 -3
  105. package/core/plugins/registry.ts +88 -10
  106. package/core/plugins/types.ts +11 -11
  107. package/core/server/framework.ts +43 -0
  108. package/core/server/index.ts +11 -1
  109. package/core/server/live/ComponentRegistry.ts +1017 -0
  110. package/core/server/live/FileUploadManager.ts +272 -0
  111. package/core/server/live/LiveComponentPerformanceMonitor.ts +930 -0
  112. package/core/server/live/SingleConnectionManager.ts +0 -0
  113. package/core/server/live/StateSignature.ts +644 -0
  114. package/core/server/live/WebSocketConnectionManager.ts +688 -0
  115. package/core/server/live/websocket-plugin.ts +435 -0
  116. package/core/server/middleware/errorHandling.ts +141 -0
  117. package/core/server/middleware/index.ts +16 -0
  118. package/core/server/plugins/static-files-plugin.ts +232 -0
  119. package/core/server/services/BaseService.ts +95 -0
  120. package/core/server/services/ServiceContainer.ts +144 -0
  121. package/core/server/services/index.ts +9 -0
  122. package/core/templates/create-project.ts +46 -2
  123. package/core/testing/index.ts +10 -0
  124. package/core/testing/setup.ts +74 -0
  125. package/core/types/build.ts +38 -14
  126. package/core/types/types.ts +319 -0
  127. package/core/utils/env-runtime.ts +7 -0
  128. package/core/utils/errors/handlers.ts +264 -39
  129. package/core/utils/errors/index.ts +528 -18
  130. package/core/utils/errors/middleware.ts +114 -0
  131. package/core/utils/logger/formatters.ts +222 -0
  132. package/core/utils/logger/index.ts +167 -48
  133. package/core/utils/logger/middleware.ts +253 -0
  134. package/core/utils/logger/performance.ts +384 -0
  135. package/core/utils/logger/transports.ts +365 -0
  136. package/create-fluxstack.ts +296 -296
  137. package/fluxstack.config.ts +17 -1
  138. package/package-template.json +66 -66
  139. package/package.json +31 -6
  140. package/public/README.md +16 -0
  141. package/vite.config.ts +29 -14
  142. package/.claude/settings.local.json +0 -74
  143. package/.github/workflows/ci-build-tests.yml +0 -480
  144. package/.github/workflows/dependency-management.yml +0 -324
  145. package/.github/workflows/release-validation.yml +0 -355
  146. package/.kiro/specs/fluxstack-architecture-optimization/design.md +0 -700
  147. package/.kiro/specs/fluxstack-architecture-optimization/requirements.md +0 -127
  148. package/.kiro/specs/fluxstack-architecture-optimization/tasks.md +0 -330
  149. package/CLAUDE.md +0 -200
  150. package/Dockerfile +0 -58
  151. package/Dockerfile.backend +0 -52
  152. package/Dockerfile.frontend +0 -54
  153. package/README-Docker.md +0 -85
  154. package/ai-context/00-QUICK-START.md +0 -86
  155. package/ai-context/README.md +0 -88
  156. package/ai-context/development/eden-treaty-guide.md +0 -362
  157. package/ai-context/development/patterns.md +0 -382
  158. package/ai-context/development/plugins-guide.md +0 -572
  159. package/ai-context/examples/crud-complete.md +0 -626
  160. package/ai-context/project/architecture.md +0 -399
  161. package/ai-context/project/overview.md +0 -213
  162. package/ai-context/recent-changes/eden-treaty-refactor.md +0 -281
  163. package/ai-context/recent-changes/type-inference-fix.md +0 -223
  164. package/ai-context/reference/environment-vars.md +0 -384
  165. package/ai-context/reference/troubleshooting.md +0 -407
  166. package/app/client/src/components/TestPage.tsx +0 -453
  167. package/bun.lock +0 -1063
  168. package/bunfig.toml +0 -16
  169. package/core/__tests__/integration.test.ts +0 -227
  170. package/core/build/index.ts +0 -186
  171. package/core/config/__tests__/config-loader.test.ts +0 -554
  172. package/core/config/__tests__/config-merger.test.ts +0 -657
  173. package/core/config/__tests__/env-converter.test.ts +0 -372
  174. package/core/config/__tests__/env-processor.test.ts +0 -431
  175. package/core/config/__tests__/env.test.ts +0 -452
  176. package/core/config/__tests__/integration.test.ts +0 -418
  177. package/core/config/__tests__/loader.test.ts +0 -331
  178. package/core/config/__tests__/schema.test.ts +0 -129
  179. package/core/config/__tests__/validator.test.ts +0 -318
  180. package/core/framework/__tests__/server.test.ts +0 -233
  181. package/core/plugins/__tests__/built-in.test.ts.disabled +0 -366
  182. package/core/plugins/__tests__/manager.test.ts +0 -398
  183. package/core/plugins/__tests__/monitoring.test.ts +0 -401
  184. package/core/plugins/__tests__/registry.test.ts +0 -335
  185. package/core/utils/__tests__/errors.test.ts +0 -139
  186. package/core/utils/__tests__/helpers.test.ts +0 -297
  187. package/core/utils/__tests__/logger.test.ts +0 -141
  188. package/create-test-app.ts +0 -156
  189. package/docker-compose.microservices.yml +0 -75
  190. package/docker-compose.simple.yml +0 -57
  191. package/docker-compose.yml +0 -71
  192. package/eslint.config.js +0 -23
  193. package/flux-cli.ts +0 -214
  194. package/nginx-lb.conf +0 -37
  195. package/publish.sh +0 -63
  196. package/run-clean.ts +0 -26
  197. package/run-env-tests.ts +0 -313
  198. package/tailwind.config.js +0 -34
  199. package/tests/__mocks__/api.ts +0 -56
  200. package/tests/fixtures/users.ts +0 -69
  201. package/tests/integration/api/users.routes.test.ts +0 -221
  202. package/tests/setup.ts +0 -29
  203. package/tests/unit/app/client/App-simple.test.tsx +0 -56
  204. package/tests/unit/app/client/App.test.tsx.skip +0 -237
  205. package/tests/unit/app/client/eden-api.test.ts +0 -186
  206. package/tests/unit/app/client/simple.test.tsx +0 -23
  207. package/tests/unit/app/controllers/users.controller.test.ts +0 -150
  208. package/tests/unit/core/create-project.test.ts.skip +0 -95
  209. package/tests/unit/core/framework.test.ts +0 -144
  210. package/tests/unit/core/plugins/logger.test.ts.skip +0 -268
  211. package/tests/unit/core/plugins/vite.test.ts.disabled +0 -188
  212. package/tests/utils/test-helpers.ts +0 -61
  213. package/vitest.config.ts +0 -50
  214. package/workspace.json +0 -6
@@ -1,318 +0,0 @@
1
- /**
2
- * Tests for Configuration Validator
3
- */
4
-
5
- import { describe, it, expect } from 'vitest'
6
- import {
7
- validateConfig,
8
- validateConfigStrict,
9
- createEnvironmentValidator,
10
- validatePartialConfig,
11
- getConfigSuggestions
12
- } from '../validator'
13
- import { defaultFluxStackConfig } from '../schema'
14
- import type { FluxStackConfig } from '../schema'
15
-
16
- describe('Configuration Validator', () => {
17
- describe('validateConfig', () => {
18
- it('should validate default configuration successfully', () => {
19
- const result = validateConfig(defaultFluxStackConfig)
20
-
21
- expect(result.valid).toBe(true)
22
- expect(result.errors).toHaveLength(0)
23
- })
24
-
25
- it('should detect missing required properties', () => {
26
- const invalidConfig = {
27
- app: { name: 'test' }, // missing version
28
- server: defaultFluxStackConfig.server,
29
- client: defaultFluxStackConfig.client,
30
- build: defaultFluxStackConfig.build,
31
- plugins: defaultFluxStackConfig.plugins,
32
- logging: defaultFluxStackConfig.logging,
33
- monitoring: defaultFluxStackConfig.monitoring
34
- } as FluxStackConfig
35
-
36
- const result = validateConfig(invalidConfig)
37
-
38
- expect(result.valid).toBe(false)
39
- expect(result.errors.some(e => e.includes('version'))).toBe(true)
40
- })
41
-
42
- it('should detect invalid port numbers', () => {
43
- const invalidConfig = {
44
- ...defaultFluxStackConfig,
45
- server: {
46
- ...defaultFluxStackConfig.server,
47
- port: 70000 // Invalid port
48
- }
49
- }
50
-
51
- const result = validateConfig(invalidConfig)
52
-
53
- expect(result.valid).toBe(false)
54
- expect(result.errors.some(e => e.includes('port'))).toBe(true)
55
- })
56
-
57
- it('should detect port conflicts', () => {
58
- const conflictConfig = {
59
- ...defaultFluxStackConfig,
60
- server: { ...defaultFluxStackConfig.server, port: 3000 },
61
- client: { ...defaultFluxStackConfig.client, port: 3000 }
62
- }
63
-
64
- const result = validateConfig(conflictConfig)
65
-
66
- expect(result.valid).toBe(false)
67
- expect(result.errors.some(e => e.includes('different'))).toBe(true)
68
- })
69
-
70
- it('should warn about security issues', () => {
71
- const insecureConfig = {
72
- ...defaultFluxStackConfig,
73
- server: {
74
- ...defaultFluxStackConfig.server,
75
- cors: {
76
- ...defaultFluxStackConfig.server.cors,
77
- origins: ['*'],
78
- credentials: true
79
- }
80
- }
81
- }
82
-
83
- // Mock production environment
84
- const originalEnv = process.env.NODE_ENV
85
- process.env.NODE_ENV = 'production'
86
-
87
- const result = validateConfig(insecureConfig)
88
-
89
- expect(result.warnings.some(w => w.includes('wildcard'))).toBe(true)
90
-
91
- // Restore environment
92
- process.env.NODE_ENV = originalEnv
93
- })
94
-
95
- it('should validate enum values', () => {
96
- const invalidConfig = {
97
- ...defaultFluxStackConfig,
98
- logging: {
99
- ...defaultFluxStackConfig.logging,
100
- level: 'invalid' as any
101
- }
102
- }
103
-
104
- const result = validateConfig(invalidConfig)
105
-
106
- expect(result.valid).toBe(false)
107
- expect(result.errors.some(e => e.includes('one of'))).toBe(true)
108
- })
109
-
110
- it('should validate array constraints', () => {
111
- const invalidConfig = {
112
- ...defaultFluxStackConfig,
113
- server: {
114
- ...defaultFluxStackConfig.server,
115
- cors: {
116
- ...defaultFluxStackConfig.server.cors,
117
- origins: [] // Empty array
118
- }
119
- }
120
- }
121
-
122
- const result = validateConfig(invalidConfig)
123
-
124
- expect(result.valid).toBe(false)
125
- expect(result.errors.some(e => e.includes('at least'))).toBe(true)
126
- })
127
- })
128
-
129
- describe('validateConfigStrict', () => {
130
- it('should not throw for valid configuration', () => {
131
- expect(() => {
132
- validateConfigStrict(defaultFluxStackConfig)
133
- }).not.toThrow()
134
- })
135
-
136
- it('should throw for invalid configuration', () => {
137
- const invalidConfig = {
138
- ...defaultFluxStackConfig,
139
- app: { name: '' } // Invalid empty name
140
- } as FluxStackConfig
141
-
142
- expect(() => {
143
- validateConfigStrict(invalidConfig)
144
- }).toThrow()
145
- })
146
- })
147
-
148
- describe('createEnvironmentValidator', () => {
149
- it('should create production validator with additional checks', () => {
150
- const prodValidator = createEnvironmentValidator('production')
151
-
152
- const devConfig = {
153
- ...defaultFluxStackConfig,
154
- logging: { ...defaultFluxStackConfig.logging, level: 'debug' as const }
155
- }
156
-
157
- const result = prodValidator(devConfig)
158
-
159
- expect(result.warnings.some(w => w.includes('Debug logging'))).toBe(true)
160
- })
161
-
162
- it('should create development validator with build warnings', () => {
163
- const devValidator = createEnvironmentValidator('development')
164
-
165
- const prodConfig = {
166
- ...defaultFluxStackConfig,
167
- build: {
168
- ...defaultFluxStackConfig.build,
169
- optimization: {
170
- ...defaultFluxStackConfig.build.optimization,
171
- minify: true
172
- }
173
- }
174
- }
175
-
176
- const result = devValidator(prodConfig)
177
-
178
- expect(result.warnings.some(w => w.includes('Minification enabled'))).toBe(true)
179
- })
180
- })
181
-
182
- describe('validatePartialConfig', () => {
183
- it('should validate partial configuration against base', () => {
184
- const partialConfig = {
185
- server: {
186
- port: 4000,
187
- host: 'localhost',
188
- apiPrefix: '/api',
189
- cors: {
190
- origins: ['*'],
191
- methods: ['GET', 'POST'],
192
- headers: ['Content-Type'],
193
- credentials: false,
194
- maxAge: 86400
195
- },
196
- middleware: []
197
- }
198
- }
199
-
200
- const result = validatePartialConfig(partialConfig, defaultFluxStackConfig)
201
-
202
- expect(result.valid).toBe(true)
203
- })
204
-
205
- it('should detect conflicts in partial configuration', () => {
206
- const partialConfig = {
207
- server: {
208
- port: 70000, // Invalid port
209
- host: 'localhost',
210
- apiPrefix: '/api',
211
- cors: {
212
- origins: ['*'],
213
- methods: ['GET', 'POST'],
214
- headers: ['Content-Type'],
215
- credentials: false,
216
- maxAge: 86400
217
- },
218
- middleware: []
219
- }
220
- }
221
-
222
- const result = validatePartialConfig(partialConfig, defaultFluxStackConfig)
223
-
224
- expect(result.valid).toBe(false)
225
- })
226
- })
227
-
228
- describe('getConfigSuggestions', () => {
229
- it('should provide suggestions for improvement', () => {
230
- const basicConfig = {
231
- ...defaultFluxStackConfig,
232
- monitoring: { ...defaultFluxStackConfig.monitoring, enabled: false }
233
- }
234
-
235
- const suggestions = getConfigSuggestions(basicConfig)
236
-
237
- expect(suggestions.some(s => s.includes('monitoring'))).toBe(true)
238
- })
239
-
240
- it('should suggest database configuration', () => {
241
- const configWithoutDb = {
242
- ...defaultFluxStackConfig,
243
- database: undefined
244
- }
245
-
246
- const suggestions = getConfigSuggestions(configWithoutDb)
247
-
248
- expect(suggestions.some(s => s.includes('database'))).toBe(true)
249
- })
250
-
251
- it('should suggest plugin enablement', () => {
252
- const configWithoutPlugins = {
253
- ...defaultFluxStackConfig,
254
- plugins: { ...defaultFluxStackConfig.plugins, enabled: [] }
255
- }
256
-
257
- const suggestions = getConfigSuggestions(configWithoutPlugins)
258
-
259
- expect(suggestions.some(s => s.includes('plugins'))).toBe(true)
260
- })
261
- })
262
-
263
- describe('Business Logic Validation', () => {
264
- it('should validate plugin conflicts', () => {
265
- const conflictConfig = {
266
- ...defaultFluxStackConfig,
267
- plugins: {
268
- enabled: ['logger', 'cors'],
269
- disabled: ['logger'], // Conflict: logger is both enabled and disabled
270
- config: {}
271
- }
272
- }
273
-
274
- const result = validateConfig(conflictConfig)
275
-
276
- expect(result.warnings.some(w => w.includes('both enabled and disabled'))).toBe(true)
277
- })
278
-
279
- it('should validate authentication security', () => {
280
- const weakAuthConfig = {
281
- ...defaultFluxStackConfig,
282
- auth: {
283
- secret: 'short', // Too short
284
- expiresIn: '24h'
285
- }
286
- }
287
-
288
- const result = validateConfig(weakAuthConfig)
289
-
290
- expect(result.warnings.some(w => w.includes('too short'))).toBe(true)
291
- })
292
-
293
- it('should validate build optimization settings', () => {
294
- // Mock production environment
295
- const originalEnv = process.env.NODE_ENV
296
- process.env.NODE_ENV = 'production'
297
-
298
- const unoptimizedConfig = {
299
- ...defaultFluxStackConfig,
300
- build: {
301
- ...defaultFluxStackConfig.build,
302
- optimization: {
303
- ...defaultFluxStackConfig.build.optimization,
304
- minify: false,
305
- treeshake: false
306
- }
307
- }
308
- }
309
-
310
- const result = validateConfig(unoptimizedConfig)
311
-
312
- expect(result.warnings.some(w => w.includes('minification') || w.includes('tree-shaking'))).toBe(true)
313
-
314
- // Restore environment
315
- process.env.NODE_ENV = originalEnv
316
- })
317
- })
318
- })
@@ -1,233 +0,0 @@
1
- /**
2
- * Tests for FluxStack Framework Server
3
- */
4
-
5
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
6
- import { FluxStackFramework } from '../server'
7
- import type { Plugin } from '../../plugins/types'
8
-
9
- // Mock dependencies
10
- vi.mock('../../config', () => ({
11
- getConfigSync: vi.fn(() => ({
12
- server: {
13
- port: 3000,
14
- apiPrefix: '/api',
15
- cors: {
16
- origins: ['*'],
17
- methods: ['GET', 'POST'],
18
- headers: ['Content-Type'],
19
- credentials: false
20
- }
21
- },
22
- app: {
23
- name: 'test-app',
24
- version: '1.0.0'
25
- }
26
- })),
27
- getEnvironmentInfo: vi.fn(() => ({
28
- isDevelopment: true,
29
- isProduction: false,
30
- isTest: true,
31
- name: 'test'
32
- }))
33
- }))
34
-
35
- vi.mock('../../utils/logger', () => ({
36
- logger: {
37
- framework: vi.fn(),
38
- warn: vi.fn(),
39
- error: vi.fn(),
40
- child: vi.fn(() => ({
41
- framework: vi.fn(),
42
- warn: vi.fn(),
43
- error: vi.fn()
44
- }))
45
- }
46
- }))
47
-
48
- vi.mock('../../utils/errors/handlers', () => ({
49
- createErrorHandler: vi.fn(() => vi.fn())
50
- }))
51
-
52
- vi.mock('elysia', () => ({
53
- Elysia: vi.fn(() => ({
54
- onRequest: vi.fn().mockReturnThis(),
55
- onAfterHandle: vi.fn().mockReturnThis(),
56
- onError: vi.fn().mockReturnThis(),
57
- options: vi.fn().mockReturnThis(),
58
- use: vi.fn().mockReturnThis(),
59
- listen: vi.fn((_port, callback) => {
60
- if (callback) callback()
61
- })
62
- }))
63
- }))
64
-
65
- describe('FluxStackFramework', () => {
66
- let framework: FluxStackFramework
67
-
68
- beforeEach(() => {
69
- framework = new FluxStackFramework()
70
- })
71
-
72
- afterEach(() => {
73
- vi.clearAllMocks()
74
- })
75
-
76
- describe('Constructor', () => {
77
- it('should initialize framework with default config', () => {
78
- expect(framework).toBeInstanceOf(FluxStackFramework)
79
- expect(framework.getContext()).toBeDefined()
80
- expect(framework.getApp()).toBeDefined()
81
- expect(framework.getPluginRegistry()).toBeDefined()
82
- })
83
-
84
- it('should initialize framework with custom config', () => {
85
- const customConfig = {
86
- server: {
87
- port: 4000,
88
- host: 'localhost',
89
- apiPrefix: '/custom-api',
90
- cors: {
91
- origins: ['*'],
92
- methods: ['GET', 'POST'],
93
- headers: ['Content-Type'],
94
- credentials: false,
95
- maxAge: 86400
96
- },
97
- middleware: []
98
- }
99
- }
100
-
101
- const customFramework = new FluxStackFramework(customConfig)
102
- const context = customFramework.getContext()
103
-
104
- expect(context.config.server.port).toBe(4000)
105
- expect(context.config.server.apiPrefix).toBe('/custom-api')
106
- })
107
-
108
- it('should set up context correctly', () => {
109
- const context = framework.getContext()
110
-
111
- expect(context.isDevelopment).toBe(true)
112
- expect(context.isProduction).toBe(false)
113
- expect(context.isTest).toBe(true)
114
- expect(context.environment).toBe('test')
115
- })
116
- })
117
-
118
- describe('Plugin Management', () => {
119
- it('should register plugins successfully', () => {
120
- const mockPlugin: Plugin = {
121
- name: 'test-plugin',
122
- setup: vi.fn()
123
- }
124
-
125
- expect(() => framework.use(mockPlugin)).not.toThrow()
126
- expect(framework.getPluginRegistry().get('test-plugin')).toBe(mockPlugin)
127
- })
128
-
129
- it('should throw error when registering duplicate plugin', () => {
130
- const mockPlugin: Plugin = {
131
- name: 'duplicate-plugin',
132
- setup: vi.fn()
133
- }
134
-
135
- framework.use(mockPlugin)
136
- expect(() => framework.use(mockPlugin)).toThrow()
137
- })
138
-
139
- it('should validate plugin dependencies', async () => {
140
- const pluginA: Plugin = {
141
- name: 'plugin-a',
142
- setup: vi.fn()
143
- }
144
-
145
- const pluginB: Plugin = {
146
- name: 'plugin-b',
147
- dependencies: ['plugin-a'],
148
- setup: vi.fn()
149
- }
150
-
151
- framework.use(pluginA)
152
- framework.use(pluginB)
153
-
154
- await expect(framework.start()).resolves.not.toThrow()
155
- })
156
-
157
- it('should throw error for missing dependencies', async () => {
158
- const pluginWithMissingDep: Plugin = {
159
- name: 'plugin-with-missing-dep',
160
- dependencies: ['non-existent-plugin'],
161
- setup: vi.fn()
162
- }
163
-
164
- framework.use(pluginWithMissingDep)
165
- await expect(framework.start()).rejects.toThrow()
166
- })
167
- })
168
-
169
- describe('Lifecycle Management', () => {
170
- it('should start framework successfully', async () => {
171
- const mockPlugin: Plugin = {
172
- name: 'lifecycle-plugin',
173
- setup: vi.fn(),
174
- onServerStart: vi.fn()
175
- }
176
-
177
- framework.use(mockPlugin)
178
- await framework.start()
179
-
180
- expect(mockPlugin.setup).toHaveBeenCalled()
181
- expect(mockPlugin.onServerStart).toHaveBeenCalled()
182
- })
183
-
184
- it('should stop framework successfully', async () => {
185
- const mockPlugin: Plugin = {
186
- name: 'lifecycle-plugin',
187
- setup: vi.fn(),
188
- onServerStart: vi.fn(),
189
- onServerStop: vi.fn()
190
- }
191
-
192
- framework.use(mockPlugin)
193
- await framework.start()
194
- await framework.stop()
195
-
196
- expect(mockPlugin.onServerStop).toHaveBeenCalled()
197
- })
198
-
199
- it('should not start framework twice', async () => {
200
- await framework.start()
201
- await framework.start() // Should not throw or cause issues
202
-
203
- // Should log warning about already started
204
- const { logger } = await import('../../utils/logger')
205
- expect(logger.warn).toHaveBeenCalled()
206
- })
207
-
208
- it('should handle plugin setup errors', async () => {
209
- const errorPlugin: Plugin = {
210
- name: 'error-plugin',
211
- setup: vi.fn().mockRejectedValue(new Error('Setup failed'))
212
- }
213
-
214
- framework.use(errorPlugin)
215
- await expect(framework.start()).rejects.toThrow('Setup failed')
216
- })
217
- })
218
-
219
- describe('Routes', () => {
220
- it('should add routes to the app', () => {
221
- const mockRouteModule = { get: vi.fn() }
222
-
223
- expect(() => framework.routes(mockRouteModule)).not.toThrow()
224
- })
225
- })
226
-
227
- describe('Error Handling', () => {
228
- it('should set up error handling', async () => {
229
- const { createErrorHandler } = await import('../../utils/errors/handlers')
230
- expect(createErrorHandler).toHaveBeenCalled()
231
- })
232
- })
233
- })