-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-runner.js
More file actions
176 lines (151 loc) Β· 4.78 KB
/
test-runner.js
File metadata and controls
176 lines (151 loc) Β· 4.78 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
#!/usr/bin/env node
/**
* Test Runner for DTUI2 - Runs all test suites
*/
const { spawn } = require('child_process');
const fs = require('fs').promises;
const path = require('path');
// Colors for terminal output
const colors = {
reset: '\x1b[0m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
gray: '\x1b[90m'
};
function log(message, color = 'reset') {
console.log(`${colors[color]}${message}${colors.reset}`);
}
async function runCommand(command, args = [], options = {}) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
stdio: 'inherit',
shell: true,
...options
});
child.on('close', (code) => {
if (code === 0) {
resolve(code);
} else {
reject(new Error(`Command failed with exit code ${code}`));
}
});
child.on('error', reject);
});
}
async function checkDependencies() {
log('\nπ Checking dependencies...', 'blue');
try {
// Check if Playwright is installed
await fs.access('./node_modules/.bin/playwright');
log('β
Playwright installed', 'green');
} catch {
log('β Playwright not found. Installing...', 'red');
await runCommand('npm', ['install', '--save-dev', 'playwright', '@playwright/test']);
await runCommand('npx', ['playwright', 'install']);
}
// Check if app builds
try {
log('π¨ Building application...', 'blue');
await runCommand('npm', ['run', 'build']);
log('β
Build successful', 'green');
} catch (error) {
log('β Build failed', 'red');
throw error;
}
}
async function runTestSuite(name, command, description) {
log(`\nπ§ͺ Running ${name}...`, 'blue');
log(`π ${description}`, 'gray');
try {
await runCommand(command, [], { shell: true });
log(`β
${name} passed`, 'green');
return true;
} catch (error) {
log(`β ${name} failed`, 'red');
return false;
}
}
async function main() {
log('π DTUI2 Test Suite Runner', 'blue');
log('=' .repeat(50), 'blue');
const testResults = [];
let totalTests = 0;
let passedTests = 0;
try {
// Check dependencies first
await checkDependencies();
// Define test suites
const testSuites = [
{
name: 'Unit Tests',
command: 'npm test',
description: 'Basic application functionality tests'
},
{
name: 'Configuration Tests',
command: 'npm run test:config',
description: '3-tier configuration system tests'
},
{
name: 'Shell Integration Tests',
command: 'npm run test:fakeshell',
description: 'Shell agent integration tests'
},
{
name: 'GUI Output Format Tests',
command: 'npm run test:gui',
description: 'Playwright GUI tests for shell output formats'
}
];
// Run each test suite
for (const testSuite of testSuites) {
totalTests++;
const passed = await runTestSuite(testSuite.name, testSuite.command, testSuite.description);
if (passed) passedTests++;
testResults.push({ ...testSuite, passed });
}
} catch (error) {
log(`π₯ Test runner failed: ${error.message}`, 'red');
process.exit(1);
}
// Summary
log('\n' + '=' .repeat(50), 'blue');
log(`π Test Results: ${passedTests}/${totalTests} passed`,
passedTests === totalTests ? 'green' : 'yellow');
log('=' .repeat(50), 'blue');
// Detailed results
log('\nπ Detailed Results:', 'blue');
testResults.forEach((result, index) => {
const status = result.passed ? 'β
' : 'β';
const color = result.passed ? 'green' : 'red';
log(` ${status} ${index + 1}. ${result.name}`, color);
if (!result.passed) {
log(` ${result.description}`, 'gray');
}
});
// Additional information
if (passedTests < totalTests) {
log('\nπ‘ Some tests failed. To debug:', 'yellow');
log(' - Run individual test suites to see specific failures', 'gray');
log(' - Use npm run test:gui:headed for visual debugging', 'gray');
log(' - Check the Playwright test report in playwright-report/', 'gray');
}
log('\nπ― Test Commands Available:', 'blue');
log(' npm test - Basic unit tests', 'gray');
log(' npm run test:config - Configuration tests', 'gray');
log(' npm run test:fakeshell- Shell integration tests', 'gray');
log(' npm run test:gui - GUI tests (headless)', 'gray');
log(' npm run test:gui:headed - GUI tests (with UI)', 'gray');
log(' npm run test:gui:debug - GUI tests (debug mode)', 'gray');
process.exit(passedTests === totalTests ? 0 : 1);
}
// Run if executed directly
if (require.main === module) {
main().catch(error => {
log(`π₯ Unexpected error: ${error.message}`, 'red');
process.exit(1);
});
}
module.exports = { runTestSuite, checkDependencies };