Add comprehensive Home Assistant WebSocket and API tests

- Created detailed test suite for Home Assistant WebSocket client
- Implemented tests for WebSocket connection, authentication, and error handling
- Added comprehensive test coverage for HassInstanceImpl API methods
- Mocked WebSocket and fetch to simulate various connection scenarios
- Covered authentication, state retrieval, service calls, and environment configuration
- Improved test infrastructure for Home Assistant integration
This commit is contained in:
jango-blockchained
2025-01-31 20:29:24 +01:00
parent 90cf0ca315
commit 59cbd2552b
6 changed files with 410 additions and 131 deletions

View File

@@ -50,28 +50,28 @@ jest.mock('ws', () => {
});
// 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,
}
}));
const createChalkMock = () => {
const handler = {
get(target: any, prop: string) {
if (prop === 'default') {
return createChalkMock();
}
return typeof prop === 'string' ? createChalkMock() : target[prop];
},
apply(target: any, thisArg: any, args: any[]) {
return args[0];
}
};
return new Proxy(() => { }, handler);
};
jest.mock('chalk', () => createChalkMock());
// Mock ansi-styles
jest.mock('ansi-styles', () => ({}), { virtual: true });
// Mock supports-color
jest.mock('supports-color', () => ({}), { virtual: true });
// Reset mocks between tests
beforeEach(() => {