Skip to content

Commit 1f369a5

Browse files
committed
Fix Demo 01 test to work with ES6 modules
Update test-demo01-eliza.mjs to properly import ES6 modules instead of using eval(). The previous approach broke after converting Demo 01 to ES6 modules. Changes: - Import PatternMatcher and ElizaEngine using dynamic import() - Use pathToFileURL() to convert file paths to proper URLs - Add mock fetch() function for loading rules - Remove eval() code that doesn't work with ES6 import statements All 144 tests now passing. Fixes CI test failure for Demo 01.
1 parent 8bfcd97 commit 1f369a5

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

tests/test-demo01-eliza.mjs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { readFile } from 'fs/promises';
19-
import { fileURLToPath } from 'url';
19+
import { fileURLToPath, pathToFileURL } from 'url';
2020
import { dirname, join } from 'path';
2121

2222
const __filename = fileURLToPath(import.meta.url);
@@ -25,28 +25,25 @@ const __dirname = dirname(__filename);
2525
// Mock DOM globals for browser-based code
2626
global.window = {};
2727
global.document = {};
28+
global.fetch = async function(url) {
29+
// Mock fetch for loading rules
30+
const content = await readFile(join(__dirname, '../demos/01-eliza', url), 'utf-8');
31+
return {
32+
json: async () => JSON.parse(content)
33+
};
34+
};
2835

29-
// Load the required modules
30-
const patternMatcherCode = await readFile(join(__dirname, '../demos/01-eliza/js/pattern-matcher.js'), 'utf-8');
31-
const elizaEngineCode = await readFile(join(__dirname, '../demos/01-eliza/js/eliza-engine.js'), 'utf-8');
36+
// Import the ES6 modules directly using file URLs
37+
const patternMatcherPath = pathToFileURL(join(__dirname, '../demos/01-eliza/js/pattern-matcher.js')).href;
38+
const elizaEnginePath = pathToFileURL(join(__dirname, '../demos/01-eliza/js/eliza-engine.js')).href;
3239

33-
// Execute PatternMatcher code
34-
global.module = { exports: {} };
35-
eval(patternMatcherCode);
36-
const PatternMatcher = global.module.exports;
40+
const { PatternMatcher } = await import(patternMatcherPath);
41+
const { ElizaEngine } = await import(elizaEnginePath);
3742

3843
if (!PatternMatcher) {
3944
throw new Error('Failed to load PatternMatcher class');
4045
}
4146

42-
// Make PatternMatcher globally available for ElizaEngine
43-
global.PatternMatcher = PatternMatcher;
44-
45-
// Execute ElizaEngine code
46-
global.module = { exports: {} };
47-
eval(elizaEngineCode);
48-
const ElizaEngine = global.module.exports;
49-
5047
if (!ElizaEngine) {
5148
throw new Error('Failed to load ElizaEngine class');
5249
}

0 commit comments

Comments
 (0)