Skip to content

Commit 0dfd577

Browse files
committed
chore(tests): Fix using save/restore state in cypress
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 90ae1ca commit 0dfd577

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

.github/workflows/cypress.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
147147
- name: Extract NC logs
148148
if: failure() && matrix.containers != 'component'
149-
run: docker logs nextcloud-cypress-tests-${{ env.APP_NAME }} > nextcloud.log
149+
run: docker logs nextcloud-cypress-tests_${{ env.APP_NAME }} > nextcloud.log
150150

151151
- name: Upload NC logs
152152
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
@@ -157,7 +157,7 @@ jobs:
157157

158158
- name: Create data dir archive
159159
if: failure() && matrix.containers != 'component'
160-
run: docker exec nextcloud-cypress-tests-server tar -cvjf - data > data.tar
160+
run: docker exec nextcloud-cypress-tests_${{ env.APP_NAME }} tar -cvjf - data > data.tar
161161

162162
- name: Upload data dir archive
163163
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4

cypress/dockerNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import Docker from 'dockerode'
1010
import waitOn from 'wait-on'
1111
import { c as createTar } from 'tar'
12-
import path from 'path'
12+
import path, { basename } from 'path'
1313
import { execSync } from 'child_process'
1414
import { existsSync } from 'fs'
1515

1616
export const docker = new Docker()
1717

18-
const CONTAINER_NAME = 'nextcloud-cypress-tests-server'
18+
const CONTAINER_NAME = `nextcloud-cypress-tests_${basename(process.cwd()).replace(' ', '')}`
1919
const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'
2020

2121
/**

cypress/e2e/files_versions/version_expiration.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Versions expiration', () => {
2121
})
2222

2323
it('Expire all versions', () => {
24-
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
24+
cy.runOccCommand("config:system:set versions_retention_obligation --value '0, 0'")
2525
cy.runOccCommand('versions:expire')
2626
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
2727
cy.visit('/apps/files')
@@ -38,7 +38,7 @@ describe('Versions expiration', () => {
3838
it('Expire versions v2', () => {
3939
nameVersion(2, 'v1')
4040

41-
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
41+
cy.runOccCommand("config:system:set versions_retention_obligation --value '0, 0'")
4242
cy.runOccCommand('versions:expire')
4343
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
4444
cy.visit('/apps/files')

cypress/support/commands.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ declare global {
6060
* **Warning**: Providing a user will reset the previous session.
6161
*/
6262
resetUserTheming(user?: User): Cypress.Chainable<void>,
63-
64-
/**
65-
* Run an occ command in the docker container.
66-
*/
67-
runOccCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>,
6863
}
6964
}
7065
}
@@ -295,8 +290,3 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => {
295290
cy.clearCookies()
296291
}
297292
})
298-
299-
Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypress.ExecOptions>) => {
300-
const env = Object.entries(options?.env ?? {}).map(([name, value]) => `-e '${name}=${value}'`).join(' ')
301-
return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options)
302-
})

cypress/support/commonUtils.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import { basename } from 'path'
7+
68
/**
79
* Get the header navigation bar
810
*/
@@ -49,8 +51,12 @@ export function installTestApp() {
4951
cy.runOccCommand('-V').then((output) => {
5052
const version = output.stdout.match(/(\d\d+)\.\d+\.\d+/)?.[1]
5153
cy.wrap(version).should('not.be.undefined')
52-
cy.exec(`docker cp '${testAppPath}' nextcloud-cypress-tests-server:/var/www/html/apps`, { log: true })
53-
cy.exec(`docker exec nextcloud-cypress-tests-server sed -i -e 's|-version="[0-9]\\+|-version="${version}|g' apps/testapp/appinfo/info.xml`)
54+
getContainerName()
55+
.then(containerName => {
56+
cy.exec(`docker cp '${testAppPath}' ${containerName}:/var/www/html/apps`, { log: true })
57+
cy.exec(`docker exec --workdir /var/www/html ${containerName} chown -R www-data:www-data /var/www/html/apps/testapp`)
58+
})
59+
cy.runCommand(`sed -i -e 's|-version=\\"[0-9]\\+|-version=\\"${version}|g' apps/testapp/appinfo/info.xml`)
5460
cy.runOccCommand('app:enable --force testapp')
5561
})
5662
}
@@ -60,5 +66,15 @@ export function installTestApp() {
6066
*/
6167
export function uninstallTestApp() {
6268
cy.runOccCommand('app:remove testapp', { failOnNonZeroExit: false })
63-
cy.exec('docker exec nextcloud-cypress-tests-server rm -fr apps/testapp/appinfo/info.xml')
69+
cy.runCommand('rm -fr apps/testapp/appinfo/info.xml')
70+
}
71+
72+
/**
73+
*
74+
*/
75+
export function getContainerName(): Cypress.Chainable<string> {
76+
return cy.exec('pwd')
77+
.then(({ stdout }) => {
78+
return cy.wrap(`nextcloud-cypress-tests_${basename(stdout).replace(' ', '')}`)
79+
})
6480
}

0 commit comments

Comments
 (0)