// __tests__/setup/jest.setup.js const { initializeTestDB, clearAllTables, disconnectTestDB, } = require("./testDbUtils"); // Optional: Runs once before all test suites beforeAll(async () => { console.log("Global setup: Initializing test database..."); await initializeTestDB(); // Ensure clean slate for the entire test run }); // Runs before each test file (or each test if inside describe block) // For a truly clean slate for each test file or even each test: beforeEach(async () => { // console.log('Resetting tables before test...'); // Depending on your needs, you might re-initialize or just clear tables await clearAllTables(); // This is faster than full re-init if schema doesn't change }); // Optional: Runs once after all test suites afterAll(async () => { console.log("Global teardown: Disconnecting test database pool..."); await disconnectTestDB(); // You might also need to close your main app's DB pool if it's shared or server is kept running // And close Redis connections if your tests directly interact with them const { closeRedis } = require("../../src/config/redis"); // Adjust path await closeRedis(); // If your server is started for integration tests, ensure it's closed. // This is often handled by supertest if 'app' is imported and not globally started. // Or if you start server in globalSetup, close it in globalTeardown. });