one
Version:
One is a new React Framework that makes Vite serve both native and web.
96 lines (93 loc) • 4.08 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");
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
(0, import_vitest.describe)("routeHmr.native", function () {
var routeHmr;
var realWindow = globalThis.window;
var realModuleUpdatedHook = globalThis.__VXRN_ON_MODULE_UPDATED__;
(0, import_vitest.beforeEach)(async function () {
import_vitest.vi.stubEnv("NODE_ENV", "development");
import_vitest.vi.resetModules();
routeHmr = await import("./routeHmr.native");
});
(0, import_vitest.afterEach)(function () {
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", function () {
(0, import_vitest.expect)(_type_of(globalThis.__VXRN_ON_MODULE_UPDATED__)).toBe("function");
});
(0, import_vitest.it)("bumps the epoch and notifies subscribers, and stops after unsubscribe", function () {
var before = routeHmr.getRouteHmrEpoch();
var listener = import_vitest.vi.fn();
var 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", function () {
var 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", function () {
;
globalThis.window = void 0;
(0, import_vitest.expect)(function () {
return globalThis.__VXRN_ON_MODULE_UPDATED__("x.tsx");
}).not.toThrow();
});
(0, import_vitest.it)("still notifies subscribers when route-cache eviction throws", function () {
var listener = import_vitest.vi.fn();
var unsubscribe = routeHmr.subscribeRouteHmr(listener);
globalThis.window = {
__oneRouteCache: {
clearFile() {
throw new Error("cache eviction failed");
}
}
};
(0, import_vitest.expect)(function () {
return globalThis.__VXRN_ON_MODULE_UPDATED__("app/index.tsx");
}).toThrow("cache eviction failed");
(0, import_vitest.expect)(listener).toHaveBeenCalledOnce();
unsubscribe();
});
});
//# sourceMappingURL=routeHmr.native.test.native.js.map