From 108893c6242d9ee12dde300fae5d1dfa793709d6 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 +++ package.json | 2 +- test/spec/services/panoramax.js | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/renderer/map.js b/modules/renderer/map.js index 0e5a7127c..a288aef41 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 99fdc94d9..42b61edca 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/package.json b/package.json index 13f4cf024..b9e01621d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "start:watch": "run-p build:js:watch start:server", "start:server": "node scripts/server.js", "test": "npm-run-all -s lint build test:spec", - "test:spec": "vitest", + "test:spec": "vitest --no-isolate", "translations": "node scripts/update_locales.js" }, "dependencies": { diff --git a/test/spec/services/panoramax.js b/test/spec/services/panoramax.js index e41850904..c69575451 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() {