From fdb0c1921ba7b3b841fd69836f11ec5b5ac5f6ee Mon Sep 17 00:00:00 2001 From: Estelle Comment Date: Wed, 14 Sep 2022 15:55:22 +0200 Subject: [PATCH 1/2] Add to readme --- cypress/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/README.md b/cypress/README.md index 2fdacce8a0..b812ae69e5 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -3,6 +3,6 @@ To run the tests, complete the env vars, start a web instance then run the tests Files in 'support' folder are automatically imported by Cypress TODO : - - make all this run in CI ! Will need running a tchap-web server at http://localhost:8080 + - make all this run in CI ! Will need running a tchap-web server at http://localhost:8080. Cypress does not recommend that the server be started by cypress itself (https://docs.cypress.io/guides/references/best-practices#Web-Servers) - clean up the server after each test : delete created rooms, log out, ... - import/symlink/whatever the files we are using from matrix-react-sdk, instead of copying them to tchap-web repo. From f9850c9aafd911b5e88248e00d0ee326d206fd29 Mon Sep 17 00:00:00 2001 From: Estelle Comment Date: Wed, 14 Sep 2022 16:15:52 +0200 Subject: [PATCH 2/2] Leave rooms after each test, to avoid accumulating rooms --- cypress/e2e/create-room/create-room.spec.ts | 18 ++++++++++++++++-- cypress/support/client.ts | 10 ++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/create-room/create-room.spec.ts b/cypress/e2e/create-room/create-room.spec.ts index ff8dde152f..ea2bbe5733 100644 --- a/cypress/e2e/create-room/create-room.spec.ts +++ b/cypress/e2e/create-room/create-room.spec.ts @@ -43,8 +43,22 @@ describe("Create Room", () => { }); afterEach(() => { - // todo logout, otherwise the login test is not reliable aby more. - // todo delete room, otherwise the test user will end up with a million identical rooms after a while. + // We find the roomId to clean up from the current URL. + // Note : This is simple and works, so good enough for now. But if we want to store the roomId at the end of the test instead, we could use “as” + // for passing the value around : https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Sharing-Context + // Do NOT use a describe-level variable (like "let roomIdToCleanup") like we do in unit tests, cypress does not work like that. + cy.url().then(urlString => { + console.log('roomId url string', urlString); + console.log('roomId url string split', urlString.split('/#/room/')); + console.log('roomIdToCleanup', urlString.split('/#/room/')[1]); + const roomId = urlString.split('/#/room/')[1]; + if (roomId) { + cy.leaveRoom(roomId); + // todo also forgetRoom to save resources. + } else { + console.error('Did not find roomId in url. Not cleaning up.'); + } + }); }); it("should allow us to create a private room with name", () => { diff --git a/cypress/support/client.ts b/cypress/support/client.ts index c3f3aab0eb..b0531866bd 100644 --- a/cypress/support/client.ts +++ b/cypress/support/client.ts @@ -129,6 +129,12 @@ declare global { * @param roomIdOrAlias the id or alias of the room to join */ joinRoom(roomIdOrAlias: string): Chainable; + /** + * :TCHAP: added this function + * Leave a room. + * @param roomId the id of the room to invite to + */ + leaveRoom(roomId: string): Chainable<{}>; } } } @@ -226,3 +232,7 @@ Cypress.Commands.add("bootstrapCrossSigning", () => { Cypress.Commands.add("joinRoom", (roomIdOrAlias: string): Chainable => { return cy.getClient().then(cli => cli.joinRoom(roomIdOrAlias)); }); + +Cypress.Commands.add("leaveRoom", (roomId: string): Chainable<{}> => { + return cy.getClient().then(cli => cli.leave(roomId)); +});