forked from faezemohades/svger-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframeworks.test.js
More file actions
executable file
·190 lines (165 loc) · 5.86 KB
/
Copy pathframeworks.test.js
File metadata and controls
executable file
·190 lines (165 loc) · 5.86 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
#!/usr/bin/env node
/**
* Framework Testing Script for SVGER-CLI
* Tests all 9 supported frameworks: React, React Native, Vue, Svelte, Angular, Solid, Preact, Lit, Vanilla
*/
import { frameworkTemplateEngine } from './dist/index.js';
import fs from 'fs';
import path from 'path';
const testSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
</svg>`;
const frameworks = [
{ name: 'react', typescript: true, options: {} },
{ name: 'react-native', typescript: true, options: {} },
{ name: 'vue', typescript: true, options: { scriptSetup: true } },
{ name: 'vue', typescript: true, options: { scriptSetup: false } },
{ name: 'svelte', typescript: true, options: {} },
{ name: 'angular', typescript: true, options: { standalone: true } },
{ name: 'angular', typescript: true, options: { standalone: false } },
{ name: 'solid', typescript: true, options: {} },
{ name: 'preact', typescript: true, options: {} },
{ name: 'lit', typescript: true, options: {} },
{ name: 'vanilla', typescript: true, options: {} },
];
console.log('🚀 SVGER-CLI Framework Testing Suite\n');
console.log('='.repeat(80));
const testOutputDir = path.join(process.cwd(), 'test-output');
if (!fs.existsSync(testOutputDir)) {
fs.mkdirSync(testOutputDir, { recursive: true });
}
let passed = 0;
let failed = 0;
frameworks.forEach((config, index) => {
const { name, typescript, options } = config;
const variant =
options.scriptSetup !== undefined
? options.scriptSetup
? '-composition'
: '-options'
: options.standalone !== undefined
? options.standalone
? '-standalone'
: '-module'
: '';
const testName = `${name}${variant}`;
try {
console.log(
`\n[${index + 1}/${frameworks.length}] Testing: ${testName.toUpperCase()}`
);
console.log('-'.repeat(80));
const componentOptions = {
framework: name,
componentName: 'TestIcon',
svgContent: testSVG,
typescript,
frameworkOptions: options,
};
// Generate component
const component =
frameworkTemplateEngine.generateComponent(componentOptions);
// Validate component
if (!component || component.length === 0) {
throw new Error('Generated component is empty');
}
// Get file extension
const extension = frameworkTemplateEngine.getFileExtension(
name,
typescript
);
// Save to file
const fileName = `TestIcon-${testName}.${extension}`;
const filePath = path.join(testOutputDir, fileName);
fs.writeFileSync(filePath, component, 'utf8');
// Framework-specific validation
switch (name) {
case 'react':
case 'react-native':
case 'preact':
case 'solid':
if (!component.includes('export default')) {
throw new Error('Missing default export');
}
if (!component.includes('interface')) {
throw new Error('Missing TypeScript interface');
}
if (name === 'react-native') {
if (!component.includes('react-native-svg')) {
throw new Error('Missing react-native-svg import');
}
if (!component.includes('Svg')) {
throw new Error('Missing Svg component');
}
}
break;
case 'vue':
if (!component.includes('<template>')) {
throw new Error('Missing Vue template section');
}
if (!component.includes('<script')) {
throw new Error('Missing Vue script section');
}
if (options.scriptSetup && !component.includes('setup')) {
throw new Error('Missing composition API setup');
}
break;
case 'svelte':
if (!component.includes('<script')) {
throw new Error('Missing Svelte script section');
}
if (!component.includes('export let')) {
throw new Error('Missing Svelte props');
}
break;
case 'angular':
if (!component.includes('@Component')) {
throw new Error('Missing Angular decorator');
}
if (!component.includes('selector:')) {
throw new Error('Missing component selector');
}
if (options.standalone && !component.includes('standalone: true')) {
throw new Error('Missing standalone flag');
}
break;
case 'lit':
if (!component.includes('@customElement')) {
throw new Error('Missing Lit decorator');
}
if (!component.includes('extends LitElement')) {
throw new Error('Not extending LitElement');
}
break;
case 'vanilla':
if (!component.includes('export function')) {
throw new Error('Missing function export');
}
if (!component.includes('document.createElementNS')) {
throw new Error('Missing DOM manipulation');
}
break;
}
console.log(`✅ SUCCESS: Generated valid ${name.toUpperCase()} component`);
console.log(` 📄 File: ${fileName}`);
console.log(` 📏 Size: ${component.length} characters`);
console.log(` 📝 Extension: .${extension}`);
passed++;
} catch (error) {
console.log(`❌ FAILED: ${testName.toUpperCase()}`);
console.log(` Error: ${error.message}`);
failed++;
}
});
console.log('\n' + '='.repeat(80));
console.log('\n📊 Test Results Summary\n');
console.log(` Total Tests: ${frameworks.length}`);
console.log(` ✅ Passed: ${passed}`);
console.log(` ❌ Failed: ${failed}`);
console.log(` 📂 Output: ${testOutputDir}\n`);
if (failed === 0) {
console.log('🎉 All framework tests passed successfully!\n');
process.exit(0);
} else {
console.log('⚠️ Some tests failed. Please review the errors above.\n');
process.exit(1);
}