Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore(tests): Fix using save/restore state in cypress
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Mar 6, 2025
commit 4e65026d2f84f7ae4d0f7a087770da2ad7b0f923
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cypress/dockerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/files_versions/version_expiration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
10 changes: 0 additions & 10 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
}
}
Expand Down Expand Up @@ -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)
})
27 changes: 24 additions & 3 deletions cypress/support/commonUtils.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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')
})
}
Expand All @@ -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(' ', '')}`)
})
}