-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-e2e.js
More file actions
143 lines (122 loc) Β· 3.75 KB
/
test-e2e.js
File metadata and controls
143 lines (122 loc) Β· 3.75 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
#!/usr/bin/env node
/**
* DTUI2 End-to-End Test Script
* Tests the application through the AI Provider interface
*/
const { AIProvider } = require('./dist-test/AIProvider.js');
const { MockAIAgent } = require('./dist-test/MockAIAgent.js');
// Test scenarios
const testScenarios = [
{
name: 'Basic greeting',
input: 'Hello',
expectedPattern: /hello|hi|greet/i
},
{
name: 'Help command',
input: 'help',
expectedPattern: /available commands|terminal operations/i
},
{
name: 'Shell command (!ls)',
input: '!ls',
expectedPattern: /node_modules|src|package\.json/i
},
{
name: 'File read command',
input: 'read file package.json',
expectedPattern: /package\.json|file:/i
},
{
name: 'Code analysis',
input: 'analyze code src/App.tsx',
expectedPattern: /analyze|code|file/i
},
{
name: 'Project analysis',
input: 'analyze project',
expectedPattern: /project|structure|directories/i
},
{
name: 'Error suggestion',
input: 'suggest fix TypeError: Cannot read property',
expectedPattern: /suggestion|fix|error/i
},
{
name: 'Code generation',
input: 'generate code React component',
expectedPattern: /generated|component|react/i
}
];
async function runE2ETests() {
console.log('π Starting E2E Tests for DTUI2\n');
const results = [];
// Create a mock AI provider
const aiProvider = new AIProvider();
for (const scenario of testScenarios) {
console.log(`Testing: ${scenario.name}`);
try {
const messages = [
{ role: 'user', content: scenario.input, timestamp: Date.now() }
];
const response = await aiProvider.generateResponse(messages);
const passed = scenario.expectedPattern.test(response);
results.push({
scenario: scenario.name,
passed,
input: scenario.input,
response: response.substring(0, 100) + '...'
});
console.log(passed ? ' β
Passed' : ' β Failed');
if (!passed) {
console.log(` Expected pattern: ${scenario.expectedPattern}`);
console.log(` Got: ${response.substring(0, 200)}...`);
}
} catch (error) {
console.log(` β Error: ${error.message}`);
results.push({
scenario: scenario.name,
passed: false,
error: error.message
});
}
}
// Print summary
console.log('\n' + '='.repeat(50));
console.log('π E2E Test Results\n');
const passed = results.filter(r => r.passed).length;
const failed = results.filter(r => !r.passed).length;
const total = results.length;
console.log(`Total: ${total} | Passed: ${passed} | Failed: ${failed}`);
if (failed > 0) {
console.log('\nFailed Scenarios:');
results
.filter(r => !r.passed)
.forEach(r => {
console.log(` β ${r.scenario}`);
if (r.error) console.log(` Error: ${r.error}`);
});
}
const percentage = (passed / total * 100).toFixed(1);
console.log(`\nπ― Success Rate: ${percentage}%`);
if (failed === 0) {
console.log('β¨ All E2E tests passed!');
} else {
console.log('β οΈ Some tests failed. Please review the results above.');
}
}
// Check if we can import the modules
try {
console.log('Note: This test requires the application to be built.');
console.log('Run "npm run build" first if you see module errors.\n');
// For now, just print the test plan
console.log('π Test Plan:');
testScenarios.forEach((s, i) => {
console.log(` ${i + 1}. ${s.name}`);
console.log(` Input: "${s.input}"`);
});
console.log('\nβ
Test scenarios defined successfully!');
console.log('To run actual E2E tests, ensure the app is built first.');
} catch (error) {
console.error('Error:', error.message);
}