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.

173 lines
4.5 KiB

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