Bin
2025-12-17 05a69820e0c402b0b33c063d3b922f0a0571cbbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { defineConfig } from "cypress";
import path from "path";
import installLogsPrinter from "cypress-terminal-report/src/installLogsPrinter";
import * as tasks from "./tasks";
import { disableChromeGPU } from "./plugins/disable_gpu";
import { coverageParallel } from "./plugins/coverage_parallel.js";
import { addMatchImageSnapshotPlugin } from "cypress-image-snapshot/plugin";
import { nxE2EPreset } from "@nx/cypress/plugins/cypress-preset";
 
const COLLECT_COVERAGE = process.env.COLLECT_COVERAGE === "true" || process.env.COLLECT_COVERAGE === "1";
const localPath = (p: string) => path.resolve(process.cwd(), p);
 
/**
 * Override Cypress settings
 */
export default function (
  configModifier?: (config: Cypress.ConfigOptions) => Cypress.ConfigOptions,
  setupNodeEvents?: Cypress.EndToEndConfigOptions["setupNodeEvents"],
) {
  /** @type {Cypress.ConfigOptions<any>} */
  const defaultConfig: Cypress.ConfigOptions = {
    // Assets configuration
    supportFolder: localPath("./cypress/support/"),
    videosFolder: localPath("./output/video"),
    screenshotsFolder: localPath("./output/screenshots"),
    downloadsFolder: localPath("./output/downloads"),
    fixturesFolder: localPath("./fixtures"),
    trashAssetsBeforeRuns: false, // Kills ability to run in parallel, must be off
    numTestsKeptInMemory: 1,
    env: {
      coverage: COLLECT_COVERAGE,
      DEFAULT_CPU_THROTTLING: process.env.DEFAULT_CPU_THROTTLING ? Number(process.env.DEFAULT_CPU_THROTTLING) : null,
      DEFAULT_NETWORK_THROTTLING: process.env.DEFAULT_NETWORK_THROTTLING || null,
    },
    e2e: {
      ...nxE2EPreset(__filename, { cypressDir: "tests/integration" }),
      baseUrl: "http://localhost:3000",
      injectDocumentDomain: true,
      viewportWidth: 1600,
      viewportHeight: 900,
      // output config
      setupNodeEvents(on, config) {
        on("before:browser:launch", (browser = null, launchOptions) => {
          if (browser.name === "chrome") {
            // Force sRGB color profile to prevent color mismatch in CI vs local runs
            launchOptions.args.push("--force-color-profile=srgb");
            return launchOptions;
          }
        });
 
        addMatchImageSnapshotPlugin(on, config);
 
        // Allows collecting coverage
        coverageParallel(on, config);
        on("task", { ...tasks });
        // Gives a step-by-step output for failed tests in headless mode
        installLogsPrinter(on, {
          outputVerbose: false,
        });
        // Allows compiling TS files from node_modules (this package)
        setupNodeEvents?.(on, config);
        // When running in headless on the CI, there's no GPU acceleration available
        disableChromeGPU(on);
        return config;
      },
    },
  };
 
  const finalConfig = configModifier ? configModifier(defaultConfig) : defaultConfig;
 
  return defineConfig(finalConfig);
}