memoryBankServer.test.ts•2.47 kB
import { test, expect, describe, beforeEach, afterEach } from 'bun:test';
import fs from 'fs-extra';
import path from 'path';
import { fileURLToPath } from 'url';
import { MemoryBankServer } from '../../server/MemoryBankServer.js';
// Get the directory name
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
describe('MemoryBankServer Tests', () => {
const tempDir = path.join(__dirname, 'temp-server-test-dir');
const projectPath = path.join(tempDir, 'project');
let server: MemoryBankServer;
beforeEach(async () => {
// Create temporary directories
await fs.ensureDir(tempDir);
await fs.ensureDir(projectPath);
});
afterEach(async () => {
// Shutdown server if running
if (server) {
await server.shutdown();
}
// Clean up
await fs.remove(tempDir);
});
test('Should initialize with project path', async () => {
// Create a new MemoryBankServer with a project path
server = new MemoryBankServer('code', projectPath);
// Start the server (but don't wait for it to run)
const runPromise = server.run();
// Wait a short time for initialization
await new Promise(resolve => setTimeout(resolve, 100));
// Shutdown the server
await server.shutdown();
// Verify the memory bank directory was created in the project path
const memoryBankExists = await fs.pathExists(path.join(projectPath, 'memory-bank'));
expect(memoryBankExists).toBe(true);
// Verify core files were created
const activeContextExists = await fs.pathExists(path.join(projectPath, 'memory-bank', 'active-context.md'));
expect(activeContextExists).toBe(true);
});
test('Should use default path when not provided', async () => {
// Create a new MemoryBankServer without a project path
server = new MemoryBankServer('code');
// Get the default path (should be process.cwd())
const defaultPath = process.cwd();
// Start the server (but don't wait for it to run)
const runPromise = server.run();
// Wait a short time for initialization
await new Promise(resolve => setTimeout(resolve, 100));
// Shutdown the server
await server.shutdown();
// Verify the memory bank directory was created in the default path
const memoryBankExists = await fs.pathExists(path.join(defaultPath, 'memory-bank'));
expect(memoryBankExists).toBe(true);
});
});