/** * Setup file - Runs before EACH test file * Initialize server singleton here */ const Server = require('../src/server'); // Singleton pattern - initialize only once let serverInstance = null; let app = null; async function initializeTestServer() { if (!app) { console.log('🔧 Initializing test server (one-time)...'); process.env.NODE_ENV = 'test'; process.env.PORT = 5001; process.env.ADMIN_API_KEY = 'test-admin-key-12345'; serverInstance = new Server(5001); app = await serverInstance.initializeApp(); global.__TEST_SERVER__ = serverInstance; global.__TEST_APP__ = app; console.log('✅ Test server ready'); } return app; } // Initialize before all tests beforeAll(async () => { await initializeTestServer(); }); // Test timeout jest.setTimeout(10000); // Suppress logs during tests global.console = { ...console, log: jest.fn(), info: jest.fn(), debug: jest.fn(), error: console.error, warn: console.warn, };