Skip to content

Commit

Permalink
Fix playwright flakes due to floating promises (#28981)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy authored Jan 13, 2025
1 parent 2cddb16 commit 1a21b71
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ module.exports = {
},
rules: {
"react-hooks/rules-of-hooks": ["off"],
"@typescript-eslint/no-floating-promises": ["error"],
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/accessibility/keyboard-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/chat-export/html-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/composer/RTE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/crypto/device-verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/crypto/user-verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/crypto/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function handleSasVerification(verifier: JSHandle<Verifier>): Promise<Emo
return new Promise<EmojiMapping[]>((resolve) => {
const onShowSas = (event: ShowSasCallbacks) => {
verifier.off("show_sas" as VerifierEvent, onShowSas);
event.confirm();
void event.confirm();
resolve(event.sas.emoji);
};

Expand Down Expand Up @@ -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);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/knock/manage-knocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/login/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/polls/pollHistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion playwright/e2e/room_options/marked_unread.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
4 changes: 2 additions & 2 deletions playwright/e2e/settings/account-user-settings-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/settings/preferences-user-settings-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions playwright/e2e/sliding-sync/sliding-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions playwright/e2e/widgets/stickers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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}`);
Expand All @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion playwright/pages/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 1a21b71

Please sign in to comment.