Fix Node.js test runner with CommonJS exports

This commit is contained in:
2026-02-01 14:31:27 +02:00
parent db3e46de18
commit 55ede2679e
7 changed files with 45 additions and 29 deletions

View File

@@ -620,3 +620,8 @@ function getModifierString(modifiers) {
return key; return key;
} }
// Export for Node.js (CommonJS)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { decodeDragonCode };
}

View File

@@ -736,3 +736,8 @@ function parseTechnology(token) {
return result; return result;
} }
// Export for Node.js (CommonJS)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { parseDragonCode };
}

View File

@@ -247,3 +247,8 @@ function resolveSpeciesCode(code) {
// Return the accumulated path or the name if we have it // Return the accumulated path or the name if we have it
return path.length > 0 ? path[path.length - 1] : null; return path.length > 0 ? path[path.length - 1] : null;
} }
// Export for Node.js (CommonJS)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { SPECIES_DATA, resolveSpeciesCode };
}

View File

@@ -406,3 +406,8 @@ const TAG_DESCRIPTIONS = {
'---!': "Cold fury - they're going to hunt you, and find you, and..." '---!': "Cold fury - they're going to hunt you, and find you, and..."
} }
}; };
// Export for Node.js (CommonJS)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { TAG_DESCRIPTIONS };
}

View File

@@ -330,3 +330,8 @@ const INTEGRATION_TESTS = [
} }
} }
]; ];
// Export for Node.js (CommonJS)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { TEST_CASES, INTEGRATION_TESTS };
}

View File

@@ -3,39 +3,25 @@
// Node.js Test Runner for Dragon Code V2.6 // Node.js Test Runner for Dragon Code V2.6
// Loads all dependencies and runs tests in Node environment // Loads all dependencies and runs tests in Node environment
const fs = require('fs');
const path = require('path'); const path = require('path');
const fs = require('fs');
// Simulate browser environment
global.window = {};
// Load dependencies // Load dependencies
function loadScript(filename) { const { SPECIES_DATA, resolveSpeciesCode } = require('../js/species-data.js');
const filepath = path.join(__dirname, '..', filename); const { TAG_DESCRIPTIONS } = require('../js/tags-data.js');
const content = fs.readFileSync(filepath, 'utf8'); const { parseDragonCode } = require('../js/parser.js');
eval(content); const { decodeDragonCode } = require('../js/decoder.js');
} const { TEST_CASES, INTEGRATION_TESTS } = require('./test-data.js');
const { TestRunner } = require('./test-runner.js');
// Load all JS files // Make globally accessible for test runner compatibility
try { global.SPECIES_DATA = SPECIES_DATA;
loadScript('js/species-data.js'); global.resolveSpeciesCode = resolveSpeciesCode;
loadScript('js/tags-data.js'); global.TAG_DESCRIPTIONS = TAG_DESCRIPTIONS;
loadScript('js/parser.js'); global.parseDragonCode = parseDragonCode;
loadScript('js/decoder.js'); global.decodeDragonCode = decodeDragonCode;
global.TEST_CASES = TEST_CASES;
// Load test files global.INTEGRATION_TESTS = INTEGRATION_TESTS;
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 // Run tests
console.log('='.repeat(80)); console.log('='.repeat(80));

View File

@@ -282,3 +282,8 @@ class TestRunner {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
window.TestRunner = TestRunner; window.TestRunner = TestRunner;
} }
// Export for Node.js (CommonJS)
if (typeof module !== 'undefined' && module.exports) {
module.exports = { TestRunner };
}