From 156f6a81e91d40d05ace29438f6c46af9b102b38 Mon Sep 17 00:00:00 2001 From: Kyle Hensel Date: Mon, 9 Sep 2024 20:20:12 +1000 Subject: [PATCH] enable `--no-isolate` to speed up unit tests This required fixing deferred code that was running after the unit test had unmounted --- modules/renderer/map.js | 3 +++ modules/util/session_mutex.js | 3 +++ test/spec/services/panoramax.js | 3 +++ 3 files changed, 9 insertions(+) diff --git a/modules/renderer/map.js b/modules/renderer/map.js index 0e5a7127cb..a288aef41b 100644 --- a/modules/renderer/map.js +++ b/modules/renderer/map.js @@ -653,6 +653,9 @@ export function rendererMap(context) { function redraw(difference, extent) { + // in unit tests, we need to abort if the test has already completed + if (typeof window === 'undefined') return; + if (surface.empty() || !_redrawEnabled) return; // If we are in the middle of a zoom/pan, we can't do differenced redraws. diff --git a/modules/util/session_mutex.js b/modules/util/session_mutex.js index 99fdc94d93..42b61edcad 100644 --- a/modules/util/session_mutex.js +++ b/modules/util/session_mutex.js @@ -8,6 +8,9 @@ export function utilSessionMutex(name) { var intervalID; function renew() { + // in unit tests, we need to abort if the test has already completed + if (typeof window === 'undefined') return; + var expires = new Date(); expires.setSeconds(expires.getSeconds() + 5); document.cookie = name + '=1; expires=' + expires.toUTCString() + '; sameSite=strict'; diff --git a/test/spec/services/panoramax.js b/test/spec/services/panoramax.js index e418509046..c695754518 100644 --- a/test/spec/services/panoramax.js +++ b/test/spec/services/panoramax.js @@ -21,6 +21,9 @@ describe('iD.servicePanoramax', function() { panoramax = iD.services.panoramax; panoramax.reset(); fetchMock.reset(); + + // never resolve + fetchMock.mock(/api\.panoramax\.xyz/, new Promise(() => {})); }); afterEach(function() {