UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

70 lines (68 loc) 2.57 kB
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } describe("routeHmr.native", function () { var routeHmr; var realWindow = globalThis.window; var realModuleUpdatedHook = globalThis.__VXRN_ON_MODULE_UPDATED__; beforeEach(async function () { vi.stubEnv("NODE_ENV", "development"); vi.resetModules(); routeHmr = await import("./routeHmr.native.native.js"); }); afterEach(function () { vi.unstubAllEnvs(); globalThis.__VXRN_ON_MODULE_UPDATED__ = realModuleUpdatedHook; globalThis.window = realWindow; }); it("registers globalThis.__VXRN_ON_MODULE_UPDATED__ in development", function () { expect(_type_of(globalThis.__VXRN_ON_MODULE_UPDATED__)).toBe("function"); }); it("bumps the epoch and notifies subscribers, and stops after unsubscribe", function () { var before = routeHmr.getRouteHmrEpoch(); var listener = vi.fn(); var unsubscribe = routeHmr.subscribeRouteHmr(listener); globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx"); expect(routeHmr.getRouteHmrEpoch()).toBe(before + 1); expect(listener).toHaveBeenCalledTimes(1); unsubscribe(); globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx"); expect(listener).toHaveBeenCalledTimes(1); }); it("evicts the route cache for the updated file when window.__oneRouteCache is present", function () { var clearFile = vi.fn(); globalThis.window = { __oneRouteCache: { clearFile } }; globalThis.__VXRN_ON_MODULE_UPDATED__("app/_layout.tsx"); expect(clearFile).toHaveBeenCalledWith("app/_layout.tsx"); }); it("does not throw when window / route cache is absent", function () { ; globalThis.window = void 0; expect(function () { return globalThis.__VXRN_ON_MODULE_UPDATED__("x.tsx"); }).not.toThrow(); }); it("still notifies subscribers when route-cache eviction throws", function () { var listener = vi.fn(); var unsubscribe = routeHmr.subscribeRouteHmr(listener); globalThis.window = { __oneRouteCache: { clearFile() { throw new Error("cache eviction failed"); } } }; expect(function () { return globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx"); }).toThrow("cache eviction failed"); expect(listener).toHaveBeenCalledOnce(); unsubscribe(); }); }); //# sourceMappingURL=routeHmr.native.test.native.js.map