You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.4 KiB

  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 { defineConfig } from 'cypress'
  7. import { join } from 'path'
  8. import { removeDirectory } from 'cypress-delete-downloads-folder'
  9. import cypressSplit from 'cypress-split'
  10. import webpackPreprocessor from '@cypress/webpack-preprocessor'
  11. import {
  12. applyChangesToNextcloud,
  13. configureNextcloud,
  14. startNextcloud,
  15. stopNextcloud,
  16. waitOnNextcloud,
  17. } from './cypress/dockerNode'
  18. import webpackConfig from './webpack.config.js'
  19. export default defineConfig({
  20. projectId: '37xpdh',
  21. // 16/9 screen ratio
  22. viewportWidth: 1280,
  23. viewportHeight: 720,
  24. // Tries again 2 more times on failure
  25. retries: {
  26. runMode: 2,
  27. // do not retry in `cypress open`
  28. openMode: 0,
  29. },
  30. // Needed to trigger `after:run` events with cypress open
  31. experimentalInteractiveRunEvents: true,
  32. // disabled if running in CI but enabled in debug mode
  33. video: !process.env.CI || !!process.env.RUNNER_DEBUG,
  34. // faster video processing
  35. videoCompression: false,
  36. // Prevent elements to be scrolled under a top bar during actions (click, clear, type, etc). Default is 'top'.
  37. // https://github.com/cypress-io/cypress/issues/871
  38. scrollBehavior: 'center',
  39. // Visual regression testing
  40. env: {
  41. failSilently: false,
  42. type: 'actual',
  43. },
  44. screenshotsFolder: 'cypress/snapshots/actual',
  45. trashAssetsBeforeRuns: true,
  46. e2e: {
  47. // Disable session isolation
  48. testIsolation: false,
  49. requestTimeout: 30000,
  50. // We've imported your old cypress plugins here.
  51. // You may want to clean this up later by importing these.
  52. async setupNodeEvents(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. // Check if we are running the setup checks
  89. if (process.env.SETUP_TESTING === 'true') {
  90. console.log('Adding setup tests to specPattern 🧮')
  91. config.specPattern = [join(__dirname, 'cypress/e2e/core/setup.ts')]
  92. console.log('└─ Done')
  93. } else {
  94. // If we are not running the setup tests, we need to remove the setup tests from the specPattern
  95. cypressSplit(on, config)
  96. }
  97. // Before the browser launches
  98. // starting Nextcloud testing container
  99. const ip = await startNextcloud(process.env.BRANCH)
  100. // Setting container's IP as base Url
  101. config.baseUrl = `http://${ip}/index.php`
  102. await waitOnNextcloud(ip)
  103. await configureNextcloud()
  104. if (!process.env.CI) {
  105. await applyChangesToNextcloud()
  106. }
  107. // IMPORTANT: return the config otherwise cypress-split will not work
  108. return config
  109. },
  110. },
  111. component: {
  112. specPattern: ['core/**/*.cy.ts', 'apps/**/*.cy.ts'],
  113. devServer: {
  114. framework: 'vue',
  115. bundler: 'webpack',
  116. webpackConfig: async () => {
  117. process.env.npm_package_name = 'NcCypress'
  118. process.env.npm_package_version = '1.0.0'
  119. process.env.NODE_ENV = 'development'
  120. /**
  121. * Needed for cypress stubbing
  122. *
  123. * @see https://github.com/sinonjs/sinon/issues/1121
  124. * @see https://github.com/cypress-io/cypress/issues/18662
  125. */
  126. const babel = require('./babel.config.js')
  127. babel.plugins.push([
  128. '@babel/plugin-transform-modules-commonjs',
  129. {
  130. loose: true,
  131. },
  132. ])
  133. const config = webpackConfig
  134. config.module.rules.push({
  135. test: /\.svg$/,
  136. type: 'asset/source',
  137. })
  138. return config
  139. },
  140. },
  141. },
  142. })