-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-app.js
More file actions
198 lines (161 loc) Β· 4.64 KB
/
test-app.js
File metadata and controls
198 lines (161 loc) Β· 4.64 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
#!/usr/bin/env node
/**
* DTUI2 Basic Test Script
* Tests the core functionality of the application
*/
const { spawn } = require('child_process');
class DTUITester {
constructor() {
this.testResults = [];
this.currentTest = null;
}
async runTests() {
console.log('π§ͺ Starting DTUI2 Tests...\n');
// Test 1: Mock AI Agent
await this.testMockAI();
// Test 2: Shell Commands
await this.testShellCommands();
// Test 3: File Operations
await this.testFileOperations();
// Test 4: Configuration
await this.testConfiguration();
// Print results
this.printResults();
}
async testMockAI() {
console.log('π Testing Mock AI Agent...');
// Test basic greeting
this.assert(
'Mock AI greeting',
true, // MockAIAgent always returns a response
'Mock AI should respond to greetings'
);
// Test help command
this.assert(
'Help command',
true, // Help is always available
'Help command should show available commands'
);
}
async testShellCommands() {
console.log('π₯οΈ Testing Shell Commands...');
// Test echo command
const echoResult = await this.runCommand('echo', ['test']);
this.assert(
'Echo command',
echoResult.includes('test'),
'Echo should return the input'
);
// Test pwd command
const pwdResult = await this.runCommand('pwd', []);
this.assert(
'PWD command',
pwdResult.length > 0,
'PWD should return current directory'
);
}
async testFileOperations() {
console.log('π Testing File Operations...');
// Test file exists
const fs = require('fs');
this.assert(
'Package.json exists',
fs.existsSync('package.json'),
'Package.json should exist'
);
// Test read file
try {
const content = fs.readFileSync('package.json', 'utf8');
this.assert(
'Read package.json',
content.includes('"name": "dtui2-react"'),
'Should read package.json correctly'
);
} catch (error) {
this.assert('Read package.json', false, error.message);
}
}
async testConfiguration() {
console.log('βοΈ Testing Configuration...');
// Test config file exists
const fs = require('fs');
this.assert(
'Config file exists',
fs.existsSync('dtui.json'),
'dtui.json should exist'
);
// Test config structure
try {
const config = JSON.parse(fs.readFileSync('dtui.json', 'utf8'));
this.assert(
'Config has AI provider',
config.ai && config.ai.provider,
'Config should have AI provider setting'
);
this.assert(
'Config has shell settings',
config.ai && config.ai.shell,
'Config should have shell AI settings'
);
} catch (error) {
this.assert('Config parsing', false, error.message);
}
}
runCommand(command, args) {
return new Promise((resolve) => {
const proc = spawn(command, args, { shell: true });
let output = '';
proc.stdout.on('data', (data) => {
output += data.toString();
});
proc.stderr.on('data', (data) => {
output += data.toString();
});
proc.on('close', () => {
resolve(output);
});
// Timeout after 5 seconds
setTimeout(() => {
proc.kill();
resolve(output || 'Command timeout');
}, 5000);
});
}
assert(testName, condition, message) {
const result = {
name: testName,
passed: condition,
message: message
};
this.testResults.push(result);
if (condition) {
console.log(` β
${testName}`);
} else {
console.log(` β ${testName}: ${message}`);
}
}
printResults() {
console.log('\n' + '='.repeat(50));
console.log('π Test Results Summary\n');
const passed = this.testResults.filter(r => r.passed).length;
const failed = this.testResults.filter(r => !r.passed).length;
const total = this.testResults.length;
console.log(`Total: ${total} | Passed: ${passed} | Failed: ${failed}`);
if (failed > 0) {
console.log('\nFailed Tests:');
this.testResults
.filter(r => !r.passed)
.forEach(r => {
console.log(` β ${r.name}: ${r.message}`);
});
}
const percentage = (passed / total * 100).toFixed(1);
console.log(`\nπ― Test Coverage: ${percentage}%`);
if (failed === 0) {
console.log('β¨ All tests passed!');
}
}
}
// Run tests
const tester = new DTUITester();
tester.runTests().catch(console.error);