Abort requests [#608] (#625)

* Properly abort requests using AbortController

* add basic adapter tests

---------

Co-authored-by: Andrew Dassonville <dassonville.andrew@gmail.com>
This commit is contained in:
Brandon Liu
2025-12-24 17:33:11 +08:00
committed by GitHub
parent a5f8a89256
commit cabe8a898a
6 changed files with 536 additions and 405 deletions

44
js/test/utils.ts Normal file
View File

@@ -0,0 +1,44 @@
import fs from "fs";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
class MockServer {
etag?: string;
numRequests: number;
lastCache?: string;
reset() {
this.numRequests = 0;
this.etag = undefined;
}
constructor() {
this.numRequests = 0;
this.etag = undefined;
const serverBuffer = fs.readFileSync("test/data/test_fixture_1.pmtiles");
const server = setupServer(
http.get(
"http://localhost:1337/example.pmtiles",
({ request, params }) => {
this.lastCache = request.cache;
this.numRequests++;
const range = request.headers.get("range")?.substr(6).split("-");
if (!range) {
throw new Error("invalid range");
}
const offset = +range[0];
const length = +range[1];
const body = serverBuffer.slice(offset, offset + length - 1);
return new HttpResponse(body, {
status: 206,
statusText: "OK",
headers: { etag: this.etag } as HeadersInit,
});
}
)
);
server.listen({ onUnhandledRequest: "error" });
}
}
export const mockServer = new MockServer();