one
Version:
One is a new React Framework that makes Vite serve both native and web.
44 lines (43 loc) • 1.42 kB
JavaScript
import { afterEach, describe, expect, it, vi } from "vitest";
import { globbedRoutesToRouteContext } from "./useViteRoutes.mjs";
const mocks = vi.hoisted(() => ({
hmrImport: vi.fn()
}));
vi.mock("./hmrImport", () => ({
hmrImport: mocks.hmrImport
}));
const realWindow = globalThis.window;
afterEach(() => {
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", () => {
it("evicts and reloads a route under a custom router root", async () => {
vi.stubEnv("NODE_ENV", "development");
globalThis.window = {};
const initialRoute = {
default: () => "initial"
};
const updatedRoute = {
default: () => "updated"
};
const context = globbedRoutesToRouteContext({
"/routes/index.tsx": () => 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.mjs.map