cypress.config.ts 3.9 KB

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