116 lines
3.1 KiB
JavaScript
116 lines
3.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Node.js Test Runner for Dragon Code V2.6
|
|
// Loads all dependencies and runs tests in Node environment
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Simulate browser environment
|
|
global.window = {};
|
|
|
|
// Load dependencies
|
|
function loadScript(filename) {
|
|
const filepath = path.join(__dirname, '..', filename);
|
|
const content = fs.readFileSync(filepath, 'utf8');
|
|
eval(content);
|
|
}
|
|
|
|
// Load all JS files
|
|
try {
|
|
loadScript('js/species-data.js');
|
|
loadScript('js/tags-data.js');
|
|
loadScript('js/parser.js');
|
|
loadScript('js/decoder.js');
|
|
|
|
// Load test files
|
|
const testDataPath = path.join(__dirname, 'test-data.js');
|
|
const testData = fs.readFileSync(testDataPath, 'utf8');
|
|
eval(testData);
|
|
|
|
const testRunnerPath = path.join(__dirname, 'test-runner.js');
|
|
const testRunner = fs.readFileSync(testRunnerPath, 'utf8');
|
|
eval(testRunner);
|
|
|
|
} catch (error) {
|
|
console.error('Error loading scripts:', error.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Run tests
|
|
console.log('='.repeat(80));
|
|
console.log('Dragon Code V2.6 - Automated Test Suite');
|
|
console.log('='.repeat(80));
|
|
console.log('');
|
|
|
|
const runner = new TestRunner();
|
|
const results = runner.runAll();
|
|
const summary = runner.generateSummary();
|
|
|
|
console.log('');
|
|
console.log('='.repeat(80));
|
|
console.log('DETAILED FAILURES');
|
|
console.log('='.repeat(80));
|
|
console.log('');
|
|
|
|
// 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.');
|
|
}
|
|
|
|
console.log('');
|
|
console.log('='.repeat(80));
|
|
console.log('SUMMARY BY CATEGORY');
|
|
console.log('='.repeat(80));
|
|
console.log('');
|
|
|
|
// Group by category and show stats
|
|
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('');
|
|
console.log('='.repeat(80));
|
|
|
|
// Write results to file
|
|
const outputPath = path.join(__dirname, 'test-results.json');
|
|
fs.writeFileSync(outputPath, JSON.stringify({
|
|
summary,
|
|
results: results.details,
|
|
categoryStats
|
|
}, null, 2));
|
|
|
|
console.log(`\nDetailed results written to: ${outputPath}`);
|
|
|
|
// Exit with error code if tests failed
|
|
process.exit(results.failed > 0 ? 1 : 0);
|