csvlod-ai-mcp-server
Version:
CSVLOD-AI MCP Server v3.0 with Quantum Context Intelligence - Revolutionary Context Intelligence Engine and Multimodal Processor for sovereign AI development
103 lines (90 loc) • 2.37 kB
text/typescript
import { jest } from '@jest/globals';
// Global test configuration
beforeAll(() => {
// Set test environment variables
process.env.NODE_ENV = 'test';
process.env.CSVLOD_LOG_LEVEL = 'error'; // Reduce logging noise during tests
// Mock external dependencies that aren't available in test environment
jest.mock('fs', () => {
const actual = jest.requireActual('fs') as any;
return {
...actual,
// Add any specific fs mocks if needed
};
});
});
beforeEach(() => {
// Clear any module caches between tests
jest.clearAllMocks();
});
afterEach(() => {
// Cleanup after each test
jest.restoreAllMocks();
});
afterAll(() => {
// Global cleanup
jest.clearAllTimers();
});
// Global test utilities
global.testUtils = {
createTempDir: async () => {
const fs = await import('fs/promises');
const path = await import('path');
const os = await import('os');
return fs.mkdtemp(path.join(os.tmpdir(), 'csvlod-test-'));
},
cleanupTempDir: async (dir: string) => {
const fs = await import('fs/promises');
try {
await fs.rm(dir, { recursive: true, force: true });
} catch (error) {
// Ignore cleanup errors
}
},
mockPerformance: () => {
const originalNow = Date.now;
let mockTime = 1000;
Date.now = jest.fn(() => mockTime);
return {
advance: (ms: number) => {
mockTime += ms;
},
restore: () => {
Date.now = originalNow;
}
};
}
};
// Extend Jest matchers if needed
expect.extend({
toBeWithinRange(received: number, floor: number, ceiling: number) {
const pass = received >= floor && received <= ceiling;
if (pass) {
return {
message: () => `expected ${received} not to be within range ${floor} - ${ceiling}`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to be within range ${floor} - ${ceiling}`,
pass: false,
};
}
},
});
// Declare global types for TypeScript
declare global {
namespace jest {
interface Matchers<R> {
toBeWithinRange(floor: number, ceiling: number): R;
}
}
var testUtils: {
createTempDir(): Promise<string>;
cleanupTempDir(dir: string): Promise<void>;
mockPerformance(): {
advance(ms: number): void;
restore(): void;
};
};
}