diff --git a/playwright/pages/client.ts b/playwright/pages/client.ts index abd487988b..7d62f42ae0 100644 --- a/playwright/pages/client.ts +++ b/playwright/pages/client.ts @@ -294,6 +294,8 @@ export class Client { * * This is often useful after joining a room, when we need to wait for the sync loop to catch up. * + * Times out with an error after 1 second. + * * @param roomId - ID of the room to check * @param membership - required membership. */ @@ -310,7 +312,15 @@ export class Client { }; if (isReady()) return; - return new Promise((resolve) => { + const timeoutPromise = new Promise((resolve) => setTimeout(resolve, 1000)).then(() => { + const room = cli.getRoom(roomId); + const myMembership = room?.getMyMembership(); + throw new Error( + `Timeout waiting for room ${roomId} membership (now '${myMembership}', wanted '${membership}')`, + ); + }); + + const readyPromise = new Promise((resolve) => { async function onEvent() { if (isReady()) { cli.removeListener(window.matrixcs.ClientEvent.Event, onEvent); @@ -320,6 +330,8 @@ export class Client { cli.on(window.matrixcs.ClientEvent.Event, onEvent); }); + + return Promise.race([timeoutPromise, readyPromise]); }, { roomId, membership }, );