UNPKG

one

Version:

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

52 lines 2.29 kB
var import_vitest = require("vitest"); var import_hmrImport = require("./hmrImport.native"); const realRuntime = globalThis.__rolldown_runtime__; (0, import_vitest.afterEach)(() => { ; globalThis.__rolldown_runtime__ = realRuntime; import_vitest.vi.restoreAllMocks(); }); const setRuntime = runtime => { ; globalThis.__rolldown_runtime__ = runtime; }; (0, import_vitest.describe)("hmrImport (native)", () => { (0, import_vitest.it)("rejects when no runtime is present", async () => { setRuntime(void 0); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("foo.tsx")).rejects.toThrow("HMR import not supported on native"); }); (0, import_vitest.it)("rejects when loadExports is missing", async () => { setRuntime({}); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("foo.tsx")).rejects.toThrow("HMR import not supported on native"); }); (0, import_vitest.it)("resolves with the runtime exports and strips ./ and / prefixes", async () => { const exports = { default: () => null }; const loadExports = import_vitest.vi.fn(() => exports); setRuntime({ loadExports }); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("./foo.tsx")).resolves.toBe(exports); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("/foo.tsx")).resolves.toBe(exports); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("foo.tsx")).resolves.toBe(exports); (0, import_vitest.expect)(loadExports).toHaveBeenNthCalledWith(1, "foo.tsx"); (0, import_vitest.expect)(loadExports).toHaveBeenNthCalledWith(2, "foo.tsx"); (0, import_vitest.expect)(loadExports).toHaveBeenNthCalledWith(3, "foo.tsx"); }); (0, import_vitest.it)("rejects when loadExports returns null", async () => { setRuntime({ loadExports: () => null }); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("foo.tsx")).rejects.toThrow("no exports for foo.tsx"); }); (0, import_vitest.it)("rejects when loadExports throws", async () => { const boom = new Error("boom"); setRuntime({ loadExports: () => { throw boom; } }); await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("foo.tsx")).rejects.toBe(boom); }); });