Initial version
This commit is contained in:
98
tests/run-tests.html
Normal file
98
tests/run-tests.html
Normal file
@@ -0,0 +1,98 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Dragon Code Tests - Auto Runner</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Running Tests...</h1>
|
||||
<pre id="output"></pre>
|
||||
|
||||
<script src="../js/species-data.js"></script>
|
||||
<script src="../js/tags-data.js"></script>
|
||||
<script src="../js/parser.js"></script>
|
||||
<script src="../js/decoder.js"></script>
|
||||
<script src="test-data.js"></script>
|
||||
<script src="test-runner.js"></script>
|
||||
<script>
|
||||
// Auto-run tests and output to console and page
|
||||
const output = document.getElementById('output');
|
||||
const originalLog = console.log;
|
||||
|
||||
let logBuffer = [];
|
||||
console.log = function(...args) {
|
||||
const message = args.join(' ');
|
||||
logBuffer.push(message);
|
||||
output.textContent += message + '\n';
|
||||
originalLog.apply(console, args);
|
||||
};
|
||||
|
||||
// Run tests
|
||||
const runner = new TestRunner();
|
||||
const results = runner.runAll();
|
||||
const summary = runner.generateSummary();
|
||||
|
||||
console.log('\n' + '='.repeat(80));
|
||||
console.log('DETAILED FAILURES');
|
||||
console.log('='.repeat(80) + '\n');
|
||||
|
||||
// Show only failures
|
||||
let failureCount = 0;
|
||||
results.details.forEach(detail => {
|
||||
if (!detail.passed) {
|
||||
failureCount++;
|
||||
console.log(`[${detail.category.toUpperCase()}] ${detail.test}`);
|
||||
console.log(` Expected: ${JSON.stringify(detail.expected)}`);
|
||||
console.log(` Got: ${detail.actual || 'null'}`);
|
||||
if (detail.error) {
|
||||
console.log(` Error: ${detail.error}`);
|
||||
}
|
||||
console.log('');
|
||||
}
|
||||
});
|
||||
|
||||
if (failureCount === 0) {
|
||||
console.log('🎉 All tests passed! No failures to report.\n');
|
||||
}
|
||||
|
||||
console.log('='.repeat(80));
|
||||
console.log('SUMMARY BY CATEGORY');
|
||||
console.log('='.repeat(80) + '\n');
|
||||
|
||||
// Group by category
|
||||
const categoryStats = {};
|
||||
results.details.forEach(detail => {
|
||||
if (!categoryStats[detail.category]) {
|
||||
categoryStats[detail.category] = { passed: 0, failed: 0, total: 0 };
|
||||
}
|
||||
categoryStats[detail.category].total++;
|
||||
if (detail.passed) {
|
||||
categoryStats[detail.category].passed++;
|
||||
} else {
|
||||
categoryStats[detail.category].failed++;
|
||||
}
|
||||
});
|
||||
|
||||
for (const [category, stats] of Object.entries(categoryStats)) {
|
||||
const passRate = ((stats.passed / stats.total) * 100).toFixed(1);
|
||||
const status = stats.failed === 0 ? '✓' : '✗';
|
||||
console.log(`${status} ${category.padEnd(20)} ${stats.passed}/${stats.total} (${passRate}%)`);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(80));
|
||||
|
||||
// Create downloadable file
|
||||
const blob = new Blob([logBuffer.join('\n')], { type: 'text/plain' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = 'test-results.txt';
|
||||
link.textContent = 'Download Test Results';
|
||||
link.style.cssText = 'display:block;margin:20px;padding:10px;background:#3498db;color:white;text-decoration:none;border-radius:4px;width:200px;text-align:center';
|
||||
document.body.insertBefore(link, output);
|
||||
|
||||
// Auto-download (commented out - enable if desired)
|
||||
// link.click();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user