From d8d3ebc6d644168804441a60e529a6e7dc841140 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 13 Jan 2025 14:29:27 +0000 Subject: [PATCH] Fix playwright flakes due to floating promises Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintrc.js | 1 + playwright/e2e/accessibility/keyboard-navigation.spec.ts | 2 +- playwright/e2e/chat-export/html-export.spec.ts | 2 +- playwright/e2e/composer/RTE.spec.ts | 2 +- playwright/e2e/crypto/device-verification.spec.ts | 2 +- playwright/e2e/crypto/user-verification.spec.ts | 2 +- playwright/e2e/crypto/utils.ts | 4 ++-- playwright/e2e/knock/manage-knocks.spec.ts | 2 +- playwright/e2e/login/utils.ts | 2 +- playwright/e2e/polls/pollHistory.spec.ts | 2 +- playwright/e2e/room_options/marked_unread.spec.ts | 2 +- playwright/e2e/settings/account-user-settings-tab.spec.ts | 4 ++-- .../e2e/settings/preferences-user-settings-tab.spec.ts | 4 ++-- playwright/e2e/sliding-sync/sliding-sync.spec.ts | 4 ++-- playwright/e2e/threads/threads.spec.ts | 8 ++++---- playwright/e2e/widgets/stickers.spec.ts | 6 +++--- playwright/pages/bot.ts | 2 +- 17 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2b0dd2c186b..28d26696cb1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -271,6 +271,7 @@ module.exports = { }, rules: { "react-hooks/rules-of-hooks": ["off"], + "@typescript-eslint/no-floating-promises": ["error"], }, }, { diff --git a/playwright/e2e/accessibility/keyboard-navigation.spec.ts b/playwright/e2e/accessibility/keyboard-navigation.spec.ts index 6f4fc9be5fc..e22664c8985 100644 --- a/playwright/e2e/accessibility/keyboard-navigation.spec.ts +++ b/playwright/e2e/accessibility/keyboard-navigation.spec.ts @@ -123,7 +123,7 @@ test.describe("Landmark navigation tests", () => { await expect(page.getByText("Bob joined the room")).toBeVisible(); // Close the room - page.goto("/#/home"); + await page.goto("/#/home"); // Pressing Control+F6 will first focus the space button await page.keyboard.press("ControlOrMeta+F6"); diff --git a/playwright/e2e/chat-export/html-export.spec.ts b/playwright/e2e/chat-export/html-export.spec.ts index 33ca6728c6c..760d3cc5f1c 100644 --- a/playwright/e2e/chat-export/html-export.spec.ts +++ b/playwright/e2e/chat-export/html-export.spec.ts @@ -95,7 +95,7 @@ test.describe("HTML Export", () => { async ({ page, app, room }) => { // Set a fixed time rather than masking off the line with the time in it: we don't need to worry // about the width changing and we can actually test this line looks correct. - page.clock.setSystemTime(new Date("2024-01-01T00:00:00Z")); + await page.clock.setSystemTime(new Date("2024-01-01T00:00:00Z")); // Send a bunch of messages to populate the room for (let i = 1; i < 10; i++) { diff --git a/playwright/e2e/composer/RTE.spec.ts b/playwright/e2e/composer/RTE.spec.ts index 3b750000c56..e88dd827fcc 100644 --- a/playwright/e2e/composer/RTE.spec.ts +++ b/playwright/e2e/composer/RTE.spec.ts @@ -165,7 +165,7 @@ test.describe("Composer", () => { // Type another await page.locator("div[contenteditable=true]").pressSequentially("my message 1"); // Send message - page.locator("div[contenteditable=true]").press("Enter"); + await page.locator("div[contenteditable=true]").press("Enter"); // It was sent await expect(page.locator(".mx_EventTile_last .mx_EventTile_body").getByText("my message 1")).toBeVisible(); }); diff --git a/playwright/e2e/crypto/device-verification.spec.ts b/playwright/e2e/crypto/device-verification.spec.ts index a028bfb70c2..df75ff5f77b 100644 --- a/playwright/e2e/crypto/device-verification.spec.ts +++ b/playwright/e2e/crypto/device-verification.spec.ts @@ -212,7 +212,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => { /* on the bot side, wait for the verifier to exist ... */ const verifier = await awaitVerifier(botVerificationRequest); // ... confirm ... - botVerificationRequest.evaluate((verificationRequest) => verificationRequest.verifier.verify()); + void botVerificationRequest.evaluate((verificationRequest) => verificationRequest.verifier.verify()); // ... and then check the emoji match await doTwoWaySasVerification(page, verifier); diff --git a/playwright/e2e/crypto/user-verification.spec.ts b/playwright/e2e/crypto/user-verification.spec.ts index 7d428ac0604..175c8d5fdfd 100644 --- a/playwright/e2e/crypto/user-verification.spec.ts +++ b/playwright/e2e/crypto/user-verification.spec.ts @@ -74,7 +74,7 @@ test.describe("User verification", () => { /* on the bot side, wait for the verifier to exist ... */ const botVerifier = await awaitVerifier(bobVerificationRequest); // ... confirm ... - botVerifier.evaluate((verifier) => verifier.verify()); + void botVerifier.evaluate((verifier) => verifier.verify()); // ... and then check the emoji match await doTwoWaySasVerification(page, botVerifier); diff --git a/playwright/e2e/crypto/utils.ts b/playwright/e2e/crypto/utils.ts index 48da798f1a7..697572faa75 100644 --- a/playwright/e2e/crypto/utils.ts +++ b/playwright/e2e/crypto/utils.ts @@ -59,7 +59,7 @@ export function handleSasVerification(verifier: JSHandle): Promise((resolve) => { const onShowSas = (event: ShowSasCallbacks) => { verifier.off("show_sas" as VerifierEvent, onShowSas); - event.confirm(); + void event.confirm(); resolve(event.sas.emoji); }; @@ -313,7 +313,7 @@ export async function autoJoin(client: Client) { await client.evaluate((cli) => { cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => { if (member.membership === "invite" && member.userId === cli.getUserId()) { - cli.joinRoom(member.roomId); + void cli.joinRoom(member.roomId); } }); }); diff --git a/playwright/e2e/knock/manage-knocks.spec.ts b/playwright/e2e/knock/manage-knocks.spec.ts index fb7e2751945..6d0340170e1 100644 --- a/playwright/e2e/knock/manage-knocks.spec.ts +++ b/playwright/e2e/knock/manage-knocks.spec.ts @@ -50,7 +50,7 @@ test.describe("Manage Knocks", () => { }); test("should deny knock using bar", async ({ page, app, bot, room }) => { - bot.knockRoom(room.roomId); + await bot.knockRoom(room.roomId); const roomKnocksBar = page.locator(".mx_RoomKnocksBar"); await expect(roomKnocksBar.getByRole("heading", { name: "Asking to join" })).toBeVisible(); diff --git a/playwright/e2e/login/utils.ts b/playwright/e2e/login/utils.ts index cc98d8819a2..6e52dd99818 100644 --- a/playwright/e2e/login/utils.ts +++ b/playwright/e2e/login/utils.ts @@ -92,7 +92,7 @@ export async function interceptRequestsWithSoftLogout(page: Page, user: Credenti // do something to make the active /sync return: create a new room await page.evaluate(() => { // don't wait for this to complete: it probably won't, because of the broken sync - window.mxMatrixClientPeg.get().createRoom({}); + void window.mxMatrixClientPeg.get().createRoom({}); }); await promise; diff --git a/playwright/e2e/polls/pollHistory.spec.ts b/playwright/e2e/polls/pollHistory.spec.ts index a4d6a8ae0e0..319a08cda91 100644 --- a/playwright/e2e/polls/pollHistory.spec.ts +++ b/playwright/e2e/polls/pollHistory.spec.ts @@ -134,7 +134,7 @@ test.describe("Poll history", () => { await expect(dialog.getByText(pollParams2.title)).toBeAttached(); await expect(dialog.getByText(pollParams1.title)).toBeAttached(); - dialog.getByText("Active polls").click(); + await dialog.getByText("Active polls").click(); // no more active polls await expect(page.getByText("There are no active polls in this room")).toBeAttached(); diff --git a/playwright/e2e/room_options/marked_unread.spec.ts b/playwright/e2e/room_options/marked_unread.spec.ts index b314152e684..d7011684a7e 100644 --- a/playwright/e2e/room_options/marked_unread.spec.ts +++ b/playwright/e2e/room_options/marked_unread.spec.ts @@ -48,6 +48,6 @@ test.describe("Mark as Unread", () => { await roomTile.getByRole("button", { name: "Room options" }).click(); await page.getByRole("menuitem", { name: "Mark as unread" }).click(); - expect(page.getByLabel(TEST_ROOM_NAME + " Unread messages.")).toBeVisible(); + await expect(page.getByLabel(TEST_ROOM_NAME + " Unread messages.")).toBeVisible(); }); }); diff --git a/playwright/e2e/settings/account-user-settings-tab.spec.ts b/playwright/e2e/settings/account-user-settings-tab.spec.ts index f0374174477..df011bdc4e5 100644 --- a/playwright/e2e/settings/account-user-settings-tab.spec.ts +++ b/playwright/e2e/settings/account-user-settings-tab.spec.ts @@ -34,14 +34,14 @@ test.describe("Account user settings tab", () => { await expect(profile.getByRole("textbox", { name: "Display Name" })).toHaveValue(USER_NAME); // Assert that a userId is rendered - expect(uut.getByLabel("Username")).toHaveText(user.userId); + await expect(uut.getByLabel("Username")).toHaveText(user.userId); // Wait until spinners disappear await expect(uut.getByTestId("accountSection").locator(".mx_Spinner")).not.toBeVisible(); await expect(uut.getByTestId("discoverySection").locator(".mx_Spinner")).not.toBeVisible(); const accountSection = uut.getByTestId("accountSection"); - accountSection.scrollIntoViewIfNeeded(); + await accountSection.scrollIntoViewIfNeeded(); // Assert that input areas for changing a password exists await expect(accountSection.getByLabel("Current password")).toBeVisible(); await expect(accountSection.getByLabel("New Password")).toBeVisible(); diff --git a/playwright/e2e/settings/preferences-user-settings-tab.spec.ts b/playwright/e2e/settings/preferences-user-settings-tab.spec.ts index 4b6e3e299d7..5c7c9efffb8 100644 --- a/playwright/e2e/settings/preferences-user-settings-tab.spec.ts +++ b/playwright/e2e/settings/preferences-user-settings-tab.spec.ts @@ -24,7 +24,7 @@ test.describe("Preferences user settings tab", () => { }); test("should be rendered properly", { tag: "@screenshot" }, async ({ app, page, user }) => { - page.setViewportSize({ width: 1024, height: 3300 }); + await page.setViewportSize({ width: 1024, height: 3300 }); const tab = await app.settings.openUserSettings("Preferences"); // Assert that the top heading is rendered await expect(tab.getByRole("heading", { name: "Preferences" })).toBeVisible(); @@ -61,7 +61,7 @@ test.describe("Preferences user settings tab", () => { // Click the button to display the dropdown menu await timezoneInput.getByRole("button", { name: "Set timezone" }).click(); // Select a different value - timezoneInput.getByRole("option", { name: /Africa\/Abidjan/ }).click(); + await timezoneInput.getByRole("option", { name: /Africa\/Abidjan/ }).click(); // Check the new value await expect(timezoneValue.getByText("Africa/Abidjan")).toBeVisible(); }); diff --git a/playwright/e2e/sliding-sync/sliding-sync.spec.ts b/playwright/e2e/sliding-sync/sliding-sync.spec.ts index 1ab7909a478..0fde7ddefb8 100644 --- a/playwright/e2e/sliding-sync/sliding-sync.spec.ts +++ b/playwright/e2e/sliding-sync/sliding-sync.spec.ts @@ -275,7 +275,7 @@ test.describe("Sliding Sync", () => { // now rescind the invite await bot.evaluate( async (client, { roomRescind, clientUserId }) => { - client.kick(roomRescind, clientUserId); + await client.kick(roomRescind, clientUserId); }, { roomRescind, clientUserId }, ); @@ -294,7 +294,7 @@ test.describe("Sliding Sync", () => { is_direct: true, }); await app.client.evaluate(async (client, roomId) => { - client.setRoomTag(roomId, "m.favourite", { order: 0.5 }); + await client.setRoomTag(roomId, "m.favourite", { order: 0.5 }); }, roomId); await expect(page.getByRole("group", { name: "Favourites" }).getByText("Favourite DM")).toBeVisible(); await expect(page.getByRole("group", { name: "People" }).getByText("Favourite DM")).not.toBeAttached(); diff --git a/playwright/e2e/threads/threads.spec.ts b/playwright/e2e/threads/threads.spec.ts index edcc0578d8a..4e84e812e2c 100644 --- a/playwright/e2e/threads/threads.spec.ts +++ b/playwright/e2e/threads/threads.spec.ts @@ -164,7 +164,7 @@ test.describe("Threads", () => { locator = page.locator( ".mx_ThreadView .mx_GenericEventListSummary[data-layout=bubble] .mx_EventTile_info.mx_EventTile_last", ); - expect(locator.locator(".mx_EventTile_line .mx_EventTile_content")) + await expect(locator.locator(".mx_EventTile_line .mx_EventTile_content")) // 76px: ThreadViewGroupSpacingStart + 14px + 6px // 14px: avatar width // See: _EventTile.pcss @@ -233,8 +233,8 @@ test.describe("Threads", () => { // User closes right panel after clicking back to thread list locator = page.locator(".mx_ThreadPanel"); - locator.getByRole("button", { name: "Threads" }).click(); - locator.getByRole("button", { name: "Close" }).click(); + await locator.getByRole("button", { name: "Threads" }).click(); + await locator.getByRole("button", { name: "Close" }).click(); // Bot responds to thread await bot.sendMessage(roomId, "How are things?", threadId); @@ -344,7 +344,7 @@ test.describe("Threads", () => { await expect(page.locator(".mx_ThreadView_timelinePanelWrapper")).toHaveCount(1); - (await app.openMessageComposerOptions(true)).getByRole("menuitem", { name: "Voice Message" }).click(); + await (await app.openMessageComposerOptions(true)).getByRole("menuitem", { name: "Voice Message" }).click(); await page.waitForTimeout(3000); await app.getComposer(true).getByRole("button", { name: "Send voice message" }).click(); await expect(page.locator(".mx_ThreadView .mx_MVoiceMessageBody")).toHaveCount(1); diff --git a/playwright/e2e/widgets/stickers.spec.ts b/playwright/e2e/widgets/stickers.spec.ts index 54de1b69e28..2477efdc6b3 100644 --- a/playwright/e2e/widgets/stickers.spec.ts +++ b/playwright/e2e/widgets/stickers.spec.ts @@ -150,7 +150,7 @@ test.describe("Stickers", { tag: ["@no-firefox", "@no-webkit"] }, () => { const { content_uri: contentUri } = await app.client.uploadContent(STICKER_IMAGE, { type: "image/png" }); const widgetHtml = getWidgetHtml(contentUri, "image/png"); stickerPickerUrl = webserver.start(widgetHtml); - setWidgetAccountData(app, user, stickerPickerUrl); + await setWidgetAccountData(app, user, stickerPickerUrl); await app.viewRoomByName(ROOM_NAME_1); await expect(page).toHaveURL(`/#/room/${room.roomId}`); @@ -177,7 +177,7 @@ test.describe("Stickers", { tag: ["@no-firefox", "@no-webkit"] }, () => { const { content_uri: contentUri } = await app.client.uploadContent(STICKER_IMAGE, { type: "image/png" }); const widgetHtml = getWidgetHtml(contentUri, "image/png"); stickerPickerUrl = webserver.start(widgetHtml); - setWidgetAccountData(app, user, stickerPickerUrl, false); + await setWidgetAccountData(app, user, stickerPickerUrl, false); await app.viewRoomByName(ROOM_NAME_1); await expect(page).toHaveURL(`/#/room/${room.roomId}`); @@ -192,7 +192,7 @@ test.describe("Stickers", { tag: ["@no-firefox", "@no-webkit"] }, () => { }); const widgetHtml = getWidgetHtml(contentUri, "application/octet-stream"); stickerPickerUrl = webserver.start(widgetHtml); - setWidgetAccountData(app, user, stickerPickerUrl); + await setWidgetAccountData(app, user, stickerPickerUrl); await app.viewRoomByName(ROOM_NAME_1); await expect(page).toHaveURL(`/#/room/${room.roomId}`); diff --git a/playwright/pages/bot.ts b/playwright/pages/bot.ts index 1d414c7bf6a..200f83e2f6f 100644 --- a/playwright/pages/bot.ts +++ b/playwright/pages/bot.ts @@ -171,7 +171,7 @@ export class Bot extends Client { if (opts.autoAcceptInvites) { cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => { if (member.membership === "invite" && member.userId === cli.getUserId()) { - cli.joinRoom(member.roomId); + void cli.joinRoom(member.roomId); } }); }