Files
homeassistant-mcp/jest.setup.ts
jango-blockchained 96aaffd952 Update project configuration and testing infrastructure
- Refactored Jest configuration for improved ESM and TypeScript support
- Updated `jest.setup.ts` with comprehensive test environment configuration
- Enhanced mocking for WebSocket, console, and external dependencies
- Adjusted package.json dependencies and scripts
- Updated tsconfig.json with decorator and test exclusion settings
- Improved test coverage configuration and reporting
- Simplified test file structure and mocking strategies
2025-01-30 20:06:40 +01:00

84 lines
2.1 KiB
TypeScript

import { jest } from '@jest/globals';
import dotenv from 'dotenv';
import { TextEncoder, TextDecoder } from 'util';
// Load test environment variables
dotenv.config({ path: '.env.test' });
// Set test environment
process.env.NODE_ENV = 'test';
process.env.HASS_URL = 'http://localhost:8123';
process.env.HASS_TOKEN = 'test_token';
process.env.CLAUDE_API_KEY = 'test_api_key';
process.env.CLAUDE_MODEL = 'test_model';
// Add TextEncoder and TextDecoder to global scope
Object.defineProperty(global, 'TextEncoder', {
value: TextEncoder,
writable: true
});
Object.defineProperty(global, 'TextDecoder', {
value: TextDecoder,
writable: true
});
// Configure console for tests
const originalConsole = { ...console };
global.console = {
...console,
log: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
// Increase test timeout
jest.setTimeout(30000);
// Mock WebSocket
jest.mock('ws', () => {
return {
WebSocket: jest.fn().mockImplementation(() => ({
on: jest.fn(),
send: jest.fn(),
close: jest.fn(),
removeAllListeners: jest.fn()
}))
};
});
// Mock chalk
jest.mock('chalk', () => ({
default: {
red: (text: string) => text,
green: (text: string) => text,
yellow: (text: string) => text,
blue: (text: string) => text,
magenta: (text: string) => text,
cyan: (text: string) => text,
white: (text: string) => text,
gray: (text: string) => text,
grey: (text: string) => text,
black: (text: string) => text,
bold: (text: string) => text,
dim: (text: string) => text,
italic: (text: string) => text,
underline: (text: string) => text,
inverse: (text: string) => text,
hidden: (text: string) => text,
strikethrough: (text: string) => text,
visible: (text: string) => text,
}
}));
// Reset mocks between tests
beforeEach(() => {
jest.clearAllMocks();
});
// Cleanup after tests
afterEach(() => {
jest.clearAllTimers();
});