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:
Brandon Liu
2024-09-19 23:26:09 +08:00
committed by GitHub
parent 897d6f186e
commit ce959e50b0
7 changed files with 42 additions and 7 deletions

View File

@@ -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);
});
});