UNPKG

one

Version:

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

54 lines (53 loc) 1.57 kB
import { afterEach, describe, expect, it, vi } from "vitest"; import { globbedRoutesToRouteContext } from "./useViteRoutes.native.js"; var mocks = vi.hoisted(function () { return { hmrImport: vi.fn() }; }); vi.mock("./hmrImport", function () { return { hmrImport: mocks.hmrImport }; }); var realWindow = globalThis.window; afterEach(function () { vi.unstubAllEnvs(); mocks.hmrImport.mockReset(); globalThis.window = realWindow; }); async function resolveRoute(context) { try { return context("./index.tsx"); } catch (pending) { await pending; return context("./index.tsx"); } } describe("globbedRoutesToRouteContext HMR", function () { it("evicts and reloads a route under a custom router root", async function () { vi.stubEnv("NODE_ENV", "development"); globalThis.window = {}; var initialRoute = { default: function () { return "initial"; } }; var updatedRoute = { default: function () { return "updated"; } }; var context = globbedRoutesToRouteContext({ "/routes/index.tsx": function () { return Promise.resolve(initialRoute); } }, "routes"); await expect(resolveRoute(context)).resolves.toBe(initialRoute); mocks.hmrImport.mockResolvedValue(updatedRoute); globalThis.window.__oneRouteCache.clearFile("routes/index.tsx"); await expect(resolveRoute(context)).resolves.toBe(updatedRoute); expect(mocks.hmrImport).toHaveBeenCalledWith("/routes/index.tsx"); }); }); //# sourceMappingURL=useViteRoutes.test.native.js.map