Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,19 @@ jobs:
cypress/snapshots
cypress/videos

- name: Extract NC logs
- name: Show logs
if: failure() && matrix.containers != 'component'
run: docker logs nextcloud-cypress-tests_${{ env.APP_NAME }} > nextcloud.log

- name: Upload NC logs
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: failure() && matrix.containers != 'component'
with:
name: nc_logs_${{ matrix.containers }}
path: nextcloud.log
run: |
for id in $(docker ps -aq); do
docker container inspect "$id" --format '=== Logs for container {{.Name}} ==='
docker logs "$id" >> nextcloud.log
done
echo '=== Nextcloud server logs ==='
docker exec nextcloud-e2e-test-server_${{ env.APP_NAME }} cat data/nextcloud.log

- name: Create data dir archive
if: failure() && matrix.containers != 'component'
run: docker exec nextcloud-cypress-tests_${{ env.APP_NAME }} tar -cvjf - data > data.tar
run: docker exec nextcloud-e2e-test-server_${{ env.APP_NAME }} tar -cvjf - data > data.tar

- name: Upload data dir archive
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
Expand Down
1 change: 0 additions & 1 deletion build/files-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
'cron.php',
'custom.d.ts',
'cypress.config.ts',
'cypress.d.ts',
'cypress',
'dist',
'eslint.config.mjs',
Expand Down
116 changes: 93 additions & 23 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Configuration } from 'webpack'

import webpackPreprocessor from '@cypress/webpack-preprocessor'
import { configureNextcloud, docker, getContainer, getContainerName, runExec, runOcc, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/e2e-test-server'
import { defineConfig } from 'cypress'
import { removeDirectory } from 'cypress-delete-downloads-folder'
import cypressSplit from 'cypress-split'
import { join } from 'path'
import {
applyChangesToNextcloud,
configureNextcloud,
startNextcloud,
stopNextcloud,
waitOnNextcloud,
} from './cypress/dockerNode.ts'
import webpackConfig from './webpack.config.js'
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',
Expand Down Expand Up @@ -65,13 +63,13 @@ export default defineConfig({
// 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', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration }))

on('task', { removeDirectory })
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 = {}
const data: Record<string, unknown> = {}
on('task', {
setVariable({ key, value }) {
data[key] = value
Expand All @@ -80,6 +78,17 @@ export default defineConfig({
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
Expand Down Expand Up @@ -117,21 +126,82 @@ export default defineConfig({
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 ip = await startNextcloud(process.env.BRANCH)

const port = 8042
const ip = await startNextcloud(process.env.BRANCH, false, {
mounts,
exposePort: port,
})
// Setting container's IP as base Url
config.baseUrl = `http://${ip}/index.php`
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'])

if (!process.env.CI) {
await applyChangesToNextcloud()
}
// 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 🌐')
}
32 changes: 0 additions & 32 deletions cypress.d.ts

This file was deleted.

Loading
Loading