Skip to content

Commit 1082dee

Browse files
committed
chore: migrate Cypress to @nextcloud/e2e-test-server
- chore: use vite preprocessor for Cypress Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent f050c32 commit 1082dee

File tree

81 files changed

+605
-829
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+605
-829
lines changed

.github/workflows/cypress.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,19 @@ jobs:
205205
cypress/snapshots
206206
cypress/videos
207207
208-
- name: Extract NC logs
208+
- name: Show logs
209209
if: failure() && matrix.containers != 'component'
210-
run: docker logs nextcloud-cypress-tests_${{ env.APP_NAME }} > nextcloud.log
211-
212-
- name: Upload NC logs
213-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
214-
if: failure() && matrix.containers != 'component'
215-
with:
216-
name: nc_logs_${{ matrix.containers }}
217-
path: nextcloud.log
210+
run: |
211+
for id in $(docker ps -aq); do
212+
docker container inspect "$id" --format '=== Logs for container {{.Name}} ==='
213+
docker logs "$id" >> nextcloud.log
214+
done
215+
echo '=== Nextcloud server logs ==='
216+
docker exec nextcloud-e2e-test-server_${{ env.APP_NAME }} cat data/nextcloud.log
218217
219218
- name: Create data dir archive
220219
if: failure() && matrix.containers != 'component'
221-
run: docker exec nextcloud-cypress-tests_${{ env.APP_NAME }} tar -cvjf - data > data.tar
220+
run: docker exec nextcloud-e2e-test-server_${{ env.APP_NAME }} tar -cvjf - data > data.tar
222221

223222
- name: Upload data dir archive
224223
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2

build/files-checker.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
'cron.php',
5858
'custom.d.ts',
5959
'cypress.config.ts',
60-
'cypress.d.ts',
6160
'cypress',
6261
'dist',
6362
'eslint.config.mjs',

cypress.config.ts

Lines changed: 82 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
* SPDX-License-Identifier: AGPL-3.0-or-later
55
*/
66

7-
import type { Configuration } from 'webpack'
8-
9-
import webpackPreprocessor from '@cypress/webpack-preprocessor'
7+
import { configureNextcloud, docker, getContainer, getContainerName, runExec, runOcc, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/e2e-test-server'
108
import { defineConfig } from 'cypress'
119
import { removeDirectory } from 'cypress-delete-downloads-folder'
1210
import cypressSplit from 'cypress-split'
13-
import { join } from 'path'
14-
import {
15-
applyChangesToNextcloud,
16-
configureNextcloud,
17-
startNextcloud,
18-
stopNextcloud,
19-
waitOnNextcloud,
20-
} from './cypress/dockerNode.ts'
21-
import webpackConfig from './webpack.config.js'
11+
import vitePreprocessor from 'cypress-vite'
12+
import { existsSync } from 'node:fs'
13+
import { dirname, join, resolve } from 'node:path'
14+
import { fileURLToPath } from 'node:url'
15+
import { nodePolyfills } from 'vite-plugin-node-polyfills'
16+
17+
if (!globalThis.__dirname) {
18+
// Cypress has their own weird parser
19+
globalThis.__dirname = dirname(fileURLToPath(new URL(import.meta.url)))
20+
}
2221

2322
export default defineConfig({
2423
projectId: '37xpdh',
@@ -65,13 +64,15 @@ export default defineConfig({
6564
// We've imported your old cypress plugins here.
6665
// You may want to clean this up later by importing these.
6766
async setupNodeEvents(on, config) {
68-
on('file:preprocessor', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration }))
67+
on('file:preprocessor', vitePreprocessor({
68+
plugins: [nodePolyfills()],
69+
}))
6970

7071
on('task', { removeDirectory })
7172

7273
// This allows to store global data (e.g. the name of a snapshot)
7374
// because Cypress.env() and other options are local to the current spec file.
74-
const data = {}
75+
const data: Record<string, unknown> = {}
7576
on('task', {
7677
setVariable({ key, value }) {
7778
data[key] = value
@@ -117,21 +118,82 @@ export default defineConfig({
117118
cypressSplit(on, config)
118119
}
119120

121+
const mounts = {
122+
'3rdparty': resolve(__dirname, './3rdparty'),
123+
apps: resolve(__dirname, './apps'),
124+
core: resolve(__dirname, './core'),
125+
cypress: resolve(__dirname, './cypress'),
126+
dist: resolve(__dirname, './dist'),
127+
lib: resolve(__dirname, './lib'),
128+
ocs: resolve(__dirname, './ocs'),
129+
'ocs-provider': resolve(__dirname, './ocs-provider'),
130+
resources: resolve(__dirname, './resources'),
131+
tests: resolve(__dirname, './tests'),
132+
'console.php': resolve(__dirname, './console.php'),
133+
'cron.php': resolve(__dirname, './cron.php'),
134+
'index.php': resolve(__dirname, './index.php'),
135+
occ: resolve(__dirname, './occ'),
136+
'public.php': resolve(__dirname, './public.php'),
137+
'remote.php': resolve(__dirname, './remote.php'),
138+
'status.php': resolve(__dirname, './status.php'),
139+
'version.php': resolve(__dirname, './version.php'),
140+
} as Record<string, string>
141+
142+
for (const [key, path] of Object.entries(mounts)) {
143+
if (!existsSync(path)) {
144+
delete mounts[key]
145+
}
146+
}
147+
120148
// Before the browser launches
121149
// starting Nextcloud testing container
122-
const ip = await startNextcloud(process.env.BRANCH)
123-
150+
const port = 8042
151+
const ip = await startNextcloud(process.env.BRANCH, false, {
152+
mounts,
153+
exposePort: port,
154+
})
124155
// Setting container's IP as base Url
125-
config.baseUrl = `http://${ip}/index.php`
156+
config.baseUrl = `http://localhost:${port}/index.php`
157+
// if needed for the setup tests, connect to the actions network
158+
await connectToActionsNetwork()
159+
// make sure not to write into apps but use a local apps folder
160+
runExec(['mkdir', 'apps-cypress'])
161+
runExec(['cp', 'cypress/fixtures/app.config.php', 'config'])
162+
// now wait until Nextcloud is ready and configure it
126163
await waitOnNextcloud(ip)
127164
await configureNextcloud()
165+
// additionally we do not want to DoS the app store
166+
runOcc(['config:system:set', 'appstoreenabled', '--value', 'false', '--type', 'boolean'])
128167

129-
if (!process.env.CI) {
130-
await applyChangesToNextcloud()
131-
}
168+
// for later use in tests save the container name
169+
// @ts-expect-error we are adding a custom property
170+
config.dockerContainerName = getContainerName()
132171

133172
// IMPORTANT: return the config otherwise cypress-split will not work
134173
return config
135174
},
136175
},
137176
})
177+
178+
/**
179+
* Connect the running test container to the GitHub Actions network
180+
*/
181+
async function connectToActionsNetwork() {
182+
if (process.env.SETUP_TESTING !== 'true') {
183+
console.log('├─ Not running setup tests, skipping actions network connection 🌐')
184+
return
185+
}
186+
187+
console.log('├─ Looking for github actions network... 🔍')
188+
const networks = await docker.listNetworks()
189+
const network = networks.find((network) => network.Name.startsWith('github_network'))
190+
if (!network) {
191+
console.log('│ └─ No actions network found ⚠️')
192+
return
193+
}
194+
195+
console.log('│ |─ Found actions network: ' + network.Name)
196+
await docker.getNetwork(network.Id)
197+
.connect({ Container: getContainer().id })
198+
console.log('│ └─ Connected to actions network 🌐')
199+
}

cypress.d.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)