|
4 | 4 | * SPDX-License-Identifier: AGPL-3.0-or-later |
5 | 5 | */ |
6 | 6 |
|
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' |
10 | 8 | import { defineConfig } from 'cypress' |
11 | 9 | import { removeDirectory } from 'cypress-delete-downloads-folder' |
12 | 10 | 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 | +} |
22 | 21 |
|
23 | 22 | export default defineConfig({ |
24 | 23 | projectId: '37xpdh', |
@@ -65,13 +64,15 @@ export default defineConfig({ |
65 | 64 | // We've imported your old cypress plugins here. |
66 | 65 | // You may want to clean this up later by importing these. |
67 | 66 | async setupNodeEvents(on, config) { |
68 | | - on('file:preprocessor', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration })) |
| 67 | + on('file:preprocessor', vitePreprocessor({ |
| 68 | + plugins: [nodePolyfills()], |
| 69 | + })) |
69 | 70 |
|
70 | 71 | on('task', { removeDirectory }) |
71 | 72 |
|
72 | 73 | // This allows to store global data (e.g. the name of a snapshot) |
73 | 74 | // because Cypress.env() and other options are local to the current spec file. |
74 | | - const data = {} |
| 75 | + const data: Record<string, unknown> = {} |
75 | 76 | on('task', { |
76 | 77 | setVariable({ key, value }) { |
77 | 78 | data[key] = value |
@@ -117,21 +118,82 @@ export default defineConfig({ |
117 | 118 | cypressSplit(on, config) |
118 | 119 | } |
119 | 120 |
|
| 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 | + |
120 | 148 | // Before the browser launches |
121 | 149 | // 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 | + }) |
124 | 155 | // 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 |
126 | 163 | await waitOnNextcloud(ip) |
127 | 164 | await configureNextcloud() |
| 165 | + // additionally we do not want to DoS the app store |
| 166 | + runOcc(['config:system:set', 'appstoreenabled', '--value', 'false', '--type', 'boolean']) |
128 | 167 |
|
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() |
132 | 171 |
|
133 | 172 | // IMPORTANT: return the config otherwise cypress-split will not work |
134 | 173 | return config |
135 | 174 | }, |
136 | 175 | }, |
137 | 176 | }) |
| 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 | +} |
0 commit comments