one
Version:
One is a new React Framework that makes Vite serve both native and web.
62 lines (60 loc) • 2.5 kB
JavaScript
;
var import_vitest = require("vitest");
var import_hmrImport = require("./hmrImport.native");
var realRuntime = globalThis.__rolldown_runtime__;
(0, import_vitest.afterEach)(function () {
;
globalThis.__rolldown_runtime__ = realRuntime;
import_vitest.vi.restoreAllMocks();
});
var setRuntime = function (runtime) {
;
globalThis.__rolldown_runtime__ = runtime;
};
(0, import_vitest.describe)("hmrImport (native)", function () {
(0, import_vitest.it)("rejects when no runtime is present", async function () {
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 function () {
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 function () {
var exports = {
default: function () {
return null;
}
};
var loadExports = import_vitest.vi.fn(function () {
return 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 function () {
setRuntime({
loadExports: function () {
return 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 function () {
var boom = new Error("boom");
setRuntime({
loadExports: function () {
throw boom;
}
});
await (0, import_vitest.expect)((0, import_hmrImport.hmrImport)("foo.tsx")).rejects.toBe(boom);
});
});
//# sourceMappingURL=hmrImport.native.test.native.js.map