diff --git a/js/decoder.js b/js/decoder.js index 4d6f9c2..6d15073 100644 --- a/js/decoder.js +++ b/js/decoder.js @@ -620,3 +620,8 @@ function getModifierString(modifiers) { return key; } + +// Export for Node.js (CommonJS) +if (typeof module !== 'undefined' && module.exports) { + module.exports = { decodeDragonCode }; +} diff --git a/js/parser.js b/js/parser.js index 313a389..5483825 100644 --- a/js/parser.js +++ b/js/parser.js @@ -736,3 +736,8 @@ function parseTechnology(token) { return result; } + +// Export for Node.js (CommonJS) +if (typeof module !== 'undefined' && module.exports) { + module.exports = { parseDragonCode }; +} diff --git a/js/species-data.js b/js/species-data.js index 9bb35b7..470690b 100644 --- a/js/species-data.js +++ b/js/species-data.js @@ -247,3 +247,8 @@ function resolveSpeciesCode(code) { // Return the accumulated path or the name if we have it 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 }; +} diff --git a/js/tags-data.js b/js/tags-data.js index b85ed53..f805da8 100644 --- a/js/tags-data.js +++ b/js/tags-data.js @@ -406,3 +406,8 @@ const TAG_DESCRIPTIONS = { '---!': "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 }; +} diff --git a/tests/test-data.js b/tests/test-data.js index dc25adf..ef3c6da 100644 --- a/tests/test-data.js +++ b/tests/test-data.js @@ -330,3 +330,8 @@ const INTEGRATION_TESTS = [ } } ]; + +// Export for Node.js (CommonJS) +if (typeof module !== 'undefined' && module.exports) { + module.exports = { TEST_CASES, INTEGRATION_TESTS }; +} diff --git a/tests/test-runner-node.js b/tests/test-runner-node.js index b02895e..1fdf2c3 100644 --- a/tests/test-runner-node.js +++ b/tests/test-runner-node.js @@ -3,39 +3,25 @@ // 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 = {}; +const fs = require('fs'); // Load dependencies -function loadScript(filename) { - const filepath = path.join(__dirname, '..', filename); - const content = fs.readFileSync(filepath, 'utf8'); - eval(content); -} +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'); -// 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); -} +// 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)); diff --git a/tests/test-runner.js b/tests/test-runner.js index d416fa2..9e852ee 100644 --- a/tests/test-runner.js +++ b/tests/test-runner.js @@ -282,3 +282,8 @@ class TestRunner { if (typeof window !== 'undefined') { window.TestRunner = TestRunner; } + +// Export for Node.js (CommonJS) +if (typeof module !== 'undefined' && module.exports) { + module.exports = { TestRunner }; +}