mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
Chrome windows cache workaround (#454)
js 3.1.0 * Disable browser caching on chrome on windows [#442] * work around for chromium issue: https://issues.chromium.org/issues/40542704
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import fs from "fs";
|
||||
import assert from "node:assert";
|
||||
import { test } from "node:test";
|
||||
import { afterEach, beforeEach, describe, it, test } from "node:test";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
class MockServer {
|
||||
etag?: string;
|
||||
numRequests: number;
|
||||
lastCache?: string;
|
||||
|
||||
reset() {
|
||||
this.numRequests = 0;
|
||||
@@ -37,6 +38,7 @@ class MockServer {
|
||||
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) {
|
||||
@@ -415,3 +417,21 @@ test("pmtiles get TileJSON", async () => {
|
||||
assert.equal("test_fixture_1.pmtiles", tilejson.name);
|
||||
assert.equal("2", tilejson.version);
|
||||
});
|
||||
|
||||
describe("user agent", async () => {
|
||||
beforeEach(() => {
|
||||
// @ts-ignore
|
||||
global.navigator = { userAgent: "Windows Chrome" };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// @ts-ignore
|
||||
global.navigator.userAgent = undefined;
|
||||
});
|
||||
|
||||
it("works around caching bug on chrome on windows", async () => {
|
||||
const p = new PMTiles("http://localhost:1337/example.pmtiles");
|
||||
await p.getZxy(0, 0, 0);
|
||||
assert.equal("no-store", mockserver.lastCache);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user