formies/__tests__/setup/jest.setup.js
Mohamad.Elsena a3236ae9d5 Refactor environment configuration for PostgreSQL and enhance application structure
- Updated `.env` and `.env.test` files to include PostgreSQL connection settings and Redis configuration.
- Migrated database from SQLite to PostgreSQL, updating relevant queries and connection logic.
- Enhanced error handling and logging throughout the application.
- Added new test utilities for PostgreSQL integration and updated user model methods.
- Introduced new routes for user authentication and form management, ensuring compatibility with the new database structure.
- Created login and registration views in EJS for user interaction.
2025-05-28 16:16:33 +02:00

35 lines
1.3 KiB
JavaScript

// __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.
});