Skip to content

Commit de601c0

Browse files
committed
chore: add Vitest for testing with configuration and setup files
- Added Vitest as a testing framework with commands in package.json. - Created vitest.config.ts for Vitest configuration including React plugin and alias resolution. - Added vitest.setup.ts to include jest-dom for improved testing utilities. - Updated package.json with necessary devDependencies for testing.
1 parent 9c9bf55 commit de601c0

File tree

4 files changed

+236
-236
lines changed

4 files changed

+236
-236
lines changed

lib/__tests__/template-config.test.ts

Lines changed: 153 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -2,163 +2,163 @@ import { describe, it, expect } from 'vitest'
22
import { getTemplateConfig, templateCombinations, type TemplateKey } from '@/lib/template-config'
33

44
describe('template-config', () => {
5-
describe('getTemplateConfig', () => {
6-
describe('with string key (legacy support)', () => {
7-
it('should return correct config for existing string key', () => {
8-
const result = getTemplateConfig('vscode-copilot-instructions')
9-
expect(result).toEqual({
10-
template: 'copilot-instructions-template.md',
11-
outputFileName: 'copilot-instructions.md'
5+
describe('getTemplateConfig', () => {
6+
describe('with string key (legacy support)', () => {
7+
it('should return correct config for existing string key', () => {
8+
const result = getTemplateConfig('vscode-copilot-instructions')
9+
expect(result).toEqual({
10+
template: 'copilot-instructions-template.md',
11+
outputFileName: 'copilot-instructions.md'
12+
})
13+
})
14+
15+
it('should return correct config for agents template', () => {
16+
const result = getTemplateConfig('vscode-agents')
17+
expect(result).toEqual({
18+
template: 'agents-template.md',
19+
outputFileName: 'agents.md'
20+
})
21+
})
22+
23+
it('should return correct config for cursor rules', () => {
24+
const result = getTemplateConfig('cursor-cursor-rules')
25+
expect(result).toEqual({
26+
template: 'copilot-instructions-template.md',
27+
outputFileName: '.cursorrules'
28+
})
29+
})
30+
31+
it('should return correct config for legacy instructions-md', () => {
32+
const result = getTemplateConfig('instructions-md')
33+
expect(result).toEqual({
34+
template: 'copilot-instructions-template.md',
35+
outputFileName: 'copilot-instructions.md'
36+
})
37+
})
38+
39+
it('should return null for non-existent string key', () => {
40+
const result = getTemplateConfig('non-existent-key')
41+
expect(result).toBeNull()
42+
})
43+
44+
it('should handle empty string', () => {
45+
const result = getTemplateConfig('')
46+
expect(result).toBeNull()
47+
})
1248
})
13-
})
1449

15-
it('should return correct config for agents template', () => {
16-
const result = getTemplateConfig('vscode-agents')
17-
expect(result).toEqual({
18-
template: 'agents-template.md',
19-
outputFileName: 'agents.md'
50+
describe('with TemplateKey object', () => {
51+
it('should return config for specific framework combination', () => {
52+
const key: TemplateKey = {
53+
ide: 'vscode',
54+
templateType: 'agents',
55+
framework: 'python'
56+
}
57+
const result = getTemplateConfig(key)
58+
expect(result).toEqual({
59+
template: 'agents-template.md',
60+
outputFileName: 'agents.md'
61+
})
62+
})
63+
64+
it('should return config for specific react combination', () => {
65+
const key: TemplateKey = {
66+
ide: 'vscode',
67+
templateType: 'agents',
68+
framework: 'react'
69+
}
70+
const result = getTemplateConfig(key)
71+
expect(result).toEqual({
72+
template: 'agents-template.md',
73+
outputFileName: 'agents.md'
74+
})
75+
})
76+
77+
it('should fallback to general combination when specific framework not found', () => {
78+
const key: TemplateKey = {
79+
ide: 'vscode',
80+
templateType: 'copilot-instructions',
81+
framework: 'nonexistent-framework'
82+
}
83+
const result = getTemplateConfig(key)
84+
expect(result).toEqual({
85+
template: 'copilot-instructions-template.md',
86+
outputFileName: 'copilot-instructions.md'
87+
})
88+
})
89+
90+
it('should return general combination when no framework specified', () => {
91+
const key: TemplateKey = {
92+
ide: 'vscode',
93+
templateType: 'copilot-instructions'
94+
}
95+
const result = getTemplateConfig(key)
96+
expect(result).toEqual({
97+
template: 'copilot-instructions-template.md',
98+
outputFileName: 'copilot-instructions.md'
99+
})
100+
})
101+
102+
it('should fallback to template type only when ide-template combination not found', () => {
103+
const key: TemplateKey = {
104+
ide: 'nonexistent-ide',
105+
templateType: 'instructions-md'
106+
}
107+
const result = getTemplateConfig(key)
108+
expect(result).toEqual({
109+
template: 'copilot-instructions-template.md',
110+
outputFileName: 'copilot-instructions.md'
111+
})
112+
})
113+
114+
it('should return null when no matching configuration found', () => {
115+
const key: TemplateKey = {
116+
ide: 'nonexistent-ide',
117+
templateType: 'nonexistent-template'
118+
}
119+
const result = getTemplateConfig(key)
120+
expect(result).toBeNull()
121+
})
122+
123+
it('should handle cursor IDE with rules template', () => {
124+
const key: TemplateKey = {
125+
ide: 'cursor',
126+
templateType: 'cursor-rules'
127+
}
128+
const result = getTemplateConfig(key)
129+
expect(result).toEqual({
130+
template: 'copilot-instructions-template.md',
131+
outputFileName: '.cursorrules'
132+
})
133+
})
20134
})
21-
})
22135

23-
it('should return correct config for cursor rules', () => {
24-
const result = getTemplateConfig('cursor-cursor-rules')
25-
expect(result).toEqual({
26-
template: 'copilot-instructions-template.md',
27-
outputFileName: '.cursorrules'
136+
describe('templateCombinations object', () => {
137+
it('should contain all expected template combinations', () => {
138+
const expectedKeys = [
139+
'vscode-copilot-instructions',
140+
'vscode-agents',
141+
'vscode-agents-python',
142+
'vscode-agents-react',
143+
'cursor-cursor-rules',
144+
'instructions-md'
145+
]
146+
147+
expectedKeys.forEach(key => {
148+
expect(templateCombinations).toHaveProperty(key)
149+
expect(templateCombinations[key]).toHaveProperty('template')
150+
expect(templateCombinations[key]).toHaveProperty('outputFileName')
151+
})
152+
})
153+
154+
it('should have valid template and outputFileName for all combinations', () => {
155+
Object.entries(templateCombinations).forEach(([key, config]) => {
156+
expect(config.template).toBeTruthy()
157+
expect(config.outputFileName).toBeTruthy()
158+
expect(typeof config.template).toBe('string')
159+
expect(typeof config.outputFileName).toBe('string')
160+
})
161+
})
28162
})
29-
})
30-
31-
it('should return correct config for legacy instructions-md', () => {
32-
const result = getTemplateConfig('instructions-md')
33-
expect(result).toEqual({
34-
template: 'copilot-instructions-template.md',
35-
outputFileName: 'copilot-instructions.md'
36-
})
37-
})
38-
39-
it('should return null for non-existent string key', () => {
40-
const result = getTemplateConfig('non-existent-key')
41-
expect(result).toBeNull()
42-
})
43-
44-
it('should handle empty string', () => {
45-
const result = getTemplateConfig('')
46-
expect(result).toBeNull()
47-
})
48-
})
49-
50-
describe('with TemplateKey object', () => {
51-
it('should return config for specific framework combination', () => {
52-
const key: TemplateKey = {
53-
ide: 'vscode',
54-
templateType: 'agents',
55-
framework: 'python'
56-
}
57-
const result = getTemplateConfig(key)
58-
expect(result).toEqual({
59-
template: 'agents-template.md',
60-
outputFileName: 'agents.md'
61-
})
62-
})
63-
64-
it('should return config for specific react combination', () => {
65-
const key: TemplateKey = {
66-
ide: 'vscode',
67-
templateType: 'agents',
68-
framework: 'react'
69-
}
70-
const result = getTemplateConfig(key)
71-
expect(result).toEqual({
72-
template: 'agents-template.md',
73-
outputFileName: 'agents.md'
74-
})
75-
})
76-
77-
it('should fallback to general combination when specific framework not found', () => {
78-
const key: TemplateKey = {
79-
ide: 'vscode',
80-
templateType: 'copilot-instructions',
81-
framework: 'nonexistent-framework'
82-
}
83-
const result = getTemplateConfig(key)
84-
expect(result).toEqual({
85-
template: 'copilot-instructions-template.md',
86-
outputFileName: 'copilot-instructions.md'
87-
})
88-
})
89-
90-
it('should return general combination when no framework specified', () => {
91-
const key: TemplateKey = {
92-
ide: 'vscode',
93-
templateType: 'copilot-instructions'
94-
}
95-
const result = getTemplateConfig(key)
96-
expect(result).toEqual({
97-
template: 'copilot-instructions-template.md',
98-
outputFileName: 'copilot-instructions.md'
99-
})
100-
})
101-
102-
it('should fallback to template type only when ide-template combination not found', () => {
103-
const key: TemplateKey = {
104-
ide: 'nonexistent-ide',
105-
templateType: 'instructions-md'
106-
}
107-
const result = getTemplateConfig(key)
108-
expect(result).toEqual({
109-
template: 'copilot-instructions-template.md',
110-
outputFileName: 'copilot-instructions.md'
111-
})
112-
})
113-
114-
it('should return null when no matching configuration found', () => {
115-
const key: TemplateKey = {
116-
ide: 'nonexistent-ide',
117-
templateType: 'nonexistent-template'
118-
}
119-
const result = getTemplateConfig(key)
120-
expect(result).toBeNull()
121-
})
122-
123-
it('should handle cursor IDE with rules template', () => {
124-
const key: TemplateKey = {
125-
ide: 'cursor',
126-
templateType: 'cursor-rules'
127-
}
128-
const result = getTemplateConfig(key)
129-
expect(result).toEqual({
130-
template: 'copilot-instructions-template.md',
131-
outputFileName: '.cursorrules'
132-
})
133-
})
134-
})
135-
136-
describe('templateCombinations object', () => {
137-
it('should contain all expected template combinations', () => {
138-
const expectedKeys = [
139-
'vscode-copilot-instructions',
140-
'vscode-agents',
141-
'vscode-agents-python',
142-
'vscode-agents-react',
143-
'cursor-cursor-rules',
144-
'instructions-md'
145-
]
146-
147-
expectedKeys.forEach(key => {
148-
expect(templateCombinations).toHaveProperty(key)
149-
expect(templateCombinations[key]).toHaveProperty('template')
150-
expect(templateCombinations[key]).toHaveProperty('outputFileName')
151-
})
152-
})
153-
154-
it('should have valid template and outputFileName for all combinations', () => {
155-
Object.entries(templateCombinations).forEach(([key, config]) => {
156-
expect(config.template).toBeTruthy()
157-
expect(config.outputFileName).toBeTruthy()
158-
expect(typeof config.template).toBe('string')
159-
expect(typeof config.outputFileName).toBe('string')
160-
})
161-
})
162163
})
163-
})
164164
})

0 commit comments

Comments
 (0)