setup.ts•1.65 kB
import { jest } from '@jest/globals';
// Set test environment variables
process.env.NODE_ENV = 'test';
process.env.LOG_LEVEL = 'error'; // Reduce log noise during tests
process.env.LOG_TRANSPORT = 'console';
process.env.PORT = '3006'; // Use different port for tests
process.env.CARBON_VOICE_BASE_URL = 'https://api.test.carbonvoice.app';
process.env.CARBON_VOICE_API_KEY = 'test-api-key';
// Mock console methods to reduce noise in tests
global.console = {
...console,
log: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
// Mock fs to avoid file system operations during tests
jest.mock('fs', () => ({
...(jest.requireActual('fs') as any),
existsSync: jest.fn(() => true),
mkdirSync: jest.fn(),
writeFileSync: jest.fn(),
readFileSync: jest.fn(),
}));
// Mock winston-cloudwatch to avoid AWS calls during tests
jest.mock('winston-cloudwatch', () => {
return jest.fn().mockImplementation(() => ({
log: jest.fn(),
}));
});
// Mock AWS SDK
jest.mock('@aws-sdk/client-cloudwatch-logs', () => ({
CloudWatchLogsClient: jest.fn().mockImplementation(() => ({
send: jest.fn(),
})),
PutLogEventsCommand: jest.fn(),
}));
// Global test timeout
jest.setTimeout(10000);
// Clean up after each test
afterEach(() => {
jest.clearAllMocks();
});
// Global error handler for unhandled promise rejections
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});
// Global error handler for uncaught exceptions
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
});