Skip to content

g1t/apps/web/app/lib/stale-build.test.ts

24 lines1,623 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { reloadFixes } from "./stale-build.ts";
5
6test("a client navigation that hits an older build reloads the page", () => {
7 const seen = { clientNavigation: true, caughtByCatchAll: false };
8 assert.equal(reloadFixes({ ...seen, error: new Error("Unable to discover routes due to manifest version mismatch.") }), true);
9 assert.equal(reloadFixes({ ...seen, error: new TypeError("Failed to fetch dynamically imported module: https://g1t.sh/assets/pull-abc.js") }), true);
10 assert.equal(reloadFixes({ ...seen, error: new TypeError("Importing a module script failed.") }), true);
11});
12
13test("an address only the new build knows reloads, once it fell to the catch-all", () => {
14 assert.equal(reloadFixes({ error: {}, status: 404, clientNavigation: true, caughtByCatchAll: true }), true);
15 // A 404 a page threw itself (a missing issue) is a real one.
16 assert.equal(reloadFixes({ error: {}, status: 404, clientNavigation: true, caughtByCatchAll: false }), false);
17});
18
19test("a document load, or any other error, shows the error page", () => {
20 assert.equal(reloadFixes({ error: new Error("manifest version mismatch"), clientNavigation: false, caughtByCatchAll: false }), false);
21 assert.equal(reloadFixes({ error: {}, status: 404, clientNavigation: false, caughtByCatchAll: true }), false);
22 assert.equal(reloadFixes({ error: new Error("D1_ERROR: no such table"), clientNavigation: true, caughtByCatchAll: false }), false);
23 assert.equal(reloadFixes({ error: {}, status: 500, clientNavigation: true, caughtByCatchAll: false }), false);
24});