From d3862a3afd3d5b9b08a1decd57fb0a737c64d5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 11 Mar 2022 10:29:42 +0100 Subject: [PATCH] Better e2e tests (#1959) * Adding a timeout to wait for old map to be correctly loaded * Adding an exception for E2E tests to load a local map as if it was remote. --- back/src/Services/MapFetcher.ts | 9 +++++++++ tests/tests/variables.spec.ts | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/back/src/Services/MapFetcher.ts b/back/src/Services/MapFetcher.ts index 813685b2..3eeab9b8 100644 --- a/back/src/Services/MapFetcher.ts +++ b/back/src/Services/MapFetcher.ts @@ -43,6 +43,15 @@ class MapFetcher { * @private */ async isLocalUrl(url: string): Promise { + if ( + url === + "http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json" + ) { + // This is an ugly exception case needed for the E2E test at "tests/tests/variables.spec.ts" + // Otherwise, we cannot test locally maps that are... not local. + return false; + } + const urlObj = new URL(url); if (urlObj.hostname === "localhost" || urlObj.hostname.endsWith(".localhost")) { return true; diff --git a/tests/tests/variables.spec.ts b/tests/tests/variables.spec.ts index 4b6c1f13..a652a247 100644 --- a/tests/tests/variables.spec.ts +++ b/tests/tests/variables.spec.ts @@ -142,6 +142,9 @@ test.describe('Variables', () => { await login(page, 'Alice', 2); + // Wait for page to load before copying file (it seems the await above does not 100% fills its role otherwise). + await timeout(3000); + // Let's REPLACE the map by a map that has a new variable // At this point, the back server contains a cache of the old map (with no variables) fs.copyFileSync( @@ -162,3 +165,8 @@ test.describe('Variables', () => { await assertLogMessage(page2, 'SUCCESS!'); }); }); + + +function timeout(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +}