digidem / mapeo-map-server

Offline map style and tile server
MIT License
5 stars 2 forks source link

chore: switch to nock from msw #50

Closed gmaclennan closed 2 years ago

gmaclennan commented 2 years ago

I came across an issue with msw that for passthrough requests, http headers are stripped. There is some mention of it being fixed in the latest release, but latest msw now only support Node 16, which is a bit premature given that Node 14 is still LTS, and ideally we need Node 12 support too until we get nodejs-mobile updated.

I found that nock is much more focussed on mocking for Node (as opposed to service workers) and works better for our use-case. I particularly like that we can block all requests apart from for localhost (simulating offline) and then selectively add mocks for where we expect them. In nock, mocks are only used once (unless you specify otherwise) so it helps our tests also catch unnecessary upstream requests that we might not be expecting.

In a follow up, once we support style.json with expanded sources (rather than a url prop which needs to be fetch upstream), then we can do most of the style tests without requiring nocking.

Also, I noticed during this that the errors we give when offline are not quite right (500 errors), so we should write more tests for offline use cases (in particular accessing tiles when offline)