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