Skip to content

Wait for map and image loads in tests - #58

Merged
johanrd merged 1 commit into
mainfrom
test-waiters
Sep 22, 2026
Merged

johanrd merged 1 commit into
mainfrom
test-waiters

Conversation

@johanrd

@johanrd johanrd commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Registers test waiters, so await render() and await visit() return after the map has fired load, and after images loaded by <map.image> are on the map. Tests no longer need waitUntil for either — 69 such calls are removed from this suite, and 4 are kept where a test deliberately holds a load open.

@ember/test-waiters and @embroider/macros move from devDependencies to dependencies. The waiters, and the timers below, exist only in test and development builds.

A wait ends when:

  • the map fires load, or the image is added
  • the map cannot load: its constructor throws (no WebGL), or an error arrives before the style has loaded
  • a newer image load replaces one still in flight
  • the component is destroyed
  • 10 seconds pass, which warns in the console, since settled() then continues as if the work had finished

The last three matter. Without them, one request that never answers holds settled() open for the rest of the suite. The addon's own tests stub loadImage with a promise that never resolves, and hung exactly that way while this was built.

The waiters cover the map's load event and <map.image>. Sources, layers, markers and popups act on the map while the block renders, so await render() already covers them too. Anything after that — a popup opened by a marker click, setStyle, tile loading — is still yours to wait for.

New tests cover the map load, a style that 404s, a tile error after the style has loaded, destroying a map before it loads, and raster plus SVG images being on the map when render() returns.

Also fixed

A reused map (@reuseMaps) that was pooled while its tiles were still loading never rendered its block on remount. The code waited for style.load, which MapLibre fires only when it parses a style, never again for one it has already parsed. The pool only accepts maps whose style has loaded, so the remount now signals load directly. A test covers it — before this PR the bug was a silent hang, so the new wait would only have turned it into a 10-second one.

For apps

  • A stub passed to @mapLib must fire load, or each test waits 10 seconds.
  • A map with a slow remote style now makes render() and visit() wait for it.

No component API changes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It changes production map/image load-lifecycle behavior and reworks settled()-dependent test semantics across seven files plus a runtime dependency promotion, which warrants human verification even though no defects were found.

Review effort: Balanced
Findings: None

What changed in this PR

This PR improves test-waiter hygiene so that await render()/await settled() reliably wait for a map (and <map.image> images) to finish loading, removing the many manual waitUntil(() => find(...)) calls scattered across the integration tests. It introduces a small beginWait helper that opens an @ember/test-waiters token with a 10s safety timeout, wires it into the maplibre-gl and maplibre-gl-image components' load/error/destroy lifecycles, and moves @ember/test-waiters from devDependencies to dependencies since it is now imported by shipped source.

Changes:

  • Add src/-private/wait.ts (beginWait) and register map-load/image-load waiters in the map and image components, ending them on load, style failure, construction failure, replacement, or destroy.
  • Remove now-unnecessary waitUntil calls across seven integration test files and add dedicated waiter tests plus a data-URL raster/SVG image test.
  • Promote @ember/test-waiters to a runtime dependency and document the testing behavior in docs/components/map.md.
File Description
src/​-private/​wait.ts New idempotent beginWait helper with a 10s timeout safety net.
src/​components/​maplibre-gl.gts Begin/end map-load waiter across load, style-failure error, WebGL construction failure, and destructor.
src/​components/​maplibre-gl-image.gts Begin/end image-load waiter for SVG and raster paths, replacement loads, and destructor.
package.json Move @ember/test-waiters from devDependencies to dependencies.
pnpm-lock.yaml Reflect the dependency section move.
docs/​components/​map.md Add a Testing section describing the waiter behavior.
tests/​integration/​components/​maplibre-gl-test.gts Drop waitUntil; add nested test waiter suite with a ManualMap stub.
tests/​integration/​components/​maplibre-gl-image-test.gts Drop waitUntil, add data-URL image test, and rework stale-load tests around the waiter.
tests/​integration/​components/​maplibre-gl-source-test.gts Remove waitUntil/find import churn now covered by the waiter.
tests/​integration/​components/​maplibre-gl-layer-test.gts Remove waitUntil calls now covered by the waiter.
tests/​integration/​components/​maplibre-gl-marker-test.gts Remove waitUntil (including marker-count polling) now covered by the waiter.
tests/​integration/​components/​maplibre-gl-popup-test.gts Remove waitUntil calls now covered by the waiter.
tests/​integration/​components/​maplibre-gl-control-test.gts Remove waitUntil calls now covered by the waiter.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@johanrd johanrd changed the title test waiter hygiene Wait for map and image loads in tests Sep 22, 2026
@johanrd johanrd added the enhancement New feature or request label Sep 22, 2026
@johanrd
johanrd force-pushed the test-waiters branch 2 times, most recently from 82235a7 to 8f3e37d Compare September 22, 2026 09:48
@johanrd
johanrd merged commit 6433469 into main Sep 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants