1
0

cypress.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 { removeDirectory } from 'cypress-delete-downloads-folder'
  15. import cypressSplit from 'cypress-split'
  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. // Visual regression testing
  35. env: {
  36. failSilently: false,
  37. type: 'actual',
  38. },
  39. screenshotsFolder: 'cypress/snapshots/actual',
  40. trashAssetsBeforeRuns: true,
  41. e2e: {
  42. // Disable session isolation
  43. testIsolation: false,
  44. requestTimeout: 30000,
  45. // We've imported your old cypress plugins here.
  46. // You may want to clean this up later by importing these.
  47. async setupNodeEvents(on, config) {
  48. cypressSplit(on, config)
  49. on('file:preprocessor', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration }))
  50. on('task', { removeDirectory })
  51. // Disable spell checking to prevent rendering differences
  52. on('before:browser:launch', (browser, launchOptions) => {
  53. if (browser.family === 'chromium' && browser.name !== 'electron') {
  54. launchOptions.preferences.default['browser.enable_spellchecking'] = false
  55. return launchOptions
  56. }
  57. if (browser.family === 'firefox') {
  58. launchOptions.preferences['layout.spellcheckDefault'] = 0
  59. return launchOptions
  60. }
  61. if (browser.name === 'electron') {
  62. launchOptions.preferences.spellcheck = false
  63. return launchOptions
  64. }
  65. })
  66. // Remove container after run
  67. on('after:run', () => {
  68. if (!process.env.CI) {
  69. stopNextcloud()
  70. }
  71. })
  72. // Before the browser launches
  73. // starting Nextcloud testing container
  74. const ip = await startNextcloud(process.env.BRANCH)
  75. // Setting container's IP as base Url
  76. config.baseUrl = `http://${ip}/index.php`
  77. await waitOnNextcloud(ip)
  78. await configureNextcloud()
  79. await applyChangesToNextcloud()
  80. // IMPORTANT: return the config otherwise cypress-split will not work
  81. return config
  82. },
  83. },
  84. component: {
  85. devServer: {
  86. framework: 'vue',
  87. bundler: 'webpack',
  88. webpackConfig: async () => {
  89. process.env.npm_package_name = 'NcCypress'
  90. process.env.npm_package_version = '1.0.0'
  91. process.env.NODE_ENV = 'development'
  92. /**
  93. * Needed for cypress stubbing
  94. *
  95. * @see https://github.com/sinonjs/sinon/issues/1121
  96. * @see https://github.com/cypress-io/cypress/issues/18662
  97. */
  98. const babel = require('./babel.config.js')
  99. babel.plugins.push([
  100. '@babel/plugin-transform-modules-commonjs',
  101. {
  102. loose: true,
  103. },
  104. ])
  105. const config = webpackConfig
  106. config.module.rules.push({
  107. test: /\.svg$/,
  108. type: 'asset/source',
  109. })
  110. return config
  111. },
  112. },
  113. },
  114. })