UNPKG

one

Version:

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

60 lines 3.28 kB
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"); var constants = __toESM(require("./constants.cjs"), 1); (0, import_vitest.describe)("CACHE_KEY pinning", () => { let originalKey; (0, import_vitest.beforeEach)(() => { originalKey = constants.CACHE_KEY; }); (0, import_vitest.afterEach)(() => { constants.setCacheKey(originalKey); }); (0, import_vitest.it)("setCacheKey rebinds CACHE_KEY-derived postfixes", () => { constants.setCacheKey("9999999"); (0, import_vitest.expect)(constants.CACHE_KEY).toBe("9999999"); (0, import_vitest.expect)(constants.PRELOAD_JS_POSTFIX).toBe("_9999999_preload.js"); (0, import_vitest.expect)(constants.CSS_PRELOAD_JS_POSTFIX).toBe("_9999999_preload_css.js"); (0, import_vitest.expect)(constants.LOADER_JS_POSTFIX).toBe(`_9999999${constants.LOADER_JS_POSTFIX_UNCACHED}`); }); (0, import_vitest.it)("setCacheKey is a no-op for empty or identical keys", () => { const before = constants.CACHE_KEY; constants.setCacheKey(""); (0, import_vitest.expect)(constants.CACHE_KEY).toBe(before); constants.setCacheKey(before); (0, import_vitest.expect)(constants.CACHE_KEY).toBe(before); }); (0, import_vitest.it)("PRELOAD_JS_POSTFIX_REGEX matches the literal postfix shape with any digits", () => { constants.setCacheKey("12345"); (0, import_vitest.expect)(constants.PRELOAD_JS_POSTFIX_REGEX.test("/assets/foo_12345_preload.js")).toBe(true); (0, import_vitest.expect)(constants.PRELOAD_JS_POSTFIX_REGEX.test("/assets/foo_98765_preload.js")).toBe(true); (0, import_vitest.expect)(constants.PRELOAD_JS_POSTFIX_REGEX.test("/assets/foo_preload.js")).toBe(false); (0, import_vitest.expect)(constants.PRELOAD_JS_POSTFIX_REGEX.test("/assets/foo_12345_preload_css.js")).toBe(false); }); (0, import_vitest.it)("CSS_PRELOAD_JS_POSTFIX_REGEX matches only the css variant", () => { (0, import_vitest.expect)(constants.CSS_PRELOAD_JS_POSTFIX_REGEX.test("/assets/foo_12345_preload_css.js")).toBe(true); (0, import_vitest.expect)(constants.CSS_PRELOAD_JS_POSTFIX_REGEX.test("/assets/foo_12345_preload.js")).toBe(false); }); });