create-fluxstack 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +30 -0
- package/LICENSE +21 -0
- package/README.md +214 -0
- package/app/client/README.md +69 -0
- package/app/client/frontend-only.ts +12 -0
- package/app/client/index.html +13 -0
- package/app/client/public/vite.svg +1 -0
- package/app/client/src/App.css +883 -0
- package/app/client/src/App.tsx +669 -0
- package/app/client/src/assets/react.svg +1 -0
- package/app/client/src/components/TestPage.tsx +453 -0
- package/app/client/src/index.css +51 -0
- package/app/client/src/lib/eden-api.ts +110 -0
- package/app/client/src/main.tsx +10 -0
- package/app/client/src/vite-env.d.ts +1 -0
- package/app/client/tsconfig.app.json +43 -0
- package/app/client/tsconfig.json +7 -0
- package/app/client/tsconfig.node.json +25 -0
- package/app/server/app.ts +10 -0
- package/app/server/backend-only.ts +15 -0
- package/app/server/controllers/users.controller.ts +69 -0
- package/app/server/index.ts +104 -0
- package/app/server/routes/index.ts +25 -0
- package/app/server/routes/users.routes.ts +121 -0
- package/app/server/types/index.ts +1 -0
- package/app/shared/types/index.ts +18 -0
- package/bun.lock +1053 -0
- package/core/__tests__/integration.test.ts +227 -0
- package/core/build/index.ts +186 -0
- package/core/cli/command-registry.ts +334 -0
- package/core/cli/index.ts +394 -0
- package/core/cli/plugin-discovery.ts +200 -0
- package/core/client/standalone.ts +57 -0
- package/core/config/__tests__/config-loader.test.ts +591 -0
- package/core/config/__tests__/config-merger.test.ts +657 -0
- package/core/config/__tests__/env-converter.test.ts +372 -0
- package/core/config/__tests__/env-processor.test.ts +431 -0
- package/core/config/__tests__/env.test.ts +452 -0
- package/core/config/__tests__/integration.test.ts +418 -0
- package/core/config/__tests__/loader.test.ts +331 -0
- package/core/config/__tests__/schema.test.ts +129 -0
- package/core/config/__tests__/validator.test.ts +318 -0
- package/core/config/env-dynamic.ts +326 -0
- package/core/config/env.ts +597 -0
- package/core/config/index.ts +317 -0
- package/core/config/loader.ts +546 -0
- package/core/config/runtime-config.ts +322 -0
- package/core/config/schema.ts +694 -0
- package/core/config/validator.ts +540 -0
- package/core/framework/__tests__/server.test.ts +233 -0
- package/core/framework/client.ts +132 -0
- package/core/framework/index.ts +8 -0
- package/core/framework/server.ts +501 -0
- package/core/framework/types.ts +63 -0
- package/core/plugins/__tests__/built-in.test.ts.disabled +366 -0
- package/core/plugins/__tests__/manager.test.ts +398 -0
- package/core/plugins/__tests__/monitoring.test.ts +401 -0
- package/core/plugins/__tests__/registry.test.ts +335 -0
- package/core/plugins/built-in/index.ts +142 -0
- package/core/plugins/built-in/logger/index.ts +180 -0
- package/core/plugins/built-in/monitoring/README.md +193 -0
- package/core/plugins/built-in/monitoring/index.ts +912 -0
- package/core/plugins/built-in/static/index.ts +289 -0
- package/core/plugins/built-in/swagger/index.ts +229 -0
- package/core/plugins/built-in/vite/index.ts +316 -0
- package/core/plugins/config.ts +348 -0
- package/core/plugins/discovery.ts +350 -0
- package/core/plugins/executor.ts +351 -0
- package/core/plugins/index.ts +195 -0
- package/core/plugins/manager.ts +583 -0
- package/core/plugins/registry.ts +424 -0
- package/core/plugins/types.ts +254 -0
- package/core/server/framework.ts +123 -0
- package/core/server/index.ts +8 -0
- package/core/server/plugins/database.ts +182 -0
- package/core/server/plugins/logger.ts +47 -0
- package/core/server/plugins/swagger.ts +34 -0
- package/core/server/standalone.ts +91 -0
- package/core/templates/create-project.ts +455 -0
- package/core/types/api.ts +169 -0
- package/core/types/build.ts +174 -0
- package/core/types/config.ts +68 -0
- package/core/types/index.ts +127 -0
- package/core/types/plugin.ts +94 -0
- package/core/utils/__tests__/errors.test.ts +139 -0
- package/core/utils/__tests__/helpers.test.ts +297 -0
- package/core/utils/__tests__/logger.test.ts +141 -0
- package/core/utils/env-runtime-v2.ts +232 -0
- package/core/utils/env-runtime.ts +252 -0
- package/core/utils/errors/codes.ts +115 -0
- package/core/utils/errors/handlers.ts +63 -0
- package/core/utils/errors/index.ts +81 -0
- package/core/utils/helpers.ts +180 -0
- package/core/utils/index.ts +18 -0
- package/core/utils/logger/index.ts +161 -0
- package/core/utils/logger.ts +106 -0
- package/core/utils/monitoring/index.ts +212 -0
- package/create-fluxstack.ts +231 -0
- package/package.json +43 -0
- package/tsconfig.json +51 -0
- package/vite.config.ts +42 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Environment Configuration System
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
getEnvironmentInfo,
|
|
8
|
+
EnvConverter,
|
|
9
|
+
EnvironmentProcessor,
|
|
10
|
+
ConfigMerger,
|
|
11
|
+
EnvironmentConfigApplier,
|
|
12
|
+
isDevelopment,
|
|
13
|
+
isProduction,
|
|
14
|
+
isTest,
|
|
15
|
+
getEnvironmentRecommendations
|
|
16
|
+
} from '../env'
|
|
17
|
+
import { defaultFluxStackConfig } from '../schema'
|
|
18
|
+
|
|
19
|
+
describe('Environment Configuration System', () => {
|
|
20
|
+
const originalEnv = { ...process.env }
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
// Clean environment
|
|
24
|
+
Object.keys(process.env).forEach(key => {
|
|
25
|
+
if (key.startsWith('FLUXSTACK_') || key.startsWith('TEST_')) {
|
|
26
|
+
delete process.env[key]
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
// Restore original environment
|
|
33
|
+
process.env = { ...originalEnv }
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('getEnvironmentInfo', () => {
|
|
37
|
+
it('should return development info by default', () => {
|
|
38
|
+
delete process.env.NODE_ENV
|
|
39
|
+
const info = getEnvironmentInfo()
|
|
40
|
+
|
|
41
|
+
expect(info.name).toBe('development')
|
|
42
|
+
expect(info.isDevelopment).toBe(true)
|
|
43
|
+
expect(info.isProduction).toBe(false)
|
|
44
|
+
expect(info.isTest).toBe(false)
|
|
45
|
+
expect(info.nodeEnv).toBe('development')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should detect production environment', () => {
|
|
49
|
+
process.env.NODE_ENV = 'production'
|
|
50
|
+
const info = getEnvironmentInfo()
|
|
51
|
+
|
|
52
|
+
expect(info.name).toBe('production')
|
|
53
|
+
expect(info.isDevelopment).toBe(false)
|
|
54
|
+
expect(info.isProduction).toBe(true)
|
|
55
|
+
expect(info.isTest).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should detect test environment', () => {
|
|
59
|
+
process.env.NODE_ENV = 'test'
|
|
60
|
+
const info = getEnvironmentInfo()
|
|
61
|
+
|
|
62
|
+
expect(info.name).toBe('test')
|
|
63
|
+
expect(info.isDevelopment).toBe(false)
|
|
64
|
+
expect(info.isProduction).toBe(false)
|
|
65
|
+
expect(info.isTest).toBe(true)
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('EnvConverter', () => {
|
|
70
|
+
describe('toNumber', () => {
|
|
71
|
+
it('should convert valid numbers', () => {
|
|
72
|
+
expect(EnvConverter.toNumber('123', 0)).toBe(123)
|
|
73
|
+
expect(EnvConverter.toNumber('0', 100)).toBe(0)
|
|
74
|
+
expect(EnvConverter.toNumber('-50', 0)).toBe(-50)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('should return default for invalid numbers', () => {
|
|
78
|
+
expect(EnvConverter.toNumber('abc', 42)).toBe(42)
|
|
79
|
+
expect(EnvConverter.toNumber('', 100)).toBe(100)
|
|
80
|
+
expect(EnvConverter.toNumber(undefined, 200)).toBe(200)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('toBoolean', () => {
|
|
85
|
+
it('should convert truthy values', () => {
|
|
86
|
+
expect(EnvConverter.toBoolean('true', false)).toBe(true)
|
|
87
|
+
expect(EnvConverter.toBoolean('1', false)).toBe(true)
|
|
88
|
+
expect(EnvConverter.toBoolean('yes', false)).toBe(true)
|
|
89
|
+
expect(EnvConverter.toBoolean('on', false)).toBe(true)
|
|
90
|
+
expect(EnvConverter.toBoolean('TRUE', false)).toBe(true)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should convert falsy values', () => {
|
|
94
|
+
expect(EnvConverter.toBoolean('false', true)).toBe(false)
|
|
95
|
+
expect(EnvConverter.toBoolean('0', true)).toBe(false)
|
|
96
|
+
expect(EnvConverter.toBoolean('no', true)).toBe(false)
|
|
97
|
+
expect(EnvConverter.toBoolean('off', true)).toBe(false)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('should return default for undefined', () => {
|
|
101
|
+
expect(EnvConverter.toBoolean(undefined, true)).toBe(true)
|
|
102
|
+
expect(EnvConverter.toBoolean(undefined, false)).toBe(false)
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('toArray', () => {
|
|
107
|
+
it('should convert comma-separated values', () => {
|
|
108
|
+
expect(EnvConverter.toArray('a,b,c')).toEqual(['a', 'b', 'c'])
|
|
109
|
+
expect(EnvConverter.toArray('one, two, three')).toEqual(['one', 'two', 'three'])
|
|
110
|
+
expect(EnvConverter.toArray('single')).toEqual(['single'])
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should handle empty values', () => {
|
|
114
|
+
expect(EnvConverter.toArray('')).toEqual([])
|
|
115
|
+
expect(EnvConverter.toArray(undefined)).toEqual([])
|
|
116
|
+
expect(EnvConverter.toArray('a,,b')).toEqual(['a', 'b']) // Filters empty strings
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe('toLogLevel', () => {
|
|
121
|
+
it('should convert valid log levels', () => {
|
|
122
|
+
expect(EnvConverter.toLogLevel('debug', 'info')).toBe('debug')
|
|
123
|
+
expect(EnvConverter.toLogLevel('INFO', 'debug')).toBe('info')
|
|
124
|
+
expect(EnvConverter.toLogLevel('warn', 'info')).toBe('warn')
|
|
125
|
+
expect(EnvConverter.toLogLevel('error', 'info')).toBe('error')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('should return default for invalid levels', () => {
|
|
129
|
+
expect(EnvConverter.toLogLevel('invalid', 'info')).toBe('info')
|
|
130
|
+
expect(EnvConverter.toLogLevel(undefined, 'warn')).toBe('warn')
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('toObject', () => {
|
|
135
|
+
it('should parse valid JSON', () => {
|
|
136
|
+
expect(EnvConverter.toObject('{"key": "value"}', {})).toEqual({ key: 'value' })
|
|
137
|
+
expect(EnvConverter.toObject('[1,2,3]', [] as any)).toEqual([1, 2, 3])
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('should return default for invalid JSON', () => {
|
|
141
|
+
expect(EnvConverter.toObject('invalid-json', { default: true })).toEqual({ default: true })
|
|
142
|
+
expect(EnvConverter.toObject(undefined, null)).toBe(null)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
describe('EnvironmentProcessor', () => {
|
|
148
|
+
it('should process basic environment variables', () => {
|
|
149
|
+
process.env.PORT = '4000'
|
|
150
|
+
process.env.HOST = 'example.com'
|
|
151
|
+
process.env.FLUXSTACK_APP_NAME = 'test-app'
|
|
152
|
+
|
|
153
|
+
const processor = new EnvironmentProcessor()
|
|
154
|
+
const config = processor.processEnvironmentVariables()
|
|
155
|
+
|
|
156
|
+
expect(config.server?.port).toBe(4000)
|
|
157
|
+
expect(config.server?.host).toBe('example.com')
|
|
158
|
+
expect(config.app?.name).toBe('test-app')
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('should process CORS configuration', () => {
|
|
162
|
+
process.env.CORS_ORIGINS = 'http://localhost:3000,https://example.com'
|
|
163
|
+
process.env.CORS_METHODS = 'GET,POST,PUT'
|
|
164
|
+
process.env.CORS_CREDENTIALS = 'true'
|
|
165
|
+
|
|
166
|
+
const processor = new EnvironmentProcessor()
|
|
167
|
+
const config = processor.processEnvironmentVariables()
|
|
168
|
+
|
|
169
|
+
expect(config.server?.cors?.origins).toEqual(['http://localhost:3000', 'https://example.com'])
|
|
170
|
+
expect(config.server?.cors?.methods).toEqual(['GET', 'POST', 'PUT'])
|
|
171
|
+
expect(config.server?.cors?.credentials).toBe(true)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('should process build configuration', () => {
|
|
175
|
+
process.env.BUILD_TARGET = 'node'
|
|
176
|
+
process.env.BUILD_MINIFY = 'false'
|
|
177
|
+
process.env.BUILD_SOURCEMAPS = 'true'
|
|
178
|
+
|
|
179
|
+
const processor = new EnvironmentProcessor()
|
|
180
|
+
const config = processor.processEnvironmentVariables()
|
|
181
|
+
|
|
182
|
+
expect(config.build?.target).toBe('node')
|
|
183
|
+
expect(config.build?.optimization?.minify).toBe(false)
|
|
184
|
+
expect(config.build?.sourceMaps).toBe(true)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('should process optional database configuration', () => {
|
|
188
|
+
process.env.DATABASE_URL = 'postgresql://localhost:5432/test'
|
|
189
|
+
process.env.DATABASE_SSL = 'true'
|
|
190
|
+
process.env.DATABASE_POOL_SIZE = '10'
|
|
191
|
+
|
|
192
|
+
const processor = new EnvironmentProcessor()
|
|
193
|
+
const config = processor.processEnvironmentVariables()
|
|
194
|
+
|
|
195
|
+
expect(config.database?.url).toBe('postgresql://localhost:5432/test')
|
|
196
|
+
expect(config.database?.ssl).toBe(true)
|
|
197
|
+
expect(config.database?.poolSize).toBe(10)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('should track precedence information', () => {
|
|
201
|
+
process.env.PORT = '5000'
|
|
202
|
+
process.env.FLUXSTACK_APP_NAME = 'precedence-test'
|
|
203
|
+
|
|
204
|
+
const processor = new EnvironmentProcessor()
|
|
205
|
+
processor.processEnvironmentVariables()
|
|
206
|
+
|
|
207
|
+
const precedence = processor.getPrecedenceInfo()
|
|
208
|
+
|
|
209
|
+
expect(precedence.has('server.port')).toBe(true)
|
|
210
|
+
expect(precedence.has('app.name')).toBe(true)
|
|
211
|
+
expect(precedence.get('server.port')?.source).toBe('environment')
|
|
212
|
+
expect(precedence.get('server.port')?.priority).toBe(3)
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
describe('ConfigMerger', () => {
|
|
217
|
+
it('should merge configurations with precedence', () => {
|
|
218
|
+
const merger = new ConfigMerger()
|
|
219
|
+
|
|
220
|
+
const baseConfig = {
|
|
221
|
+
app: { name: 'base-app', version: '1.0.0' },
|
|
222
|
+
server: {
|
|
223
|
+
port: 3000,
|
|
224
|
+
host: 'localhost',
|
|
225
|
+
apiPrefix: '/api',
|
|
226
|
+
cors: {
|
|
227
|
+
origins: ['*'],
|
|
228
|
+
methods: ['GET', 'POST'],
|
|
229
|
+
headers: ['Content-Type'],
|
|
230
|
+
credentials: false,
|
|
231
|
+
maxAge: 86400
|
|
232
|
+
},
|
|
233
|
+
middleware: []
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const envConfig = {
|
|
238
|
+
server: {
|
|
239
|
+
port: 4000,
|
|
240
|
+
host: 'localhost',
|
|
241
|
+
apiPrefix: '/api',
|
|
242
|
+
cors: {
|
|
243
|
+
origins: ['*'],
|
|
244
|
+
methods: ['GET', 'POST'],
|
|
245
|
+
headers: ['Content-Type'],
|
|
246
|
+
credentials: false,
|
|
247
|
+
maxAge: 86400
|
|
248
|
+
},
|
|
249
|
+
middleware: []
|
|
250
|
+
},
|
|
251
|
+
logging: {
|
|
252
|
+
level: 'debug' as const,
|
|
253
|
+
format: 'pretty' as const,
|
|
254
|
+
transports: [{ type: 'console' as const, level: 'debug' as const, format: 'pretty' as const }]
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const result = merger.merge(
|
|
259
|
+
{ config: baseConfig, source: 'file' },
|
|
260
|
+
{ config: envConfig, source: 'environment' }
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
expect(result.app.name).toBe('base-app') // From base
|
|
264
|
+
expect(result.server.port).toBe(4000) // Overridden by env
|
|
265
|
+
expect(result.server.host).toBe('localhost') // From base
|
|
266
|
+
expect(result.logging?.level).toBe('debug') // From env
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
it('should handle nested object merging', () => {
|
|
270
|
+
const merger = new ConfigMerger()
|
|
271
|
+
|
|
272
|
+
const config1 = {
|
|
273
|
+
server: {
|
|
274
|
+
port: 3000,
|
|
275
|
+
host: 'localhost',
|
|
276
|
+
apiPrefix: '/api',
|
|
277
|
+
cors: {
|
|
278
|
+
origins: ['http://localhost:3000'],
|
|
279
|
+
methods: ['GET', 'POST'],
|
|
280
|
+
headers: ['Content-Type'],
|
|
281
|
+
credentials: false,
|
|
282
|
+
maxAge: 86400
|
|
283
|
+
},
|
|
284
|
+
middleware: []
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const config2 = {
|
|
289
|
+
server: {
|
|
290
|
+
port: 3000,
|
|
291
|
+
host: 'localhost',
|
|
292
|
+
apiPrefix: '/api',
|
|
293
|
+
cors: {
|
|
294
|
+
origins: ['https://example.com'],
|
|
295
|
+
methods: ['GET', 'POST'],
|
|
296
|
+
headers: ['Content-Type'],
|
|
297
|
+
credentials: true,
|
|
298
|
+
maxAge: 86400
|
|
299
|
+
},
|
|
300
|
+
middleware: []
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const result = merger.merge(
|
|
305
|
+
{ config: config1, source: 'default' },
|
|
306
|
+
{ config: config2, source: 'environment' }
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
expect(result.server.cors.origins).toEqual(['https://example.com'])
|
|
310
|
+
expect(result.server.cors.methods).toEqual(['GET', 'POST'])
|
|
311
|
+
expect(result.server.cors.credentials).toBe(true)
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
describe('EnvironmentConfigApplier', () => {
|
|
316
|
+
it('should apply environment-specific configuration', () => {
|
|
317
|
+
const applier = new EnvironmentConfigApplier()
|
|
318
|
+
|
|
319
|
+
const baseConfig = {
|
|
320
|
+
...defaultFluxStackConfig,
|
|
321
|
+
environments: {
|
|
322
|
+
production: {
|
|
323
|
+
logging: {
|
|
324
|
+
level: 'error' as const,
|
|
325
|
+
format: 'json' as const,
|
|
326
|
+
transports: [{ type: 'console' as const, level: 'error' as const, format: 'json' as const }]
|
|
327
|
+
},
|
|
328
|
+
monitoring: {
|
|
329
|
+
enabled: true,
|
|
330
|
+
metrics: {
|
|
331
|
+
enabled: true,
|
|
332
|
+
collectInterval: 30000,
|
|
333
|
+
httpMetrics: true,
|
|
334
|
+
systemMetrics: true,
|
|
335
|
+
customMetrics: false
|
|
336
|
+
},
|
|
337
|
+
profiling: {
|
|
338
|
+
enabled: true,
|
|
339
|
+
sampleRate: 0.01,
|
|
340
|
+
memoryProfiling: true,
|
|
341
|
+
cpuProfiling: true
|
|
342
|
+
},
|
|
343
|
+
exporters: ['prometheus']
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const result = applier.applyEnvironmentConfig(baseConfig, 'production')
|
|
350
|
+
|
|
351
|
+
expect(result.logging.level).toBe('error')
|
|
352
|
+
expect(result.monitoring.enabled).toBe(true)
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
it('should get available environments', () => {
|
|
356
|
+
const applier = new EnvironmentConfigApplier()
|
|
357
|
+
|
|
358
|
+
const config = {
|
|
359
|
+
...defaultFluxStackConfig,
|
|
360
|
+
environments: {
|
|
361
|
+
staging: {},
|
|
362
|
+
production: {},
|
|
363
|
+
custom: {}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const environments = applier.getAvailableEnvironments(config)
|
|
368
|
+
|
|
369
|
+
expect(environments).toEqual(['staging', 'production', 'custom'])
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('should validate environment configuration', () => {
|
|
373
|
+
const applier = new EnvironmentConfigApplier()
|
|
374
|
+
|
|
375
|
+
const config = {
|
|
376
|
+
...defaultFluxStackConfig,
|
|
377
|
+
environments: {
|
|
378
|
+
production: {
|
|
379
|
+
logging: {
|
|
380
|
+
level: 'debug' as const,
|
|
381
|
+
format: 'json' as const,
|
|
382
|
+
transports: [{ type: 'console' as const, level: 'debug' as const, format: 'json' as const }]
|
|
383
|
+
} // Bad for production
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const result = applier.validateEnvironmentConfig(config, 'production')
|
|
389
|
+
|
|
390
|
+
expect(result.valid).toBe(false)
|
|
391
|
+
expect(result.errors.some(e => e.includes('debug'))).toBe(true)
|
|
392
|
+
})
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
describe('Environment Helper Functions', () => {
|
|
396
|
+
it('should detect development environment', () => {
|
|
397
|
+
process.env.NODE_ENV = 'development'
|
|
398
|
+
expect(isDevelopment()).toBe(true)
|
|
399
|
+
expect(isProduction()).toBe(false)
|
|
400
|
+
expect(isTest()).toBe(false)
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
it('should detect production environment', () => {
|
|
404
|
+
process.env.NODE_ENV = 'production'
|
|
405
|
+
expect(isDevelopment()).toBe(false)
|
|
406
|
+
expect(isProduction()).toBe(true)
|
|
407
|
+
expect(isTest()).toBe(false)
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
it('should detect test environment', () => {
|
|
411
|
+
process.env.NODE_ENV = 'test'
|
|
412
|
+
expect(isDevelopment()).toBe(false)
|
|
413
|
+
expect(isProduction()).toBe(false)
|
|
414
|
+
expect(isTest()).toBe(true)
|
|
415
|
+
})
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
describe('getEnvironmentRecommendations', () => {
|
|
419
|
+
it('should provide development recommendations', () => {
|
|
420
|
+
const recommendations = getEnvironmentRecommendations('development')
|
|
421
|
+
|
|
422
|
+
expect(recommendations.logging?.level).toBe('debug')
|
|
423
|
+
expect(recommendations.logging?.format).toBe('pretty')
|
|
424
|
+
expect(recommendations.build?.optimization?.minify).toBe(false)
|
|
425
|
+
expect(recommendations.monitoring?.enabled).toBe(false)
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
it('should provide production recommendations', () => {
|
|
429
|
+
const recommendations = getEnvironmentRecommendations('production')
|
|
430
|
+
|
|
431
|
+
expect(recommendations.logging?.level).toBe('warn')
|
|
432
|
+
expect(recommendations.logging?.format).toBe('json')
|
|
433
|
+
expect(recommendations.build?.optimization?.minify).toBe(true)
|
|
434
|
+
expect(recommendations.monitoring?.enabled).toBe(true)
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
it('should provide test recommendations', () => {
|
|
438
|
+
const recommendations = getEnvironmentRecommendations('test')
|
|
439
|
+
|
|
440
|
+
expect(recommendations.logging?.level).toBe('error')
|
|
441
|
+
expect(recommendations.server?.port).toBe(0)
|
|
442
|
+
expect(recommendations.client?.port).toBe(0)
|
|
443
|
+
expect(recommendations.monitoring?.enabled).toBe(false)
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
it('should return empty for unknown environments', () => {
|
|
447
|
+
const recommendations = getEnvironmentRecommendations('unknown')
|
|
448
|
+
|
|
449
|
+
expect(Object.keys(recommendations)).toHaveLength(0)
|
|
450
|
+
})
|
|
451
|
+
})
|
|
452
|
+
})
|