From cbe3eb6d453c12d51280c92e3227e8be75de7b61 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 30 Aug 2023 12:36:46 +0200 Subject: [PATCH 1/3] fix(test-functional): fixes on hooks_functional.js --- test/hooks_functional.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/hooks_functional.js b/test/hooks_functional.js index 3d4340dd92..0593af6fa4 100644 --- a/test/hooks_functional.js +++ b/test/hooks_functional.js @@ -117,7 +117,7 @@ const loadExample = async (url, screenshotName) => { pageErrors.forEach((e) => { throw e; }); - await page.waitForFunction(() => typeof (view) === 'object'); + await page.waitForFunction(() => typeof view === 'object' && view instanceof itowns.View); await page.evaluate(() => { itowns.CameraUtils.defaultStopPlaceOnGroundAtEnd = true; @@ -131,6 +131,8 @@ const loadExample = async (url, screenshotName) => { itowns.CameraUtils.stop(view, view.camera3D); }); await layersAreInitialized(); + } else { + throw e; } } @@ -206,7 +208,7 @@ export const mochaHooks = { }); // the page all tests will be tested in - return browser.newPage().then((p) => { global.page = p; }); + global.page = await browser.newPage(); }, // store initial position for restoration after the test afterAll(done) { From 5a6d0b71f21a036c7cc592fce94818fe4c6433d3 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 30 Aug 2023 17:24:28 +0200 Subject: [PATCH 2/3] refactor(test-functional): reworks on hooks-functional.js: better gestion of errors and save initial camera position only once --- test/hooks_functional.js | 64 ++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/test/hooks_functional.js b/test/hooks_functional.js index 0593af6fa4..4b8e335822 100644 --- a/test/hooks_functional.js +++ b/test/hooks_functional.js @@ -16,6 +16,8 @@ import events from 'events'; events.EventEmitter.prototype._maxListeners = 100; +const TIMEOUT = 50000; + let itownsServer; let itownsPort; let browser; @@ -23,6 +25,7 @@ let browser; // but it's slow to start (so tests might fail on timeouts). // Since the 'test-examples' target depends on the 'run' target, // we instead run the simplest http server. + function startStaticFileServer() { return new Promise((resolve) => { const ext2mime = new Map(); @@ -79,10 +82,14 @@ function waitServerReady(port) { }); } -const layersAreInitialized = async () => { - await page.waitForFunction(() => view.mainLoop.scheduler.commandsWaitingExecutionCount() === 0 - && view.mainLoop.renderingState === 0 - && view.getLayers().every(layer => layer.ready), { timeout: 60000 }); +const initializeLayers = async (timeout = TIMEOUT) => { + await page.waitForFunction( + () => (view.mainLoop.scheduler.commandsWaitingExecutionCount() === 0 + && view.mainLoop.renderingState === 0 + && view.getLayers().every(layer => layer.ready)), + { timeout }, + timeout, + ); }; const waitNextRender = async page => page.evaluate(() => new Promise((resolve) => { @@ -113,9 +120,16 @@ const loadExample = async (url, screenshotName) => { const pageErrors = []; page.on('pageerror', (e) => { pageErrors.push(e); }); - await page.goto(url); + try { + await page.goto(url); + } catch (e) { + throw new Error(`page ${url} couldn't load`, { cause: e }); + } - pageErrors.forEach((e) => { throw e; }); + if (pageErrors.length > 0) { + const err = new Error(`page ${url} encoutered ${pageErrors.length} error(s). [${pageErrors.map(e => e.message)}]`, { errors: pageErrors }); + throw err; + } await page.waitForFunction(() => typeof view === 'object' && view instanceof itowns.View); @@ -124,14 +138,16 @@ const loadExample = async (url, screenshotName) => { }); try { - await layersAreInitialized(); + await initializeLayers(); } catch (e) { if (e instanceof Error && e.name === 'TimeoutError') { + console.warn(' *** Warning: initializeLayers timed out -> Camera motion had been stopped ***'); await page.evaluate(() => { itowns.CameraUtils.stop(view, view.camera3D); }); - await layersAreInitialized(); + await initializeLayers(); } else { + console.warn(e); throw e; } } @@ -140,9 +156,24 @@ const loadExample = async (url, screenshotName) => { await saveScreenshot(page, screenshotName); + // store initial position for restoration after each tests + await saveInitialPosition(); + return true; }; +async function saveInitialPosition() { + global.initialPosition = await page.evaluate(() => { + if (view.isGlobeView && view.controls) { + return Promise.resolve(itowns.CameraUtils.getTransformCameraLookingAtTarget(view, view.controls.camera)); + } else if (view.isPlanarView) { + // TODO: make the controls accessible from PlanarView before doing + // anything more here + return Promise.resolve(); + } + }); +} + // Use waitUntilItownsIsIdle to wait until itowns has finished all its work (= layer updates) const waitUntilItownsIsIdle = async (screenshotName) => { const result = await page.evaluate(() => new Promise((resolve) => { @@ -210,7 +241,7 @@ export const mochaHooks = { // the page all tests will be tested in global.page = await browser.newPage(); }, - // store initial position for restoration after the test + afterAll(done) { browser.close(); if (itownsServer) { @@ -220,21 +251,10 @@ export const mochaHooks = { done(); } }, - beforeEach: async () => { - global.initialPosition = await page.evaluate(() => { - if (view.isGlobeView && view.controls) { - return Promise.resolve(itowns.CameraUtils.getTransformCameraLookingAtTarget(view, view.controls.camera)); - } else if (view.isPlanarView) { - // TODO: make the controls accessible from PlanarView before doing - // anything more here - return Promise.resolve(); - } - }); - }, // reset browser state instead of closing it afterEach: async () => { await page.evaluate((init) => { - if (view.isGlobeView && view.controls) { + if (view?.isGlobeView && view.controls) { // eslint-disable-next-line no-param-reassign init.coord = new itowns.Coordinates( init.coord.crs, @@ -244,7 +264,7 @@ export const mochaHooks = { ); view.controls.lookAtCoordinate(init, false); view.notifyChange(); - } else if (view.isPlanarView) { + } else if (view?.isPlanarView) { // TODO: make the controls accessible from PlanarView before doing // anything more here } From 9c101a94f63232a804518fbe16d819095bbad018 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Fri, 3 May 2024 14:20:25 +0200 Subject: [PATCH 3/3] fix(example): change klokantech url in 3dtile_ion.html --- examples/layers/JSONLayers/OPENSM.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/layers/JSONLayers/OPENSM.json b/examples/layers/JSONLayers/OPENSM.json index d9377913c3..bd05e500b8 100644 --- a/examples/layers/JSONLayers/OPENSM.json +++ b/examples/layers/JSONLayers/OPENSM.json @@ -4,7 +4,7 @@ "crs": "EPSG:3857", "isInverted": true, "format": "image/png", - "url": "http://osm.oslandia.io/styles/klokantech-basic/${z}/${x}/${y}.png", + "url": "https://maps.pole-emploi.fr/styles/klokantech-basic/${z}/${x}/${y}.png", "attribution": { "name":"OpenStreetMap", "url": "http://www.openstreetmap.org/"