message: make receiveMessage more robust by checking first if the message is not already in the timeline
diff: @@ -46,6 +46,21 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
  session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
  // wait for a response to come in that contains the message
  // crude, but effective
  +
  + async function assertLastMessage() {
  + const lastTile = await getLastEventTile(session);
  + const lastMessage = await getMessageFromEventTile(lastTile);
  + await assertMessage(lastMessage, expectedMessage);
  + }
  +
  + // first try to see if the message is already the last message in the timeline
  + let isExpectedMessage = false;
  + try {
  + assertLastMessage();
  + isExpectedMessage = true;
  + } catch(ex) {}
  +
  + if (!isExpectedMessage) {
  await session.page.waitForResponse(async (response) => {
  if (response.request().url().indexOf("/sync") === -1) {
  return false;
  @@ -60,9 +75,9 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
  });
  // wait a bit for the incoming event to be rendered
  await session.delay(1000);
  - const lastTile = await getLastEventTile(session);
  - const foundMessage = await getMessageFromEventTile(lastTile);
  - assertMessage(foundMessage, expectedMessage);
  + await assertLastMessage();
  + }
  +
  session.log.done();
  }
  