The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | vi.mock("./appInit", () => ({ startAppServices: () => ({ load: async () => {} }) })); |
| 4 | vi.mock("./AppRoot", () => ({ AppRoot: () => null })); |
| 5 | vi.mock("./i18n/runtime", () => ({ whenLocaleReady: async () => {} })); |
| 6 | vi.mock("react-dom/client", () => ({ default: { createRoot: () => ({ render: () => {} }) } })); |
| 7 | |
| 8 | // Boots main in a fresh page that shares the tab's sessionStorage, as a reload does. |
| 9 | async function bootThenFailLazyChunk(sessionStorage: Map<string, string>) { |
| 10 | vi.resetModules(); |
| 11 | const reload = vi.fn().mockName("location.reload"); |
| 12 | const page = Object.assign(new EventTarget(), { |
| 13 | sessionStorage: { |
| 14 | getItem: (key: string) => sessionStorage.get(key) ?? null, |
| 15 | setItem: (key: string, value: string) => sessionStorage.set(key, value), |
| 16 | removeItem: (key: string) => sessionStorage.delete(key), |
| 17 | }, |
| 18 | location: { reload }, |
| 19 | }); |
| 20 | vi.stubGlobal("window", page); |
| 21 | vi.stubGlobal("document", { getElementById: () => ({}) }); |
| 22 | try { |
| 23 | const { startup } = await import("./main"); |
| 24 | await startup; |
| 25 | page.dispatchEvent(new Event("vite:preloadError", { cancelable: true })); |
| 26 | return reload; |
| 27 | } finally { |
| 28 | vi.unstubAllGlobals(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | it("reloads only once when a lazy chunk fails after every boot", async () => { |
| 33 | const sessionStorage = new Map<string, string>(); |
| 34 | |
| 35 | expect(await bootThenFailLazyChunk(sessionStorage)).toHaveBeenCalledTimes(1); |
| 36 | expect(await bootThenFailLazyChunk(sessionStorage)).not.toHaveBeenCalled(); |
| 37 | }); |