one
Version:
One is a new React Framework that makes Vite serve both native and web.
60 lines (59 loc) • 2.01 kB
JavaScript
import { afterEach, describe, expect, it, vi } from "vitest";
import { hmrImport } from "./hmrImport.native.native.js";
var realRuntime = globalThis.__rolldown_runtime__;
afterEach(function () {
;
globalThis.__rolldown_runtime__ = realRuntime;
vi.restoreAllMocks();
});
var setRuntime = function (runtime) {
;
globalThis.__rolldown_runtime__ = runtime;
};
describe("hmrImport (native)", function () {
it("rejects when no runtime is present", async function () {
setRuntime(void 0);
await expect(hmrImport("foo.tsx")).rejects.toThrow("HMR import not supported on native");
});
it("rejects when loadExports is missing", async function () {
setRuntime({});
await expect(hmrImport("foo.tsx")).rejects.toThrow("HMR import not supported on native");
});
it("resolves with the runtime exports and strips ./ and / prefixes", async function () {
var exports = {
default: function () {
return null;
}
};
var loadExports = vi.fn(function () {
return exports;
});
setRuntime({
loadExports
});
await expect(hmrImport("./foo.tsx")).resolves.toBe(exports);
await expect(hmrImport("/foo.tsx")).resolves.toBe(exports);
await expect(hmrImport("foo.tsx")).resolves.toBe(exports);
expect(loadExports).toHaveBeenNthCalledWith(1, "foo.tsx");
expect(loadExports).toHaveBeenNthCalledWith(2, "foo.tsx");
expect(loadExports).toHaveBeenNthCalledWith(3, "foo.tsx");
});
it("rejects when loadExports returns null", async function () {
setRuntime({
loadExports: function () {
return null;
}
});
await expect(hmrImport("foo.tsx")).rejects.toThrow("no exports for foo.tsx");
});
it("rejects when loadExports throws", async function () {
var boom = new Error("boom");
setRuntime({
loadExports: function () {
throw boom;
}
});
await expect(hmrImport("foo.tsx")).rejects.toBe(boom);
});
});
//# sourceMappingURL=hmrImport.native.test.native.js.map