/** * ================================================================ * E2E Test Database Reset Global Setup * ================================================================ * Runs reset-db.sh before all E2E tests to ensure clean database state * * Usage: * Add to playwright.config.js: * globalSetup: path.join(__dirname, 'e2e', 'helpers', 'db.js') * ================================================================ */ var path = require('path'); var child_process = require('child_process'); var SCRIPT_PATH = path.join(__dirname, '..', 'reset-db.sh'); /** * Reset database by executing reset-db.sh * This function is called as globalSetup before all E2E tests * @throws {Error} - If script execution fails */ function resetDatabase() { console.log('============================================================'); console.log('E2E Global Setup: Running Database Reset'); console.log('============================================================'); console.log('Script path: ' + SCRIPT_PATH); console.log('============================================================'); try { // Execute the reset-db.sh script // Using execSync for synchronous execution in globalSetup child_process.execSync('bash ' + SCRIPT_PATH, { stdio: 'inherit', cwd: __dirname }); console.log('============================================================'); console.log('E2E Global Setup: Database Reset Complete'); console.log('============================================================'); } catch (error) { console.error('============================================================'); console.error('E2E Global Setup: Database Reset FAILED'); console.error('============================================================'); console.error('Error: ' + error.message); console.error('============================================================'); console.error('Please check:'); console.error(' 1. MySQL server is running'); console.error(' 2. Network access to ' + (process.env.MYSQL_HOST || '192.168.16.251') + ' is available'); console.error(' 3. reset-db.sh exists at: ' + SCRIPT_PATH); console.error(' 4. seed-data.sql exists in the e2e directory'); console.error('============================================================'); process.exit(1); } } // Run if executed directly resetDatabase(); // ================================================================ // Module exports (CommonJS) // ================================================================ module.exports = resetDatabase;