one
Version:
One is a new React Framework that makes Vite serve both native and web.
83 lines • 3.76 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var import_vitest = require("vitest");
(0, import_vitest.describe)("routeHmr.native", () => {
let routeHmr;
const realWindow = globalThis.window;
const realModuleUpdatedHook = globalThis.__VXRN_ON_MODULE_UPDATED__;
(0, import_vitest.beforeEach)(async () => {
import_vitest.vi.stubEnv("NODE_ENV", "development");
import_vitest.vi.resetModules();
routeHmr = await import("./routeHmr.native");
});
(0, import_vitest.afterEach)(() => {
import_vitest.vi.unstubAllEnvs();
globalThis.__VXRN_ON_MODULE_UPDATED__ = realModuleUpdatedHook;
globalThis.window = realWindow;
});
(0, import_vitest.it)("registers globalThis.__VXRN_ON_MODULE_UPDATED__ in development", () => {
(0, import_vitest.expect)(typeof globalThis.__VXRN_ON_MODULE_UPDATED__).toBe("function");
});
(0, import_vitest.it)("bumps the epoch and notifies subscribers, and stops after unsubscribe", () => {
const before = routeHmr.getRouteHmrEpoch();
const listener = import_vitest.vi.fn();
const unsubscribe = routeHmr.subscribeRouteHmr(listener);
globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx");
(0, import_vitest.expect)(routeHmr.getRouteHmrEpoch()).toBe(before + 1);
(0, import_vitest.expect)(listener).toHaveBeenCalledTimes(1);
unsubscribe();
globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx");
(0, import_vitest.expect)(listener).toHaveBeenCalledTimes(1);
});
(0, import_vitest.it)("evicts the route cache for the updated file when window.__oneRouteCache is present", () => {
const clearFile = import_vitest.vi.fn();
globalThis.window = {
__oneRouteCache: {
clearFile
}
};
globalThis.__VXRN_ON_MODULE_UPDATED__("app/_layout.tsx");
(0, import_vitest.expect)(clearFile).toHaveBeenCalledWith("app/_layout.tsx");
});
(0, import_vitest.it)("does not throw when window / route cache is absent", () => {
;
globalThis.window = void 0;
(0, import_vitest.expect)(() => globalThis.__VXRN_ON_MODULE_UPDATED__("x.tsx")).not.toThrow();
});
(0, import_vitest.it)("still notifies subscribers when route-cache eviction throws", () => {
const listener = import_vitest.vi.fn();
const unsubscribe = routeHmr.subscribeRouteHmr(listener);
globalThis.window = {
__oneRouteCache: {
clearFile() {
throw new Error("cache eviction failed");
}
}
};
(0, import_vitest.expect)(() => globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx")).toThrow("cache eviction failed");
(0, import_vitest.expect)(listener).toHaveBeenCalledOnce();
unsubscribe();
});
});