Add test environment configuration and update Jest setup

- Created `.env.test.example` with test environment variables
- Updated `jest.config.cjs` to simplify configuration and improve test setup
- Added `jest.setup.ts` to load and configure test environment variables
- Updated test files to use dynamic test environment configuration
- Enhanced README.md with additional configuration details for testing
This commit is contained in:
jango-blockchained
2025-01-30 09:56:19 +01:00
parent b3fa5f729e
commit 3115c41e87
5 changed files with 362 additions and 42 deletions

15
jest.setup.ts Normal file
View File

@@ -0,0 +1,15 @@
import { config } from 'dotenv';
import { resolve } from 'path';
// Load test environment variables
const envFile = process.env.NODE_ENV === 'test' ? '.env.test' : '.env';
config({ path: resolve(__dirname, envFile) });
// Set default test environment variables if not provided
process.env.TEST_HASS_HOST = process.env.TEST_HASS_HOST || 'http://localhost:8123';
process.env.TEST_HASS_TOKEN = process.env.TEST_HASS_TOKEN || 'test_token';
process.env.TEST_HASS_SOCKET_URL = process.env.TEST_HASS_SOCKET_URL || 'ws://localhost:8123/api/websocket';
process.env.TEST_PORT = process.env.TEST_PORT || '3001';
// Ensure test environment
process.env.NODE_ENV = 'test';