-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathcypress.config.ts
More file actions
208 lines (180 loc) · 6.55 KB
/
cypress.config.ts
File metadata and controls
208 lines (180 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* eslint-disable no-console */
/*!
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { configureNextcloud, docker, getContainer, getContainerName, runExec, runOcc, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/e2e-test-server'
import { defineConfig } from 'cypress'
import cypressSplit from 'cypress-split'
import vitePreprocessor from 'cypress-vite'
import { existsSync, rmdirSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
if (!globalThis.__dirname) {
// Cypress has their own weird parser
globalThis.__dirname = dirname(fileURLToPath(new URL(import.meta.url)))
}
export default defineConfig({
projectId: '37xpdh',
// 16/9 screen ratio
viewportWidth: 1280,
viewportHeight: 720,
// Tries again when in run mode (cypress run) e.g. on CI
retries: {
runMode: 3,
// do not retry in `cypress open`
openMode: 0,
},
// Needed to trigger `after:run` events with cypress open
experimentalInteractiveRunEvents: true,
// disabled if running in CI but enabled in debug mode
video: !process.env.CI || !!process.env.RUNNER_DEBUG,
// faster video processing
videoCompression: false,
// Prevent elements to be scrolled under a top bar during actions (click, clear, type, etc). Default is 'top'.
// https://github.com/cypress-io/cypress/issues/871
scrollBehavior: 'center',
// Visual regression testing
env: {
failSilently: false,
type: 'actual',
},
screenshotsFolder: 'cypress/snapshots/actual',
trashAssetsBeforeRuns: true,
e2e: {
// Disable session isolation
testIsolation: false,
requestTimeout: 30000,
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
async setupNodeEvents(on, config) {
on('file:preprocessor', vitePreprocessor({
plugins: [nodePolyfills()],
}))
// This allows to store global data (e.g. the name of a snapshot)
// because Cypress.env() and other options are local to the current spec file.
const data: Record<string, unknown> = {}
on('task', {
setVariable({ key, value }) {
data[key] = value
return null
},
getVariable({ key }) {
return data[key] ?? null
},
// allow to clear the downloads folder
deleteFolder(path: string) {
try {
if (existsSync(path)) {
rmdirSync(path, { maxRetries: 10, recursive: true })
}
return null
} catch (error) {
throw Error(`Error while deleting ${path}. Original error: ${error}`)
}
},
})
// Disable spell checking to prevent rendering differences
on('before:browser:launch', (browser, launchOptions) => {
if (browser.family === 'chromium' && browser.name !== 'electron') {
launchOptions.preferences.default['browser.enable_spellchecking'] = false
return launchOptions
}
if (browser.family === 'firefox') {
launchOptions.preferences['layout.spellcheckDefault'] = 0
return launchOptions
}
if (browser.name === 'electron') {
launchOptions.preferences.spellcheck = false
return launchOptions
}
})
// Remove container after run
on('after:run', () => {
if (!process.env.CI) {
stopNextcloud()
}
})
// Check if we are running the setup checks
if (process.env.SETUP_TESTING === 'true') {
console.log('Adding setup tests to specPattern 🧮')
config.specPattern = [join(__dirname, 'cypress/e2e/core/setup.ts')]
console.log('└─ Done')
} else {
// If we are not running the setup tests, we need to remove the setup tests from the specPattern
cypressSplit(on, config)
}
const mounts = {
'3rdparty': resolve(__dirname, './3rdparty'),
apps: resolve(__dirname, './apps'),
core: resolve(__dirname, './core'),
cypress: resolve(__dirname, './cypress'),
dist: resolve(__dirname, './dist'),
lib: resolve(__dirname, './lib'),
ocs: resolve(__dirname, './ocs'),
'ocs-provider': resolve(__dirname, './ocs-provider'),
resources: resolve(__dirname, './resources'),
tests: resolve(__dirname, './tests'),
'console.php': resolve(__dirname, './console.php'),
'cron.php': resolve(__dirname, './cron.php'),
'index.php': resolve(__dirname, './index.php'),
occ: resolve(__dirname, './occ'),
'public.php': resolve(__dirname, './public.php'),
'remote.php': resolve(__dirname, './remote.php'),
'status.php': resolve(__dirname, './status.php'),
'version.php': resolve(__dirname, './version.php'),
} as Record<string, string>
for (const [key, path] of Object.entries(mounts)) {
if (!existsSync(path)) {
delete mounts[key]
}
}
// Before the browser launches
// starting Nextcloud testing container
const port = 8042
const ip = await startNextcloud(process.env.BRANCH, false, {
mounts,
exposePort: port,
forceRecreate: true,
})
// Setting container's IP as base Url
config.baseUrl = `http://localhost:${port}/index.php`
// if needed for the setup tests, connect to the actions network
await connectToActionsNetwork()
// make sure not to write into apps but use a local apps folder
runExec(['mkdir', 'apps-cypress'])
runExec(['cp', 'cypress/fixtures/app.config.php', 'config'])
// now wait until Nextcloud is ready and configure it
await waitOnNextcloud(ip)
await configureNextcloud()
// additionally we do not want to DoS the app store
runOcc(['config:system:set', 'appstoreenabled', '--value', 'false', '--type', 'boolean'])
// for later use in tests save the container name
// @ts-expect-error we are adding a custom property
config.dockerContainerName = getContainerName()
// IMPORTANT: return the config otherwise cypress-split will not work
return config
},
},
})
/**
* Connect the running test container to the GitHub Actions network
*/
async function connectToActionsNetwork() {
if (process.env.SETUP_TESTING !== 'true') {
console.log('├─ Not running setup tests, skipping actions network connection 🌐')
return
}
console.log('├─ Looking for github actions network... 🔍')
const networks = await docker.listNetworks()
const network = networks.find((network) => network.Name.startsWith('github_network'))
if (!network) {
console.log('│ └─ No actions network found ⚠️')
return
}
console.log('│ |─ Found actions network: ' + network.Name)
await docker.getNetwork(network.Id)
.connect({ Container: getContainer().id })
console.log('│ └─ Connected to actions network 🌐')
}