import { defineConfig } from 'cypress';

let urlHost, reporter, reporterOptions, timeouts;

if (process.env.CI) {
    urlHost = 'front';
    reporter = 'junit';
    reporterOptions = {
        mochaFile: 'junit/e2e-[hash].xml',
    };
    timeouts = {
        defaultCommandTimeout: 30000,
        requestTimeout: 30000,
        responseTimeout: 60000,
        pageLoadTimeout: 60000,
    };
} else {
    urlHost = 'localhost';
    reporter = 'cypress-mochawesome-reporter';
    reporterOptions = {
        charts: true,
        reportPageTitle: 'Cypress Inline Reporter',
        reportFilename: '[status]_[datetime]-report',
        embeddedScreenshots: true,
        reportDir: 'test/cypress/reports',
        inlineAssets: true,
    };
    timeouts = {
        defaultCommandTimeout: 10000,
        requestTimeout: 10000,
        responseTimeout: 30000,
        pageLoadTimeout: 60000,
    };
}

export default defineConfig({
    e2e: {
        baseUrl: `http://${urlHost}:9000`,
        experimentalStudio: false,
        trashAssetsBeforeRuns: false,
        defaultBrowser: 'chromium',
        fixturesFolder: 'test/cypress/fixtures',
        screenshotsFolder: 'test/cypress/screenshots',
        supportFile: 'test/cypress/support/index.js',
        videosFolder: 'test/cypress/videos',
        downloadsFolder: 'test/cypress/downloads',
        video: false,
        specPattern: 'test/cypress/integration/**/*.spec.js',
        experimentalRunAllSpecs: true,
        watchForFileChanges: true,
        reporter,
        reporterOptions,
        component: {
            componentFolder: 'src',
            testFiles: '**/*.spec.js',
            supportFile: 'test/cypress/support/unit.js',
        },
        viewportWidth: 1280,
        viewportHeight: 720,
        ...timeouts,
        includeShadowDom: true,
        waitForAnimations: true,
    },
});