diff options
author | Louis Chemineau <louis@chmn.me> | 2025-02-27 17:45:25 +0100 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2025-03-06 10:26:40 +0100 |
commit | 4e65026d2f84f7ae4d0f7a087770da2ad7b0f923 (patch) | |
tree | 7d037d2fc565707be859d403f60a409c4bf0ba4b | |
parent | e9cfb87c9839558386e2d3f3b72cc2377f09a2f0 (diff) | |
download | nextcloud-server-4e65026d2f84f7ae4d0f7a087770da2ad7b0f923.tar.gz nextcloud-server-4e65026d2f84f7ae4d0f7a087770da2ad7b0f923.zip |
chore(tests): Fix using save/restore state in cypress
Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r-- | .github/workflows/cypress.yml | 4 | ||||
-rw-r--r-- | cypress/dockerNode.ts | 3 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_expiration.cy.ts | 4 | ||||
-rw-r--r-- | cypress/support/commands.ts | 10 | ||||
-rw-r--r-- | cypress/support/commonUtils.ts | 27 |
5 files changed, 30 insertions, 18 deletions
diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index dfe124f29a9..fe5aaba375e 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -131,7 +131,7 @@ jobs: - name: Extract NC logs if: failure() && matrix.containers != 'component' - run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log + run: docker logs nextcloud-cypress-tests_${{ env.APP_NAME }} > nextcloud.log - name: Upload NC logs uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 @@ -142,7 +142,7 @@ jobs: - name: Create data dir archive if: failure() && matrix.containers != 'component' - run: docker exec nextcloud-cypress-tests-server tar -cvjf - data > data.tar + run: docker exec nextcloud-cypress-tests_${{ env.APP_NAME }} tar -cvjf - data > data.tar - name: Upload data dir archive uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 57872d1f492..03c53c00c12 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -26,11 +26,12 @@ import Docker from 'dockerode' import waitOn from 'wait-on' import tar from 'tar' +import { basename } from 'path' import { execSync } from 'child_process' export const docker = new Docker() -const CONTAINER_NAME = 'nextcloud-cypress-tests-server' +const CONTAINER_NAME = `nextcloud-cypress-tests_${basename(process.cwd()).replace(' ', '')}` const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server' /** diff --git a/cypress/e2e/files_versions/version_expiration.cy.ts b/cypress/e2e/files_versions/version_expiration.cy.ts index 1c1c6fc70ae..1e7f732777b 100644 --- a/cypress/e2e/files_versions/version_expiration.cy.ts +++ b/cypress/e2e/files_versions/version_expiration.cy.ts @@ -38,7 +38,7 @@ describe('Versions expiration', () => { }) it('Expire all versions', () => { - cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"') + cy.runOccCommand("config:system:set versions_retention_obligation --value '0, 0'") cy.runOccCommand('versions:expire') cy.runOccCommand('config:system:set versions_retention_obligation --value auto') cy.visit('/apps/files') @@ -55,7 +55,7 @@ describe('Versions expiration', () => { it('Expire versions v2', () => { nameVersion(2, 'v1') - cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"') + cy.runOccCommand("config:system:set versions_retention_obligation --value '0, 0'") cy.runOccCommand('versions:expire') cy.runOccCommand('config:system:set versions_retention_obligation --value auto') cy.visit('/apps/files') diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index c95270bab44..a676acfd1d8 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -80,11 +80,6 @@ declare global { * **Warning**: Providing a user will reset the previous session. */ resetUserTheming(user?: User): Cypress.Chainable<void>, - - /** - * Run an occ command in the docker container. - */ - runOccCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>, } } } @@ -292,8 +287,3 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => { cy.clearCookies() } }) - -Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypress.ExecOptions>) => { - const env = Object.entries(options?.env ?? {}).map(([name, value]) => `-e '${name}=${value}'`).join(' ') - return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options) -}) diff --git a/cypress/support/commonUtils.ts b/cypress/support/commonUtils.ts index ce4556a9349..8d02ace151b 100644 --- a/cypress/support/commonUtils.ts +++ b/cypress/support/commonUtils.ts @@ -1,4 +1,11 @@ /** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { basename } from 'path' + +/** * Get the header navigation bar */ export function getNextcloudHeader() { @@ -44,8 +51,12 @@ export function installTestApp() { cy.runOccCommand('-V').then((output) => { const version = output.stdout.match(/(\d\d+)\.\d+\.\d+/)?.[1] cy.wrap(version).should('not.be.undefined') - cy.exec(`docker cp '${testAppPath}' nextcloud-cypress-tests-server:/var/www/html/apps`, { log: true }) - cy.exec(`docker exec nextcloud-cypress-tests-server sed -i -e 's|-version="[0-9]\\+|-version="${version}|g' apps/testapp/appinfo/info.xml`) + getContainerName() + .then(containerName => { + cy.exec(`docker cp '${testAppPath}' ${containerName}:/var/www/html/apps`, { log: true }) + cy.exec(`docker exec --workdir /var/www/html ${containerName} chown -R www-data:www-data /var/www/html/apps/testapp`) + }) + cy.runCommand(`sed -i -e 's|-version=\\"[0-9]\\+|-version=\\"${version}|g' apps/testapp/appinfo/info.xml`) cy.runOccCommand('app:enable --force testapp') }) } @@ -55,5 +66,15 @@ export function installTestApp() { */ export function uninstallTestApp() { cy.runOccCommand('app:remove testapp', { failOnNonZeroExit: false }) - cy.exec('docker exec nextcloud-cypress-tests-server rm -fr apps/testapp/appinfo/info.xml') + cy.runCommand('rm -fr apps/testapp/appinfo/info.xml') +} + +/** + * + */ +export function getContainerName(): Cypress.Chainable<string> { + return cy.exec('pwd') + .then(({ stdout }) => { + return cy.wrap(`nextcloud-cypress-tests_${basename(stdout).replace(' ', '')}`) + }) } |