setup.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Jest setup file for Pacifica Wash Trading System
  3. * Global test configuration and utilities
  4. */
  5. import { config } from 'dotenv';
  6. // Load environment variables for testing
  7. config({ path: '.env.test' });
  8. // Set default test environment variables
  9. process.env.NODE_ENV = 'test';
  10. process.env.LOG_LEVEL = 'error';
  11. process.env.PACIFICA_API_KEY = 'test-api-key';
  12. process.env.PACIFICA_BASE_URL = 'https://api.test.pacifica.fi';
  13. process.env.WEBSOCKET_URL = 'wss://ws.test.pacifica.fi';
  14. process.env.ENCRYPTION_KEY = 'test-encryption-key-32-characters';
  15. // Global test timeout
  16. jest.setTimeout(30000);
  17. // Mock console methods in tests to reduce noise
  18. global.console = {
  19. ...console,
  20. log: jest.fn(),
  21. debug: jest.fn(),
  22. info: jest.fn(),
  23. warn: jest.fn(),
  24. error: jest.fn(),
  25. };
  26. // Global test utilities
  27. global.testUtils = {
  28. generateId: () => `test-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
  29. sleep: (ms: number) => new Promise(resolve => setTimeout(resolve, ms)),
  30. mockDate: (date: Date) => {
  31. jest.useFakeTimers();
  32. jest.setSystemTime(date);
  33. },
  34. restoreDate: () => {
  35. jest.useRealTimers();
  36. }
  37. };
  38. // Cleanup after each test
  39. afterEach(() => {
  40. jest.clearAllMocks();
  41. jest.restoreAllMocks();
  42. });
  43. // Global cleanup
  44. afterAll(() => {
  45. jest.useRealTimers();
  46. });