From 7fb48d24e4ea977e8c2aaf5ddd7c0010bdef7acd Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 8 Jul 2022 13:14:13 +0100 Subject: [PATCH] Upgrade to Cypress 10 (#9008) * Upgrade to Cypress 10 * Remove stale comment --- cypress.config.ts | 33 ++++ cypress.json | 13 -- .../1-register/register.spec.ts | 0 .../10-user-view/user-view.spec.ts | 0 .../11-room-directory/room-directory.spec.ts | 0 .../12-spotlight/spotlight.spec.ts | 0 .../pills-click-in-app.spec.ts | 0 .../2-login/consent.spec.ts | 0 .../2-login/login.spec.ts | 0 .../3-user-menu/user-menu.spec.ts | 0 .../4-create-room/create-room.spec.ts | 0 .../5-threads/threads.spec.ts | 0 .../6-spaces/spaces.spec.ts | 0 .../7-crypto/crypto.spec.ts | 0 .../8-update/update.spec.ts | 0 .../9-widgets/stickers.spec.ts | 0 .../integration/14-timeline/timeline.spec.ts | 145 ------------------ cypress/support/{index.ts => e2e.ts} | 0 package.json | 2 +- yarn.lock | 8 +- 20 files changed, 38 insertions(+), 163 deletions(-) create mode 100644 cypress.config.ts delete mode 100644 cypress.json rename cypress/{integration => e2e}/1-register/register.spec.ts (100%) rename cypress/{integration => e2e}/10-user-view/user-view.spec.ts (100%) rename cypress/{integration => e2e}/11-room-directory/room-directory.spec.ts (100%) rename cypress/{integration => e2e}/12-spotlight/spotlight.spec.ts (100%) rename cypress/{integration => e2e}/13-regression-tests/pills-click-in-app.spec.ts (100%) rename cypress/{integration => e2e}/2-login/consent.spec.ts (100%) rename cypress/{integration => e2e}/2-login/login.spec.ts (100%) rename cypress/{integration => e2e}/3-user-menu/user-menu.spec.ts (100%) rename cypress/{integration => e2e}/4-create-room/create-room.spec.ts (100%) rename cypress/{integration => e2e}/5-threads/threads.spec.ts (100%) rename cypress/{integration => e2e}/6-spaces/spaces.spec.ts (100%) rename cypress/{integration => e2e}/7-crypto/crypto.spec.ts (100%) rename cypress/{integration => e2e}/8-update/update.spec.ts (100%) rename cypress/{integration => e2e}/9-widgets/stickers.spec.ts (100%) delete mode 100644 cypress/integration/14-timeline/timeline.spec.ts rename cypress/support/{index.ts => e2e.ts} (100%) diff --git a/cypress.config.ts b/cypress.config.ts new file mode 100644 index 0000000000..9236ee2931 --- /dev/null +++ b/cypress.config.ts @@ -0,0 +1,33 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { defineConfig } from 'cypress'; + +export default defineConfig({ + videoUploadOnPasses: false, + projectId: 'ppvnzg', + experimentalInteractiveRunEvents: true, + defaultCommandTimeout: 10000, + chromeWebSecurity: false, + e2e: { + setupNodeEvents(on, config) { + return require('./cypress/plugins/index.ts').default(on, config); + }, + baseUrl: 'http://localhost:8080', + experimentalSessionAndOrigin: true, + specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}', + }, +}); diff --git a/cypress.json b/cypress.json deleted file mode 100644 index 66a45fcc79..0000000000 --- a/cypress.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "baseUrl": "http://localhost:8080", - "videoUploadOnPasses": false, - "projectId": "ppvnzg", - "experimentalSessionAndOrigin": true, - "experimentalInteractiveRunEvents": true, - "retries": { - "runMode": 2, - "openMode": 0 - }, - "defaultCommandTimeout": 10000, - "chromeWebSecurity": false -} diff --git a/cypress/integration/1-register/register.spec.ts b/cypress/e2e/1-register/register.spec.ts similarity index 100% rename from cypress/integration/1-register/register.spec.ts rename to cypress/e2e/1-register/register.spec.ts diff --git a/cypress/integration/10-user-view/user-view.spec.ts b/cypress/e2e/10-user-view/user-view.spec.ts similarity index 100% rename from cypress/integration/10-user-view/user-view.spec.ts rename to cypress/e2e/10-user-view/user-view.spec.ts diff --git a/cypress/integration/11-room-directory/room-directory.spec.ts b/cypress/e2e/11-room-directory/room-directory.spec.ts similarity index 100% rename from cypress/integration/11-room-directory/room-directory.spec.ts rename to cypress/e2e/11-room-directory/room-directory.spec.ts diff --git a/cypress/integration/12-spotlight/spotlight.spec.ts b/cypress/e2e/12-spotlight/spotlight.spec.ts similarity index 100% rename from cypress/integration/12-spotlight/spotlight.spec.ts rename to cypress/e2e/12-spotlight/spotlight.spec.ts diff --git a/cypress/integration/13-regression-tests/pills-click-in-app.spec.ts b/cypress/e2e/13-regression-tests/pills-click-in-app.spec.ts similarity index 100% rename from cypress/integration/13-regression-tests/pills-click-in-app.spec.ts rename to cypress/e2e/13-regression-tests/pills-click-in-app.spec.ts diff --git a/cypress/integration/2-login/consent.spec.ts b/cypress/e2e/2-login/consent.spec.ts similarity index 100% rename from cypress/integration/2-login/consent.spec.ts rename to cypress/e2e/2-login/consent.spec.ts diff --git a/cypress/integration/2-login/login.spec.ts b/cypress/e2e/2-login/login.spec.ts similarity index 100% rename from cypress/integration/2-login/login.spec.ts rename to cypress/e2e/2-login/login.spec.ts diff --git a/cypress/integration/3-user-menu/user-menu.spec.ts b/cypress/e2e/3-user-menu/user-menu.spec.ts similarity index 100% rename from cypress/integration/3-user-menu/user-menu.spec.ts rename to cypress/e2e/3-user-menu/user-menu.spec.ts diff --git a/cypress/integration/4-create-room/create-room.spec.ts b/cypress/e2e/4-create-room/create-room.spec.ts similarity index 100% rename from cypress/integration/4-create-room/create-room.spec.ts rename to cypress/e2e/4-create-room/create-room.spec.ts diff --git a/cypress/integration/5-threads/threads.spec.ts b/cypress/e2e/5-threads/threads.spec.ts similarity index 100% rename from cypress/integration/5-threads/threads.spec.ts rename to cypress/e2e/5-threads/threads.spec.ts diff --git a/cypress/integration/6-spaces/spaces.spec.ts b/cypress/e2e/6-spaces/spaces.spec.ts similarity index 100% rename from cypress/integration/6-spaces/spaces.spec.ts rename to cypress/e2e/6-spaces/spaces.spec.ts diff --git a/cypress/integration/7-crypto/crypto.spec.ts b/cypress/e2e/7-crypto/crypto.spec.ts similarity index 100% rename from cypress/integration/7-crypto/crypto.spec.ts rename to cypress/e2e/7-crypto/crypto.spec.ts diff --git a/cypress/integration/8-update/update.spec.ts b/cypress/e2e/8-update/update.spec.ts similarity index 100% rename from cypress/integration/8-update/update.spec.ts rename to cypress/e2e/8-update/update.spec.ts diff --git a/cypress/integration/9-widgets/stickers.spec.ts b/cypress/e2e/9-widgets/stickers.spec.ts similarity index 100% rename from cypress/integration/9-widgets/stickers.spec.ts rename to cypress/e2e/9-widgets/stickers.spec.ts diff --git a/cypress/integration/14-timeline/timeline.spec.ts b/cypress/integration/14-timeline/timeline.spec.ts deleted file mode 100644 index 22861c8fd7..0000000000 --- a/cypress/integration/14-timeline/timeline.spec.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* -Copyright 2022 The Matrix.org Foundation C.I.C. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/// - -import { MessageEvent } from "matrix-events-sdk"; - -import type { ISendEventResponse } from "matrix-js-sdk/src/@types/requests"; -import type { EventType } from "matrix-js-sdk/src/@types/event"; -import type { MatrixClient } from "matrix-js-sdk/src/client"; -import { SynapseInstance } from "../../plugins/synapsedocker"; -import { SettingLevel } from "../../../src/settings/SettingLevel"; -import Chainable = Cypress.Chainable; - -// The avatar size used in the timeline -const AVATAR_SIZE = 30; -// The resize method used in the timeline -const AVATAR_RESIZE_METHOD = "crop"; - -const ROOM_NAME = "Test room"; -const OLD_AVATAR = "avatar_image1"; -const NEW_AVATAR = "avatar_image2"; -const OLD_NAME = "Alan"; -const NEW_NAME = "Alan (away)"; - -const getEventTilesWithBodies = (): Chainable => { - return cy.get(".mx_EventTile").filter((_i, e) => e.getElementsByClassName("mx_EventTile_body").length > 0); -}; - -const expectDisplayName = (e: JQuery, displayName: string): void => { - expect(e.find(".mx_DisambiguatedProfile_displayName").text()).to.equal(displayName); -}; - -const expectAvatar = (e: JQuery, avatarUrl: string): void => { - cy.getClient().then((cli: MatrixClient) => { - expect(e.find(".mx_BaseAvatar_image").attr("src")).to.equal( - // eslint-disable-next-line no-restricted-properties - cli.mxcUrlToHttp(avatarUrl, AVATAR_SIZE, AVATAR_SIZE, AVATAR_RESIZE_METHOD), - ); - }); -}; - -const sendEvent = (roomId: string): Chainable => { - return cy.sendEvent( - roomId, - null, - "m.room.message" as EventType, - MessageEvent.from("Message").serialize().content, - ); -}; - -describe("Timeline", () => { - let synapse: SynapseInstance; - - let roomId: string; - - let oldAvatarUrl: string; - let newAvatarUrl: string; - - describe("useOnlyCurrentProfiles", () => { - beforeEach(() => { - cy.startSynapse("default").then(data => { - synapse = data; - cy.initTestUser(synapse, OLD_NAME).then(() => - cy.window({ log: false }).then(() => { - cy.createRoom({ name: ROOM_NAME }).then(_room1Id => { - roomId = _room1Id; - }); - }), - ).then(() => { - cy.uploadContent(OLD_AVATAR).then((url) => { - oldAvatarUrl = url; - cy.setAvatarUrl(url); - }); - }).then(() => { - cy.uploadContent(NEW_AVATAR).then((url) => { - newAvatarUrl = url; - }); - }); - }); - }); - - afterEach(() => { - cy.stopSynapse(synapse); - }); - - it("should show historical profiles if disabled", () => { - cy.setSettingValue("useOnlyCurrentProfiles", null, SettingLevel.ACCOUNT, false); - sendEvent(roomId); - cy.setDisplayName("Alan (away)"); - cy.setAvatarUrl(newAvatarUrl); - // XXX: If we send the second event too quickly, there won't be - // enough time for the client to register the profile change - cy.wait(500); - sendEvent(roomId); - cy.viewRoomByName(ROOM_NAME); - - const events = getEventTilesWithBodies(); - - events.should("have.length", 2); - events.each((e, i) => { - if (i === 0) { - expectDisplayName(e, OLD_NAME); - expectAvatar(e, oldAvatarUrl); - } else if (i === 1) { - expectDisplayName(e, NEW_NAME); - expectAvatar(e, newAvatarUrl); - } - }); - }); - - it("should not show historical profiles if enabled", () => { - cy.setSettingValue("useOnlyCurrentProfiles", null, SettingLevel.ACCOUNT, true); - sendEvent(roomId); - cy.setDisplayName(NEW_NAME); - cy.setAvatarUrl(newAvatarUrl); - // XXX: If we send the second event too quickly, there won't be - // enough time for the client to register the profile change - cy.wait(500); - sendEvent(roomId); - cy.viewRoomByName(ROOM_NAME); - - const events = getEventTilesWithBodies(); - - events.should("have.length", 2); - events.each((e) => { - expectDisplayName(e, NEW_NAME); - expectAvatar(e, newAvatarUrl); - }); - }); - }); -}); diff --git a/cypress/support/index.ts b/cypress/support/e2e.ts similarity index 100% rename from cypress/support/index.ts rename to cypress/support/e2e.ts diff --git a/package.json b/package.json index 8b1aa4a4ca..71051a1538 100644 --- a/package.json +++ b/package.json @@ -170,7 +170,7 @@ "babel-jest": "^26.6.3", "blob-polyfill": "^6.0.20211015", "chokidar": "^3.5.1", - "cypress": "^9.6.1", + "cypress": "^10.3.0", "cypress-real-events": "^1.7.0", "enzyme": "^3.11.0", "enzyme-to-json": "^3.6.2", diff --git a/yarn.lock b/yarn.lock index a7131a96e0..10b1f6c351 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3651,10 +3651,10 @@ cypress-real-events@^1.7.0: resolved "https://registry.yarnpkg.com/cypress-real-events/-/cypress-real-events-1.7.0.tgz#ad6a78de33af3af0e6437f5c713e30691c44472c" integrity sha512-iyXp07j0V9sG3YClVDcvHN2DAQDgr+EjTID82uWDw6OZBlU3pXEBqTMNYqroz3bxlb0k+F74U81aZwzMNaKyew== -cypress@^9.6.1: - version "9.6.1" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.6.1.tgz#a7d6b5a53325b3dc4960181f5800a5ade0f085eb" - integrity sha512-ECzmV7pJSkk+NuAhEw6C3D+RIRATkSb2VAHXDY6qGZbca/F9mv5pPsj2LO6Ty6oIFVBTrwCyL9agl28MtJMe2g== +cypress@^10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-10.3.0.tgz#fae8d32f0822fcfb938e79c7c31ef344794336ae" + integrity sha512-txkQWKzvBVnWdCuKs5Xc08gjpO89W2Dom2wpZgT9zWZT5jXxqPIxqP/NC1YArtkpmp3fN5HW8aDjYBizHLUFvg== dependencies: "@cypress/request" "^2.88.10" "@cypress/xvfb" "^1.2.4"