diff options
author | Louis Chemineau <louis@chmn.me> | 2024-11-25 12:42:51 +0100 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2024-11-25 16:22:09 +0100 |
commit | ebda7b45f64bbdb74b8e664f15c0f876d1a45117 (patch) | |
tree | bdc62596da86064767bd6a6c4e4d5468493ae04f /cypress | |
parent | 3822db51742eb12c67b525cab80ec0699e011684 (diff) | |
download | nextcloud-server-ebda7b45f64bbdb74b8e664f15c0f876d1a45117.tar.gz nextcloud-server-ebda7b45f64bbdb74b8e664f15c0f876d1a45117.zip |
chore: Update @nextcloud/cypress to v1.0.0-beta.11artonge/chore/update_nc_cypress_beta.11
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/dockerNode.ts | 4 | ||||
-rw-r--r-- | cypress/e2e/files_sharing/public-share/setup-public-share.ts | 13 | ||||
-rw-r--r-- | cypress/e2e/files_sharing/public-share/view_file-drop.cy.ts | 2 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_expiration.cy.ts | 4 | ||||
-rw-r--r-- | cypress/e2e/settings/personal-info.cy.ts | 4 | ||||
-rw-r--r-- | cypress/e2e/settings/users_groups.cy.ts | 4 | ||||
-rw-r--r-- | cypress/e2e/theming/a11y-color-contrast.cy.ts | 2 | ||||
-rw-r--r-- | cypress/e2e/theming/user-settings_app-order.cy.ts | 2 | ||||
-rw-r--r-- | cypress/support/commands.ts | 34 | ||||
-rw-r--r-- | cypress/support/commonUtils.ts | 22 | ||||
-rw-r--r-- | cypress/support/cypress-e2e.d.ts | 20 |
11 files changed, 35 insertions, 76 deletions
diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 71644ae7399..bc58e707939 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 9549552c200..5e23357a821 100644 --- a/cypress/e2e/files_sharing/public-share/setup-public-share.ts +++ b/cypress/e2e/files_sharing/public-share/setup-public-share.ts @@ -92,16 +92,12 @@ export function setupPublicShare(): Cypress.Chainable<string> { 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() - const shareData: Record<string, unknown> = {} return cy.createRandomUser() .then(($user) => { user = $user }) @@ -109,8 +105,7 @@ export function setupPublicShare(): Cypress.Chainable<string> { .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/files_sharing/public-share/view_file-drop.cy.ts b/cypress/e2e/files_sharing/public-share/view_file-drop.cy.ts index 8bc4b9b8e15..3a38f0c9ec7 100644 --- a/cypress/e2e/files_sharing/public-share/view_file-drop.cy.ts +++ b/cypress/e2e/files_sharing/public-share/view_file-drop.cy.ts @@ -144,7 +144,7 @@ describe('files_sharing: Public share - File drop', { testIsolation: true }, () }) describe('Terms of service', { testIsolation: true }, () => { - before(() => cy.runOccCommand('config:app:set --value "TEST: Some disclaimer text" --type string core shareapi_public_link_disclaimertext')) + before(() => cy.runOccCommand('config:app:set --value \'TEST: Some disclaimer text\' --type string core shareapi_public_link_disclaimertext')) beforeEach(() => cy.visit(shareUrl)) after(() => cy.runOccCommand('config:app:delete core shareapi_public_link_disclaimertext')) diff --git a/cypress/e2e/files_versions/version_expiration.cy.ts b/cypress/e2e/files_versions/version_expiration.cy.ts index 6fa432e0499..118ac01532f 100644 --- a/cypress/e2e/files_versions/version_expiration.cy.ts +++ b/cypress/e2e/files_versions/version_expiration.cy.ts @@ -21,7 +21,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') @@ -38,7 +38,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/e2e/settings/personal-info.cy.ts b/cypress/e2e/settings/personal-info.cy.ts index 30c0bce9421..940e3cd6449 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/e2e/settings/users_groups.cy.ts b/cypress/e2e/settings/users_groups.cy.ts index f7a8d7c6d03..0f5f9c26538 100644 --- a/cypress/e2e/settings/users_groups.cy.ts +++ b/cypress/e2e/settings/users_groups.cy.ts @@ -213,7 +213,7 @@ describe.only('Settings: Sort groups in the UI', () => { cy.runOccCommand('group:list --output json').then((output) => { const groups = Object.keys(JSON.parse(output.stdout)).filter((group) => group !== 'admin') groups.forEach((group) => { - cy.runOccCommand(`group:delete "${group}"`) + cy.runOccCommand(`group:delete '${group}'`) }) }) @@ -221,7 +221,7 @@ describe.only('Settings: Sort groups in the UI', () => { cy.runOccCommand('group:add A') cy.runOccCommand('group:add B') cy.createRandomUser().then((user) => { - cy.runOccCommand(`group:adduser B "${user.userId}"`) + cy.runOccCommand(`group:adduser B '${user.userId}'`) }) // Visit the settings as admin diff --git a/cypress/e2e/theming/a11y-color-contrast.cy.ts b/cypress/e2e/theming/a11y-color-contrast.cy.ts index 9d3ca2657fb..ce75e73d6db 100644 --- a/cypress/e2e/theming/a11y-color-contrast.cy.ts +++ b/cypress/e2e/theming/a11y-color-contrast.cy.ts @@ -110,7 +110,7 @@ describe('Accessibility of Nextcloud theming colors', () => { before(() => { cy.createRandomUser().then(($user) => { // set user theme - cy.runOccCommand(`user:setting -- '${$user.userId}' theming enabled-themes '["${theme}"]'`) + cy.runOccCommand(`user:setting -- '${$user.userId}' theming enabled-themes '[\\"${theme}\\"]'`) cy.login($user) cy.visit('/') cy.injectAxe({ axeCorePath: 'node_modules/axe-core/axe.min.js' }) diff --git a/cypress/e2e/theming/user-settings_app-order.cy.ts b/cypress/e2e/theming/user-settings_app-order.cy.ts index 7e6efa7d0ea..11ef2f45382 100644 --- a/cypress/e2e/theming/user-settings_app-order.cy.ts +++ b/cypress/e2e/theming/user-settings_app-order.cy.ts @@ -83,7 +83,7 @@ describe('User theming set app order with default app', () => { // install a third app installTestApp() // set files as default app - cy.runOccCommand('config:system:set --value "files" defaultapp') + cy.runOccCommand('config:system:set --value \'files\' defaultapp') // Create random user for this test cy.createRandomUser().then(($user) => { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 28bd335eecf..410a970f77b 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<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) -}) - 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<string> => { - 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 a00a6a4c740..8d02ace151b 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,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') }) } @@ -60,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(' ', '')}`) + }) } diff --git a/cypress/support/cypress-e2e.d.ts b/cypress/support/cypress-e2e.d.ts index 13b181e6db6..afe93077d6a 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<void>, - /** - * Run an occ command in the docker container. - */ - runOccCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>, - userFileExists(user: string, path: string): Cypress.Chainable<number> - - /** - * Create a snapshot of the current database - */ - backupDB(): Cypress.Chainable<string>, - - /** - * Restore a snapshot of the database - * Default is the post-setup state - */ - restoreDB(snapshot?: string): Cypress.Chainable - - backupData(users?: string[]): Cypress.Chainable<string> - - restoreData(snapshot?: string): Cypress.Chainable } } } |