cypress.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import type { Configuration } from 'webpack'
  2. import {
  3. configureNextcloud,
  4. stopNextcloud,
  5. waitOnNextcloud,
  6. } from '@nextcloud/cypress/docker'
  7. import webpackPreprocessor from '@cypress/webpack-preprocessor'
  8. import { defineConfig } from 'cypress'
  9. import { applyChangesToNextcloud, startDockerServer } from './cypress/dockerNode'
  10. import cypressSplit from 'cypress-split'
  11. import webpackConfig from './webpack.config.js'
  12. export default defineConfig({
  13. projectId: '37xpdh',
  14. // 16/9 screen ratio
  15. viewportWidth: 1280,
  16. viewportHeight: 720,
  17. // Tries again 2 more times on failure
  18. retries: {
  19. runMode: 2,
  20. // do not retry in `cypress open`
  21. openMode: 0,
  22. },
  23. // Needed to trigger `after:run` events with cypress open
  24. experimentalInteractiveRunEvents: true,
  25. // faster video processing
  26. videoCompression: false,
  27. // Prevent elements to be scrolled under a top bar during actions (click, clear, type, etc). Default is 'top'.
  28. // https://github.com/cypress-io/cypress/issues/871
  29. scrollBehavior: 'center',
  30. // Visual regression testing
  31. env: {
  32. failSilently: false,
  33. type: 'actual',
  34. },
  35. screenshotsFolder: 'cypress/snapshots/actual',
  36. trashAssetsBeforeRuns: true,
  37. e2e: {
  38. // Disable session isolation
  39. testIsolation: false,
  40. // We've imported your old cypress plugins here.
  41. // You may want to clean this up later by importing these.
  42. async setupNodeEvents(on, config) {
  43. cypressSplit(on, config)
  44. on('file:preprocessor', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration }))
  45. // Disable spell checking to prevent rendering differences
  46. on('before:browser:launch', (browser, launchOptions) => {
  47. if (browser.family === 'chromium' && browser.name !== 'electron') {
  48. launchOptions.preferences.default['browser.enable_spellchecking'] = false
  49. return launchOptions
  50. }
  51. if (browser.family === 'firefox') {
  52. launchOptions.preferences['layout.spellcheckDefault'] = 0
  53. return launchOptions
  54. }
  55. if (browser.name === 'electron') {
  56. launchOptions.preferences.spellcheck = false
  57. return launchOptions
  58. }
  59. })
  60. // Remove container after run
  61. on('after:run', () => {
  62. if (!process.env.CI) {
  63. stopNextcloud()
  64. }
  65. })
  66. // Before the browser launches
  67. // starting Nextcloud testing container
  68. const ip = await startDockerServer(process.env.BRANCH)
  69. // Setting container's IP as base Url
  70. config.baseUrl = `http://${ip}/index.php`
  71. await waitOnNextcloud(ip)
  72. await applyChangesToNextcloud()
  73. await configureNextcloud()
  74. // IMPORTANT: return the config otherwise cypress-split will not work
  75. return config
  76. },
  77. },
  78. component: {
  79. devServer: {
  80. framework: 'vue',
  81. bundler: 'webpack',
  82. webpackConfig: async () => {
  83. process.env.npm_package_name = 'NcCypress'
  84. process.env.npm_package_version = '1.0.0'
  85. process.env.NODE_ENV = 'development'
  86. /**
  87. * Needed for cypress stubbing
  88. *
  89. * @see https://github.com/sinonjs/sinon/issues/1121
  90. * @see https://github.com/cypress-io/cypress/issues/18662
  91. */
  92. const babel = require('./babel.config.js')
  93. babel.plugins.push([
  94. '@babel/plugin-transform-modules-commonjs',
  95. {
  96. loose: true,
  97. },
  98. ])
  99. const config = webpackConfig
  100. config.module.rules.push({
  101. test: /\.svg$/,
  102. type: 'asset/source',
  103. })
  104. return config
  105. },
  106. },
  107. },
  108. })