chore(tests): Fix using save/restore state in cypress

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/51284/head
Louis Chemineau 2025-02-27 17:45:25 +07:00
parent e9cfb87c98
commit 4e65026d2f
No known key found for this signature in database
5 changed files with 30 additions and 18 deletions

@ -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

@ -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'
/**

@ -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')

@ -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)
})

@ -1,3 +1,10 @@
/**
* 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
*/
@ -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(' ', '')}`)
})
}