Skip to content

Replace jasmine-ajax with MSW and modernize test infrastructure - 1st pass#7767

Merged
zoran995 merged 7 commits intomainfrom
msw-poc
Mar 4, 2026
Merged

Replace jasmine-ajax with MSW and modernize test infrastructure - 1st pass#7767
zoran995 merged 7 commits intomainfrom
msw-poc

Conversation

@zoran995
Copy link
Collaborator

@zoran995 zoran995 commented Feb 17, 2026

What this PR does

Part of #7768

Introduces Mock Service Worker (MSW) as the HTTP mocking layer and migrates a first batch of specs from jasmine-ajax to MSW handlers.

  • Add MSW infrastructure (test/mocks/browser.ts, captureRequests.ts, terrain.ts) with global Cesium terrain handlers
  • Wire up MSW worker lifecycle in test/SpecMain.ts (start/resetHandlers/stop)
  • Migrate first batch of specs from jasmine.Ajax.stubRequest to worker.use(http.get(...))
  • Convert fetchMock usage to MSW for consistency

See #7766 - Add ADR for replacing jasmine-ajax with MSW for more details

Test me

Run the Karma test suite — all migrated specs should pass with MSW intercepting requests instead of jasmine-ajax.

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

@zoran995 zoran995 requested review from ljowen and na9da February 17, 2026 22:08
@zoran995
Copy link
Collaborator Author

zoran995 commented Feb 17, 2026

Deployment is failing as terriamap needs MSW as a dependency to build terriajs

@zoran995 zoran995 force-pushed the test-async-function branch from e1d6ae2 to f69e364 Compare February 24, 2026 08:54
@zoran995 zoran995 force-pushed the msw-poc branch 2 times, most recently from 200b0c0 to 6008b20 Compare February 27, 2026 08:05
Copy link
Contributor

@ljowen ljowen left a comment

Choose a reason for hiding this comment

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

Was able to run the tests locally :) , 2 minor comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to ensure this doesn't get bundled in production builds? I guess that belongs on the TerriaMap side: copy-terriajs-assets

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should, but we already copied the third_party directory, which is only used for testing. It might be better to look into this separately after we see if we can figure out how to bundle terriajs as a library and not depend on the TerriaMap build process.

@zoran995 zoran995 force-pushed the test-async-function branch from fe0dae4 to 68e0cd1 Compare March 2, 2026 09:12
@zoran995 zoran995 force-pushed the test-async-function branch 2 times, most recently from cc713e6 to 30f5eaa Compare March 2, 2026 09:23
Base automatically changed from test-async-function to main March 4, 2026 08:15
zoran995 added 7 commits March 4, 2026 09:15
Set up Mock Service Worker (msw) to intercept network requests at
the Service Worker level, enabling gradual migration away from
jasmine-ajax. Includes global Cesium Ion terrain handlers to prevent
unhandled rejections from terrain loading.
…x to MSW

Replace jasmine.Ajax.install/uninstall/stubRequest with MSW
worker.use(http.get(...)) handlers. Removes afterEach cleanup since
worker.resetHandlers() in SpecMain handles it globally.
@zoran995 zoran995 merged commit d7849b1 into main Mar 4, 2026
9 checks passed
@zoran995 zoran995 deleted the msw-poc branch March 4, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants