cypress.config.ts 3.4 KB

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