|
| 1 | +import { defineConfig } from 'cypress'; |
| 2 | +import path from 'path'; |
| 3 | +import fs from 'fs'; |
| 4 | + |
| 5 | +// Plugins |
| 6 | +import registerCodeCoverage from '@cypress/code-coverage/task'; |
| 7 | +import cypressGrepPlugin from '@cypress/grep/src/plugin'; |
| 8 | + |
| 9 | +const reportDir = process.env.ARTIFACT_DIR || '/tmp'; |
| 10 | + |
| 11 | +export default defineConfig({ |
| 12 | + // --- General Settings --- |
| 13 | + fixturesFolder: 'fixtures', |
| 14 | + defaultCommandTimeout: 30000, |
| 15 | + viewportWidth: 1600, |
| 16 | + viewportHeight: 1200, |
| 17 | + retries: { |
| 18 | + runMode: 0, |
| 19 | + openMode: 0, |
| 20 | + }, |
| 21 | + |
| 22 | + // --- Artifacts & Reporting --- |
| 23 | + screenshotsFolder: path.join(reportDir, 'cypress', 'screenshots'), |
| 24 | + screenshotOnRunFailure: true, |
| 25 | + trashAssetsBeforeRuns: true, |
| 26 | + videosFolder: path.join(reportDir, 'cypress', 'videos'), |
| 27 | + video: true, |
| 28 | + videoCompression: false, |
| 29 | + |
| 30 | + reporter: './node_modules/cypress-multi-reporters', |
| 31 | + reporterOptions: { |
| 32 | + reporterEnabled: 'mocha-junit-reporter, mochawesome', |
| 33 | + mochaJunitReporterReporterOptions: { |
| 34 | + mochaFile: path.join(reportDir, 'junit_cypress-[hash].xml'), |
| 35 | + toConsole: false, |
| 36 | + }, |
| 37 | + mochawesomeReporterOptions: { |
| 38 | + reportDir: reportDir, |
| 39 | + reportFilename: 'cypress_report', |
| 40 | + overwrite: false, |
| 41 | + html: false, |
| 42 | + json: true, |
| 43 | + }, |
| 44 | + }, |
| 45 | + |
| 46 | + // --- Environment Variables --- |
| 47 | + env: { |
| 48 | + grepFilterSpecs: false, |
| 49 | + KUBECONFIG_PATH: process.env.KUBECONFIG, |
| 50 | + OPENSHIFT_VERSION: process.env.CYPRESS_OPENSHIFT_VERSION, |
| 51 | + OPENSHIFT_LOGGING_ENABLED: process.env.CYPRESS_OPENSHIFT_LOGGING_ENABLED === 'true', |
| 52 | + OPENSHIFT_TRACING_ENABLED: process.env.CYPRESS_OPENSHIFT_TRACING_ENABLED === 'false', |
| 53 | + OPENSHIFT_NETOBS_ENABLED: process.env.CYPRESS_OPENSHIFT_NETOBS_ENABLED === 'false', |
| 54 | + }, |
| 55 | + |
| 56 | + // --- E2E Specific Configuration --- |
| 57 | + e2e: { |
| 58 | + baseUrl: process.env.CYPRESS_BASE_URL || process.env.BASE_URL || 'http://localhost:9003', |
| 59 | + pageLoadTimeout: 300000, // 5 minutes |
| 60 | + supportFile: './cypress/support/e2e.ts', |
| 61 | + specPattern: './cypress/e2e/*.cy.{js,jsx,ts,tsx}', |
| 62 | + testIsolation: false, |
| 63 | + numTestsKeptInMemory: 1, |
| 64 | + |
| 65 | + // Experimental Features |
| 66 | + experimentalModifyObstructiveThirdPartyCode: true, |
| 67 | + experimentalOriginDependencies: true, |
| 68 | + experimentalMemoryManagement: true, |
| 69 | + experimentalCspAllowList: ['default-src', 'script-src'], |
| 70 | + |
| 71 | + setupNodeEvents(on, config) { |
| 72 | + // --- Register Plugins --- |
| 73 | + registerCodeCoverage(on, config); |
| 74 | + cypressGrepPlugin(config); |
| 75 | + |
| 76 | + // --- Browser Launch --- |
| 77 | + on('before:browser:launch', (browser, launchOptions) => { |
| 78 | + if (browser.family === 'chromium' && browser.name !== 'electron') { |
| 79 | + launchOptions.args.push('--enable-precise-memory-info'); |
| 80 | + } |
| 81 | + return launchOptions; |
| 82 | + }); |
| 83 | + |
| 84 | + // --- Custom Tasks --- |
| 85 | + on('task', { |
| 86 | + log: (msg) => { console.log(msg); return null; }, |
| 87 | + logError: (msg) => { console.error(msg); return null; }, |
| 88 | + logTable: (data) => { console.table(data); return null; }, |
| 89 | + readFileIfExists: (filename) => fs.existsSync(filename) ? fs.readFileSync(filename, 'utf8') : null, |
| 90 | + }); |
| 91 | + |
| 92 | + // --- Screenshot Rename Logic --- |
| 93 | + on('after:screenshot', async (details) => { |
| 94 | + const pathObj = path.parse(details.path); |
| 95 | + const timestamp = Date.now(); |
| 96 | + const newPath = path.join(pathObj.dir, `${timestamp}_${pathObj.base}`); |
| 97 | + await fs.promises.rename(details.path, newPath); |
| 98 | + return { path: newPath }; |
| 99 | + }); |
| 100 | + |
| 101 | + // --- Video Cleanup --- |
| 102 | + on('after:spec', (spec, results) => { |
| 103 | + if (results?.video) { |
| 104 | + const hasFailures = results.tests?.some((test) => |
| 105 | + test.attempts.some((attempt) => attempt.state === 'failed') |
| 106 | + ); |
| 107 | + if (!hasFailures && fs.existsSync(results.video)) { |
| 108 | + fs.unlinkSync(results.video); |
| 109 | + } |
| 110 | + } |
| 111 | + }); |
| 112 | + |
| 113 | + return config; |
| 114 | + }, |
| 115 | + }, |
| 116 | +}); |
0 commit comments