-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-loading.test.ts
More file actions
374 lines (308 loc) · 12.6 KB
/
Copy pathtemplate-loading.test.ts
File metadata and controls
374 lines (308 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import { describe, expect, it, beforeEach } from 'vitest';
import { TemplateRegistry } from '../../templates/registry.js';
/**
* Integration tests for template loading and merging
* Ensures templates load correctly and merge properly
*/
describe('TemplateRegistry', () => {
let registry: TemplateRegistry;
beforeEach(() => {
registry = new TemplateRegistry();
});
describe('Template Loading', () => {
it('should load base template', () => {
const template = registry.loadAndRegister('base');
expect(template).toBeDefined();
expect(template.name).toBe('base');
expect(template.manifest).toBeDefined();
expect(template.files.size).toBeGreaterThan(0);
});
it('should load vite runtime template', () => {
const template = registry.loadAndRegister('runtime/vite');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.files.size).toBeGreaterThan(0);
});
it('should load nextjs runtime template', () => {
const template = registry.loadAndRegister('runtime/nextjs');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.files.size).toBeGreaterThan(0);
});
it('should load tailwind styling template', () => {
const template = registry.loadAndRegister('styling/tailwind');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.devDependencies).toHaveProperty('tailwindcss');
});
it('should load css-modules styling template', () => {
const template = registry.loadAndRegister('styling/css-modules');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
});
it('should load zustand state template', () => {
const template = registry.loadAndRegister('state/zustand');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.dependencies).toHaveProperty('zustand');
});
it('should load redux state template', () => {
const template = registry.loadAndRegister('state/redux');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.dependencies).toHaveProperty('@reduxjs/toolkit');
});
it('should load jotai state template', () => {
const template = registry.loadAndRegister('state/jotai');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.dependencies).toHaveProperty('jotai');
});
it('should load styled-components styling template', () => {
const template = registry.loadAndRegister('styling/styled-components');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.dependencies).toHaveProperty('styled-components');
});
it('should load vitest testing template', () => {
const template = registry.loadAndRegister('testing/vitest');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.devDependencies).toHaveProperty('vitest');
});
it('should load jest testing template', () => {
const template = registry.loadAndRegister('testing/jest');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.devDependencies).toHaveProperty('jest');
});
it('should load playwright testing template', () => {
const template = registry.loadAndRegister('testing/playwright');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.devDependencies).toHaveProperty('@playwright/test');
});
it('should load tanstack-query feature template', () => {
const template = registry.loadAndRegister('features/tanstack-query');
expect(template).toBeDefined();
expect(template.manifest).toBeDefined();
expect(template.manifest.dependencies).toHaveProperty('@tanstack/react-query');
});
it('should throw error for non-existent template', () => {
expect(() => registry.loadAndRegister('non-existent')).toThrow();
});
});
describe('loadTemplatesForConfig', () => {
it('should load templates for minimal Vite config', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'css' },
stateManagement: 'none',
testing: {
enabled: false,
unit: { runner: 'vitest' },
e2e: { enabled: false, runner: 'none' },
},
dataFetching: { enabled: false },
});
// Should have base and runtime
expect(templates.length).toBeGreaterThanOrEqual(2);
expect(templates.some(t => t.name === 'base')).toBe(true);
});
it('should load templates for Vite + Tailwind config', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'tailwind' },
stateManagement: 'none',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: false },
});
expect(templates.some(t => t.path === 'styling/tailwind')).toBe(true);
});
it('should load templates for Next.js + Redux config', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'nextjs',
styling: { solution: 'css' },
stateManagement: 'redux',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: false },
});
expect(templates.some(t => t.path === 'runtime/nextjs')).toBe(true);
expect(templates.some(t => t.path === 'state/redux')).toBe(true);
});
it('should load templates for Vite + Jotai config', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'styled-components' },
stateManagement: 'jotai',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: false },
});
expect(templates.some(t => t.path === 'runtime/vite')).toBe(true);
expect(templates.some(t => t.path === 'state/jotai')).toBe(true);
expect(templates.some(t => t.path === 'styling/styled-components')).toBe(true);
});
it('should load templates for Vite + CSS Modules config', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'css-modules' },
stateManagement: 'none',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: false },
});
expect(templates.some(t => t.path === 'styling/css-modules')).toBe(true);
});
it('should load testing templates when testing is enabled', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'css' },
stateManagement: 'none',
testing: {
enabled: true,
unit: { runner: 'vitest' },
e2e: { enabled: true, runner: 'playwright' },
},
dataFetching: { enabled: false },
});
expect(templates.some(t => t.path === 'testing/vitest')).toBe(true);
expect(templates.some(t => t.path === 'testing/playwright')).toBe(true);
});
it('should load tanstack-query template when dataFetching enabled', () => {
const templates = registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'css' },
stateManagement: 'none',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: true },
});
expect(templates.some(t => t.path === 'features/tanstack-query')).toBe(true);
});
});
describe('Merged Dependencies', () => {
it('should merge dependencies from multiple templates', () => {
registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'tailwind' },
stateManagement: 'zustand',
testing: {
enabled: true,
unit: { runner: 'vitest' },
e2e: { enabled: true, runner: 'playwright' },
},
dataFetching: { enabled: true },
});
const { dependencies, devDependencies } = registry.getMergedDependencies();
// Check deps from different templates
expect(dependencies).toHaveProperty('zustand'); // from zustand
expect(dependencies).toHaveProperty('@tanstack/react-query'); // from tanstack-query
expect(devDependencies).toHaveProperty('tailwindcss'); // from tailwind
expect(devDependencies).toHaveProperty('vitest'); // from vitest
expect(devDependencies).toHaveProperty('@playwright/test'); // from playwright
});
it('should include scripts from templates', () => {
registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'css' },
stateManagement: 'none',
testing: {
enabled: true,
unit: { runner: 'vitest' },
e2e: { enabled: false, runner: 'none' },
},
dataFetching: { enabled: false },
});
const { scripts } = registry.getMergedDependencies();
expect(scripts).toHaveProperty('test');
});
});
describe('Merged Files', () => {
it('should merge files from multiple templates', () => {
registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'tailwind' },
stateManagement: 'zustand',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: false },
});
const files = registry.getMergedFiles();
expect(files.size).toBeGreaterThan(0);
// Should have files from different templates merged
// Check for vite config file
const hasViteConfig = Array.from(files.keys()).some(
path => path.includes('vite.config')
);
expect(hasViteConfig).toBe(true);
// Check for store files from zustand
const hasStoreFiles = Array.from(files.keys()).some(
path => path.includes('stores')
);
expect(hasStoreFiles).toBe(true);
});
it('should override base files with runtime-specific files', () => {
// Load base first, then runtime
registry.loadTemplatesForConfig({
runtime: 'vite',
styling: { solution: 'css' },
stateManagement: 'none',
testing: { enabled: false, e2e: { enabled: false, runner: 'none' } },
dataFetching: { enabled: false },
});
const files = registry.getMergedFiles();
// Should have runtime-specific App.tsx, not base
const appFiles = Array.from(files.keys()).filter(
path => path.includes('App.tsx')
);
expect(appFiles.length).toBeGreaterThan(0);
});
});
describe('Template Manifest Validation', () => {
it('should have valid manifest for all templates', () => {
const templatePaths = [
'base',
'runtime/vite',
'runtime/nextjs',
'styling/tailwind',
'styling/css-modules',
'styling/styled-components',
'state/zustand',
'state/redux',
'state/jotai',
'testing/vitest',
'testing/jest',
'testing/playwright',
'features/tanstack-query',
];
for (const path of templatePaths) {
const template = registry.loadTemplate(path);
expect(template.manifest, `Manifest missing for ${path}`).toBeDefined();
expect(template.manifest.name, `Name missing for ${path}`).toBeDefined();
expect(template.manifest.version, `Version missing for ${path}`).toBeDefined();
}
});
it('should have valid dependency versions in manifests', () => {
const templatePaths = [
'state/zustand',
'state/redux',
'state/jotai',
'styling/styled-components',
'testing/vitest',
'testing/playwright',
'features/tanstack-query',
];
const semverPattern = /^[\^~>=<]*\d+\.\d+\.\d+(-[\w.]+)?$/;
for (const path of templatePaths) {
const template = registry.loadTemplate(path);
const allDeps = {
...template.manifest.dependencies,
...template.manifest.devDependencies,
};
for (const [name, version] of Object.entries(allDeps)) {
expect(
version,
`Invalid version for ${name} in ${path}: ${version}`
).toMatch(semverPattern);
}
}
});
});
});