1
0

cypress.config.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. // disabled if running in CI but enabled in debug mode
  32. video: !process.env.CI || !!process.env.RUNNER_DEBUG,
  33. // faster video processing
  34. videoCompression: false,
  35. // Prevent elements to be scrolled under a top bar during actions (click, clear, type, etc). Default is 'top'.
  36. // https://github.com/cypress-io/cypress/issues/871
  37. scrollBehavior: 'center',
  38. // Visual regression testing
  39. env: {
  40. failSilently: false,
  41. type: 'actual',
  42. },
  43. screenshotsFolder: 'cypress/snapshots/actual',
  44. trashAssetsBeforeRuns: true,
  45. e2e: {
  46. // Disable session isolation
  47. testIsolation: false,
  48. requestTimeout: 30000,
  49. // We've imported your old cypress plugins here.
  50. // You may want to clean this up later by importing these.
  51. async setupNodeEvents(on, config) {
  52. cypressSplit(on, config)
  53. on('file:preprocessor', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration }))
  54. on('task', { removeDirectory })
  55. // This allows to store global data (e.g. the name of a snapshot)
  56. // because Cypress.env() and other options are local to the current spec file.
  57. const data = {}
  58. on('task', {
  59. setVariable({ key, value }) {
  60. data[key] = value
  61. return null
  62. },
  63. getVariable({ key }) {
  64. return data[key] ?? null
  65. },
  66. })
  67. // Disable spell checking to prevent rendering differences
  68. on('before:browser:launch', (browser, launchOptions) => {
  69. if (browser.family === 'chromium' && browser.name !== 'electron') {
  70. launchOptions.preferences.default['browser.enable_spellchecking'] = false
  71. return launchOptions
  72. }
  73. if (browser.family === 'firefox') {
  74. launchOptions.preferences['layout.spellcheckDefault'] = 0
  75. return launchOptions
  76. }
  77. if (browser.name === 'electron') {
  78. launchOptions.preferences.spellcheck = false
  79. return launchOptions
  80. }
  81. })
  82. // Remove container after run
  83. on('after:run', () => {
  84. if (!process.env.CI) {
  85. stopNextcloud()
  86. }
  87. })
  88. // Before the browser launches
  89. // starting Nextcloud testing container
  90. const ip = await startNextcloud(process.env.BRANCH)
  91. // Setting container's IP as base Url
  92. config.baseUrl = `http://${ip}/index.php`
  93. await waitOnNextcloud(ip)
  94. await configureNextcloud()
  95. if (!process.env.CI) {
  96. await applyChangesToNextcloud()
  97. }
  98. // IMPORTANT: return the config otherwise cypress-split will not work
  99. return config
  100. },
  101. },
  102. component: {
  103. specPattern: ['core/**/*.cy.ts', 'apps/**/*.cy.ts'],
  104. devServer: {
  105. framework: 'vue',
  106. bundler: 'webpack',
  107. webpackConfig: async () => {
  108. process.env.npm_package_name = 'NcCypress'
  109. process.env.npm_package_version = '1.0.0'
  110. process.env.NODE_ENV = 'development'
  111. /**
  112. * Needed for cypress stubbing
  113. *
  114. * @see https://github.com/sinonjs/sinon/issues/1121
  115. * @see https://github.com/cypress-io/cypress/issues/18662
  116. */
  117. const babel = require('./babel.config.js')
  118. babel.plugins.push([
  119. '@babel/plugin-transform-modules-commonjs',
  120. {
  121. loose: true,
  122. },
  123. ])
  124. const config = webpackConfig
  125. config.module.rules.push({
  126. test: /\.svg$/,
  127. type: 'asset/source',
  128. })
  129. return config
  130. },
  131. },
  132. },
  133. })