module.exports = { e2e: { viewportWidth: 1920, viewportHeight: 1080, numTestsKeptInMemory: 0, experimentalMemoryManagement: true, video: false, screenshotOnRunFailure: false, defaultCommandTimeout: 10000, pageLoadTimeout: 30000, retries: { runMode: 1, openMode: 0 }, setupNodeEvents(on, config) { const fs = require('fs'); const path = require('path'); on('before:browser:launch', (browser = {}, launchOptions) => { if (browser.name === 'chrome' || browser.name === 'electron') { launchOptions.args.push( '--js-flags="--expose-gc"', '--disable-dev-shm-usage', '--disable-background-timer-throttling', '--disable-renderer-backgrounding', '--disable-backgrounding-occluded-windows', '--memory-pressure-off', '--disable-site-isolation-trials', '--js-flags="--max-old-space-size=8192"', '--disable-gpu', '--disable-notifications', '--disable-extensions', '--no-sandbox', '--disable-software-rasterizer', '--disable-logging', '--disable-web-security', '--disable-translate', '--disable-features=site-per-process', '--disable-features=TranslateUI', '--disable-features=GlobalMediaControls' ); } return launchOptions; }); on('task', { clearMemory() { try { if (global.gc) { global.gc(); } return null; } catch (e) { console.error('GC failed:', e); return null; } }, createReportDir(dirPath) { try { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive: true }); } return null; } catch (e) { console.error('Create report directory failed:', e); return null; } }, readAllReports(environment) { try { const reportsDir = path.join(__dirname, 'cypress', 'reports'); const reports = []; const files = fs.readdirSync(reportsDir); files.forEach(file => { if (file.startsWith(`${environment}-menu-test-report-batch-`) && file.endsWith('.json')) { const filePath = path.join(reportsDir, file); const content = fs.readFileSync(filePath, 'utf8'); reports.push(JSON.parse(content)); } }); return reports; } catch (e) { console.error('Read reports failed:', e); return []; } }, cleanupReports(environment) { try { const reportsDir = path.join(__dirname, 'cypress', 'reports'); const files = fs.readdirSync(reportsDir); files.forEach(file => { if (file.startsWith(`${environment}-menu-test-report-batch-`) && file.endsWith('.json')) { fs.unlinkSync(path.join(reportsDir, file)); } }); return null; } catch (e) { console.error('Cleanup reports failed:', e); return null; } }, saveReport({ data, filename }) { try { const reportsDir = path.join(__dirname, 'cypress', 'reports'); if (!fs.existsSync(reportsDir)) { fs.mkdirSync(reportsDir, { recursive: true }); } fs.writeFileSync( path.join(reportsDir, filename), JSON.stringify(data, null, 0) ); return null; } catch (e) { console.error('Save report failed:', e); return null; } } }); return config; }, }, };