Skip to content

Commit

Permalink
refactor(4review): modif
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed May 6, 2024
1 parent b734c9a commit 4970f66
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions test/hooks_functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import events from 'events';

events.EventEmitter.prototype._maxListeners = 100;

const timeout = 50000;
const TIMEOUT = 50000;

let itownsServer;
let itownsPort;
Expand Down Expand Up @@ -82,11 +82,14 @@ function waitServerReady(port) {
});
}

const layersInitialization = async (forceTimeOut = false) => {
await page.waitForFunction(forceTimeOut => (view.mainLoop.scheduler.commandsWaitingExecutionCount() === 0
const initializeLayers = async (timeout = TIMEOUT) => {
await page.waitForFunction(
() => (view.mainLoop.scheduler.commandsWaitingExecutionCount() === 0
&& view.mainLoop.renderingState === 0
&& view.getLayers().every(layer => layer.ready)
&& !forceTimeOut), { timeout }, forceTimeOut);
&& view.getLayers().every(layer => layer.ready)),
{ timeout },
timeout,
);
};

const waitNextRender = async page => page.evaluate(() => new Promise((resolve) => {
Expand Down Expand Up @@ -135,19 +138,14 @@ const loadExample = async (url, screenshotName) => {
});

try {
await layersInitialization();
await initializeLayers();
} catch (e) {
if (e instanceof Error && e.name === 'TimeoutError') {
console.warn(' *** Warning: layersInitialization timed out -> it got stopped ***');
console.warn(' *** Warning: initializeLayers timed out -> Camera motion had been stopped ***');
await page.evaluate(() => {
itowns.CameraUtils.stop(view, view.camera3D);
});
try {
await layersInitialization();
} catch (e) {
console.warn(e);
throw e;
}
await initializeLayers();
} else {
console.warn(e);
throw e;
Expand Down

0 comments on commit 4970f66

Please sign in to comment.