| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { reloadFixes } from "./stale-build.ts"; |
| 5 | |
| 6 | test("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 | |
| 13 | test("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 | |
| 19 | test("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 | }); |