dont assert the first time in receiveMessage, as it will show an ugly assert error while everything is fine, just need to wait longer

This commit is contained in:
Bruno Windels 2018-09-14 09:52:34 +02:00
parent 9f4cf776c5
commit af255c6386

View file

@ -47,20 +47,23 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
// wait for a response to come in that contains the message // wait for a response to come in that contains the message
// crude, but effective // crude, but effective
async function assertLastMessage() { async function getLastMessage() {
const lastTile = await getLastEventTile(session); const lastTile = await getLastEventTile(session);
const lastMessage = await getMessageFromEventTile(lastTile); return getMessageFromEventTile(lastTile);
await assertMessage(lastMessage, expectedMessage);
} }
// first try to see if the message is already the last message in the timeline let lastMessage = null;
let isExpectedMessage = false; let isExpectedMessage = false;
try { try {
assertLastMessage(); lastMessage = await getLastMessage();
isExpectedMessage = true; isExpectedMessage = lastMessage &&
lastMessage.body === expectedMessage.body &&
lastMessage.sender === expectedMessage.sender;
} catch(ex) {} } catch(ex) {}
// first try to see if the message is already the last message in the timeline
if (!isExpectedMessage) { if (isExpectedMessage) {
assertMessage(lastMessage, expectedMessage);
} else {
await session.page.waitForResponse(async (response) => { await session.page.waitForResponse(async (response) => {
if (response.request().url().indexOf("/sync") === -1) { if (response.request().url().indexOf("/sync") === -1) {
return false; return false;
@ -75,7 +78,8 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
}); });
// wait a bit for the incoming event to be rendered // wait a bit for the incoming event to be rendered
await session.delay(1000); await session.delay(1000);
await assertLastMessage(); lastMessage = await getLastMessage();
assertMessage(lastMessage, expectedMessage);
} }
session.log.done(); session.log.done();