← back to Designer Wallcoverings
DW-Agents/__tests__/setup.ts
78 lines
/**
* Jest Test Setup
* Global configuration and utilities for all tests
*/
// Extend Jest timeout for integration tests
jest.setTimeout(10000);
// Global test configuration
global.testConfig = {
baseURL: process.env.BASE_URL || 'http://localhost',
masterHubPort: process.env.MASTER_HUB_PORT || '9800',
testTimeout: 10000
};
// Mock console methods in test environment to reduce noise
global.console = {
...console,
// Uncomment to suppress logs during tests
// log: jest.fn(),
// debug: jest.fn(),
// info: jest.fn(),
warn: console.warn,
error: console.error,
};
// Global test utilities
global.testUtils = {
/**
* Wait for a condition to be true
*/
async waitFor(condition: () => boolean | Promise<boolean>, timeout = 5000): Promise<void> {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {
if (await condition()) {
return;
}
await new Promise(resolve => setTimeout(resolve, 100));
}
throw new Error(`Timeout waiting for condition after ${timeout}ms`);
},
/**
* Retry an async operation
*/
async retry<T>(
operation: () => Promise<T>,
retries = 3,
delay = 1000
): Promise<T> {
for (let i = 0; i < retries; i++) {
try {
return await operation();
} catch (error) {
if (i === retries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, delay));
}
}
throw new Error('Retry failed');
}
};
// Declare global types
declare global {
var testConfig: {
baseURL: string;
masterHubPort: string;
testTimeout: number;
};
var testUtils: {
waitFor(condition: () => boolean | Promise<boolean>, timeout?: number): Promise<void>;
retry<T>(operation: () => Promise<T>, retries?: number, delay?: number): Promise<T>;
};
}
export {};