102 lines
3.0 KiB
JavaScript
102 lines
3.0 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 path = require('path');
|
|
const fs = require('fs');
|
|
|
|
// Load dependencies
|
|
const { SPECIES_DATA, resolveSpeciesCode } = require('../js/species-data.js');
|
|
const { TAG_DESCRIPTIONS } = require('../js/tags-data.js');
|
|
const { parseDragonCode } = require('../js/parser.js');
|
|
const { decodeDragonCode } = require('../js/decoder.js');
|
|
const { TEST_CASES, INTEGRATION_TESTS } = require('./test-data.js');
|
|
const { TestRunner } = require('./test-runner.js');
|
|
|
|
// Make globally accessible for test runner compatibility
|
|
global.SPECIES_DATA = SPECIES_DATA;
|
|
global.resolveSpeciesCode = resolveSpeciesCode;
|
|
global.TAG_DESCRIPTIONS = TAG_DESCRIPTIONS;
|
|
global.parseDragonCode = parseDragonCode;
|
|
global.decodeDragonCode = decodeDragonCode;
|
|
global.TEST_CASES = TEST_CASES;
|
|
global.INTEGRATION_TESTS = INTEGRATION_TESTS;
|
|
|
|
// 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);
|