cypress.config.mjs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { defineConfig } from 'cypress'
  2. import { rm } from 'node:fs/promises'
  3. import { resolve, dirname } from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. import { initPlugin as initVisualRegressionPlugin } from '@frsource/cypress-plugin-visual-regression-diff/plugins'
  6. import pkg from '../package.json' assert { type: 'json' }
  7. const dir = dirname(fileURLToPath(import.meta.url))
  8. const isCYCI = !process.env.CY_OPEN
  9. const root = resolve(dir, '..')
  10. // we don't need to optimize graphql and apollo
  11. const skipDeps = ['graphql', 'apollo', '@tiptap/pm']
  12. export default defineConfig({
  13. videosFolder: '.cypress/videos',
  14. supportFolder: '.cypress/support/index.js',
  15. fixturesFolder: '.cypress/fixtures',
  16. downloadsFolder: '.cypress/downloads',
  17. screenshotsFolder: '.cypress/screenshots',
  18. videoCompression: false,
  19. env: {
  20. CY_CI: isCYCI,
  21. pluginVisualRegressionDiffConfig: {
  22. threshold: 0.02,
  23. },
  24. pluginVisualRegressionMaxDiffThreshold: 0.02,
  25. },
  26. component: {
  27. supportFile: '.cypress/support/index.js',
  28. setupNodeEvents(on, config) {
  29. on('after:spec', (spec, results) => {
  30. if (results && results.stats.failures === 0 && results.video) {
  31. return rm(results.video)
  32. }
  33. })
  34. initVisualRegressionPlugin(on, config)
  35. on('before:browser:launch', (browser, launchOptions) => {
  36. if (browser?.family === 'chromium' && browser?.name !== 'electron') {
  37. launchOptions.args.push('--force-device-scale-factor=2')
  38. }
  39. return launchOptions
  40. })
  41. },
  42. devServer: {
  43. framework: 'vue',
  44. bundler: 'vite',
  45. viteConfig: {
  46. mode: 'cypress',
  47. root,
  48. configFile: resolve(dir, '..', 'vite.config.mjs'),
  49. cacheDir: resolve(dir, 'node_modules', '.vite'),
  50. server: {
  51. fs: {
  52. strict: false,
  53. },
  54. hmr: true,
  55. ...(isCYCI && { watch: { ignored: ['**/*'] } }),
  56. },
  57. optimizeDeps: {
  58. entries: [
  59. '**/cypress/**/*.cy.ts',
  60. '!**/node_modules/**',
  61. '!**/*.d.ts',
  62. ],
  63. include: [
  64. // if you see cypress failing on some dependency, add it to skipDeps
  65. ...Object.keys(pkg.dependencies).filter(
  66. (name) => !skipDeps.some((dep) => name.includes(dep)),
  67. ),
  68. ],
  69. },
  70. },
  71. },
  72. // iPhone 12 viewport
  73. viewportWidth: 390,
  74. viewportHeight: 844,
  75. fileServerFolder: '..',
  76. indexHtmlFile: '.cypress/support/component-index.html',
  77. specPattern: ['app/frontend/cypress/**/*.cy.{js,jsx,ts,tsx}'],
  78. },
  79. retries: 0,
  80. })