import * as fs from 'node:fs'; import * as path from 'node:path'; import { defineConfig } from "cypress"; import * as wpj from './cypress/support/wpj'; import { addMatchImageSnapshotPlugin } from '@simonsmith/cypress-image-snapshot/plugin' import registerFailFastPlugin from 'cypress-fail-fast/plugin'; import installLogsPrinter from "cypress-terminal-report/src/installLogsPrinter"; function hasFailure(result: CypressCommandLine.TestResult) { return result.attempts.some(a => a.state === 'failed'); } export default defineConfig({ e2e: { setupNodeEvents(on, config) { on('before:run', () => { // reimport database before each spec run const response = wpj.resetHard(config); console.log(`${response.url} :: ${response.status} ${response.statusText}`); }); on('after:spec', (spec, results) => { // delete video if test did not fail if (fs.existsSync(results?.video) && !results.tests.some(hasFailure)) { fs.unlinkSync(results.video); } }); // PLUGINS addMatchImageSnapshotPlugin(on); registerFailFastPlugin(on, config); config.env.useDetailedLogging && installLogsPrinter(on); }, experimentalStudio: true, specPattern: path.join(__dirname, 'cypress/e2e/**/*.cy.{ts,tsx}'), baseUrl: 'https://localhost:8123/', video: true, videoCompression: true, screenshotOnRunFailure: true, chromeWebSecurity: false, testIsolation: false, experimentalInteractiveRunEvents: true, env: { // https://www.npmjs.com/package/cypress-fail-fast#Configuration FAIL_FAST_STRATEGY: 'spec', FAIL_FAST_ENABLED: true, FAIL_FAST_PLUGIN: true, FAIL_FAST_BAIL: 1, requireSnapshots: false, useDetailedLogging: false, }, viewportHeight: 1000, viewportWidth: 1280, pageLoadTimeout: 360000, }, });