From 12c84d74b369a729b8ec22dea2dd803ba8880bff Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 25 Nov 2024 12:42:51 +0100 Subject: [PATCH] chore: Update @nextcloud/cypress to v1.0.0-beta.11 Signed-off-by: Louis Chemineau --- .github/workflows/cypress.yml | 2 +- cypress/dockerNode.ts | 4 +-- .../public-share/setup-public-share.ts | 13 +++---- cypress/e2e/settings/personal-info.cy.ts | 4 +-- cypress/support/commands.ts | 34 +------------------ cypress/support/commonUtils.ts | 19 +++++++++-- cypress/support/cypress-e2e.d.ts | 20 ----------- package-lock.json | 8 ++--- package.json | 4 +-- 9 files changed, 33 insertions(+), 75 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 9d0b48ebb1930..4b1705d940a39 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -162,7 +162,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_server tar -cvjf - data > data.tar - name: Upload data dir archive uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 71644ae73994e..bc58e7079397a 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -9,13 +9,13 @@ import Docker from 'dockerode' import waitOn from 'wait-on' import { c as createTar } from 'tar' -import path from 'path' +import path, { basename } from 'path' import { execSync } from 'child_process' import { existsSync } from 'fs' 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_sharing/public-share/setup-public-share.ts b/cypress/e2e/files_sharing/public-share/setup-public-share.ts index 9549552c2002a..d809e1280c637 100644 --- a/cypress/e2e/files_sharing/public-share/setup-public-share.ts +++ b/cypress/e2e/files_sharing/public-share/setup-public-share.ts @@ -92,15 +92,13 @@ export function setupPublicShare(): Cypress.Chainable { return cy.task('getVariable', { key: 'public-share-data' }) .then((data) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { dataSnapshot, dbSnapshot, shareUrl } = data as any || {} - if (dataSnapshot && dbSnapshot) { - cy.restoreDB(dbSnapshot) - cy.restoreData(dataSnapshot) + const { dataSnapshot, shareUrl } = data as any || {} + if (dataSnapshot) { + cy.restoreState(dataSnapshot) url = shareUrl return cy.wrap(shareUrl as string) } else { - cy.restoreData() - cy.restoreDB() + cy.restoreState() const shareData: Record = {} return cy.createRandomUser() @@ -109,8 +107,7 @@ export function setupPublicShare(): Cypress.Chainable { .then(() => createShare(shareName)) .then((value) => { shareData.shareUrl = value }) .then(() => adjustSharePermission()) - .then(() => cy.backupDB().then((value) => { shareData.dbSnapshot = value })) - .then(() => cy.backupData([user.userId]).then((value) => { shareData.dataSnapshot = value })) + .then(() => cy.saveState().then((value) => { shareData.dataSnapshot = value })) .then(() => cy.task('setVariable', { key: 'public-share-data', value: shareData })) .then(() => cy.log(`Public share setup, URL: ${shareData.shareUrl}`)) .then(() => cy.wrap(url)) diff --git a/cypress/e2e/settings/personal-info.cy.ts b/cypress/e2e/settings/personal-info.cy.ts index 30c0bce94216b..940e3cd644998 100644 --- a/cypress/e2e/settings/personal-info.cy.ts +++ b/cypress/e2e/settings/personal-info.cy.ts @@ -118,7 +118,7 @@ describe('Settings: Change personal information', { testIsolation: true }, () => cy.login(user) cy.visit('/settings/user') - cy.backupDB().then(($snapshot) => { + cy.saveState().then(($snapshot) => { snapshot = $snapshot }) }) @@ -136,7 +136,7 @@ describe('Settings: Change personal information', { testIsolation: true }, () => }) afterEach(() => { - cy.restoreDB(snapshot) + cy.restoreState(snapshot) }) it('Can dis- and enable the profile', () => { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 28bd335eecfb0..410a970f77bd0 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -216,41 +216,9 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => { } }) -Cypress.Commands.add('runOccCommand', (command: string, options?: Partial) => { - 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) -}) - Cypress.Commands.add('userFileExists', (user: string, path: string) => { user.replaceAll('"', '\\"') path.replaceAll('"', '\\"').replaceAll(/^\/+/gm, '') - return cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server stat --printf="%s" "data/${user}/files/${path}"`, { failOnNonZeroExit: true }) + return cy.runCommand(`stat --printf="%s" "data/${user}/files/${path}"`, { failOnNonZeroExit: true }) .then((exec) => Number.parseInt(exec.stdout || '0')) }) - -Cypress.Commands.add('backupDB', (): Cypress.Chainable => { - const randomString = Math.random().toString(36).substring(7) - cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server cp /var/www/html/data/owncloud.db /var/www/html/data/owncloud.db-${randomString}`) - cy.log(`Created snapshot ${randomString}`) - return cy.wrap(randomString) -}) - -Cypress.Commands.add('restoreDB', (snapshot: string = 'init') => { - cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server cp /var/www/html/data/owncloud.db-${snapshot} /var/www/html/data/owncloud.db`) - cy.log(`Restored snapshot ${snapshot}`) -}) - -Cypress.Commands.add('backupData', (users: string[] = ['admin']) => { - const snapshot = Math.random().toString(36).substring(7) - const toBackup = users.map((user) => `'${user.replaceAll('\\', '').replaceAll('\'', '\\\'')}'`).join(' ') - cy.exec(`docker exec --user www-data rm /var/www/html/data/data-${snapshot}.tar`, { failOnNonZeroExit: false }) - cy.exec(`docker exec --user www-data --workdir /var/www/html/data nextcloud-cypress-tests-server tar cf /var/www/html/data/data-${snapshot}.tar ${toBackup}`) - return cy.wrap(snapshot as string) -}) - -Cypress.Commands.add('restoreData', (snapshot?: string) => { - snapshot = snapshot ?? 'init' - snapshot.replaceAll('\\', '').replaceAll('"', '\\"') - cy.exec(`docker exec --user www-data --workdir /var/www/html/data nextcloud-cypress-tests-server rm -vfr $(tar --exclude='*/*' -tf '/var/www/html/data/data-${snapshot}.tar')`) - cy.exec(`docker exec --user www-data --workdir /var/www/html/data nextcloud-cypress-tests-server tar -xf '/var/www/html/data/data-${snapshot}.tar'`) -}) diff --git a/cypress/support/commonUtils.ts b/cypress/support/commonUtils.ts index a00a6a4c740ce..7023cc8bf64db 100644 --- a/cypress/support/commonUtils.ts +++ b/cypress/support/commonUtils.ts @@ -3,6 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { basename } from 'path' + /** * Get the header navigation bar */ @@ -49,8 +51,9 @@ 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.runCommand(`sed -i -e 's|-version="[0-9]\\+|-version="${version}|g' apps/testapp/appinfo/info.xml`) cy.runOccCommand('app:enable --force testapp') }) } @@ -60,5 +63,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 { + return cy.exec('pwd') + .then(({ stdout }) => { + return cy.wrap(`nextcloud-cypress-tests_${basename(stdout).replace(' ', '')}`) + }) } diff --git a/cypress/support/cypress-e2e.d.ts b/cypress/support/cypress-e2e.d.ts index 13b181e6db621..afe93077d6a71 100644 --- a/cypress/support/cypress-e2e.d.ts +++ b/cypress/support/cypress-e2e.d.ts @@ -53,27 +53,7 @@ declare global { */ resetUserTheming(user?: User): Cypress.Chainable, - /** - * Run an occ command in the docker container. - */ - runOccCommand(command: string, options?: Partial): Cypress.Chainable, - userFileExists(user: string, path: string): Cypress.Chainable - - /** - * Create a snapshot of the current database - */ - backupDB(): Cypress.Chainable, - - /** - * Restore a snapshot of the database - * Default is the post-setup state - */ - restoreDB(snapshot?: string): Cypress.Chainable - - backupData(users?: string[]): Cypress.Chainable - - restoreData(snapshot?: string): Cypress.Chainable } } } diff --git a/package-lock.json b/package-lock.json index 8c6ba8a7bf8cf..976cce99f18cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -94,7 +94,7 @@ "@cypress/vue2": "^2.1.1", "@cypress/webpack-preprocessor": "^6.0.2", "@nextcloud/babel-config": "^1.2.0", - "@nextcloud/cypress": "^1.0.0-beta.9", + "@nextcloud/cypress": "^1.0.0-beta.11", "@nextcloud/eslint-config": "^8.4.1", "@nextcloud/stylelint-config": "^3.0.1", "@nextcloud/typings": "^1.9.1", @@ -3686,9 +3686,9 @@ } }, "node_modules/@nextcloud/cypress": { - "version": "1.0.0-beta.9", - "resolved": "https://registry.npmjs.org/@nextcloud/cypress/-/cypress-1.0.0-beta.9.tgz", - "integrity": "sha512-i43skZoCkrr5H1L1PsYddzz/SjDlSNcTCrEcMJFRwoHiJo5giUNCz0b2lKEQBMtudP8J+BGfG+AIFA0LJ/oD2A==", + "version": "1.0.0-beta.11", + "resolved": "https://registry.npmjs.org/@nextcloud/cypress/-/cypress-1.0.0-beta.11.tgz", + "integrity": "sha512-8wR0UVfqZXRmQSAeaJg+yw95Smc9zAw35FYckk52PhXhnRugn2J5aqcXMtrQZovdeqak1y5Kjc/t0AJ2QhtnOA==", "dev": true, "dependencies": { "dockerode": "^4.0.2", diff --git a/package.json b/package.json index ea130c06f8dcb..c24290cd33cfc 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "@cypress/vue2": "^2.1.1", "@cypress/webpack-preprocessor": "^6.0.2", "@nextcloud/babel-config": "^1.2.0", - "@nextcloud/cypress": "^1.0.0-beta.9", + "@nextcloud/cypress": "^1.0.0-beta.11", "@nextcloud/eslint-config": "^8.4.1", "@nextcloud/stylelint-config": "^3.0.1", "@nextcloud/typings": "^1.9.1", @@ -204,4 +204,4 @@ "overrides": { "colors": "1.4.0" } -} +} \ No newline at end of file