configure.ts 2.8 KB

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