one
Version:
One is a new React Framework that makes Vite serve both native and web.
91 lines (90 loc) • 2.85 kB
JavaScript
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import path from "path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("vite", async function () {
var actual = await vi.importActual("vite");
return {
...actual,
createServerModuleRunner: vi.fn(function () {
return {
clearCache: vi.fn(),
import: vi.fn()
};
})
};
});
describe("createFileSystemRouterPlugin", function () {
var previousIsVxrnCli = process.env.IS_VXRN_CLI;
var previousVxrnPluginConfig;
var tempRoot;
beforeEach(function () {
previousVxrnPluginConfig = globalThis.__vxrnPluginConfig__;
});
afterEach(function () {
if (tempRoot) {
rmSync(tempRoot, {
recursive: true,
force: true
});
tempRoot = void 0;
}
if (previousIsVxrnCli === void 0) {
delete process.env.IS_VXRN_CLI;
} else {
process.env.IS_VXRN_CLI = previousIsVxrnCli;
}
if (previousVxrnPluginConfig === void 0) {
delete globalThis.__vxrnPluginConfig__;
} else {
;
globalThis.__vxrnPluginConfig__ = previousVxrnPluginConfig;
}
vi.restoreAllMocks();
});
it("keeps route watcher rebuild errors handled", async function () {
process.env.IS_VXRN_CLI = "1";
tempRoot = mkdtempSync(path.join(tmpdir(), "one-router-watch-"));
var appDir = path.join(tempRoot, "app");
writeFileSync(path.join(tempRoot, "package.json"), "{}\n");
mkdirSync(appDir);
writeFileSync(path.join(appDir, "index.tsx"), "export default function Index() { return null }\n");
globalThis.__vxrnPluginConfig__ = {
web: {
defaultRenderMode: "ssg"
}
};
var {
createFileSystemRouterPlugin
} = await import("./fileSystemRouterPlugin.native.js");
var plugin = createFileSystemRouterPlugin({
router: {
root: appDir
}
});
var watcherListener;
var server = {
environments: {
ssr: {}
},
watcher: {
addListener: vi.fn(function (event, listener) {
if (event === "all") {
watcherListener = listener;
}
}),
on: vi.fn()
}
};
plugin.configureServer(server);
expect(watcherListener).toBeDefined();
var warn = vi.spyOn(console, "warn").mockImplementation(function () {});
delete globalThis.__vxrnPluginConfig__;
if (!watcherListener) {
throw new Error("Expected route watcher listener to be registered");
}
await expect(Promise.resolve(watcherListener("add", path.join(appDir, "new-route.tsx")))).resolves.toBeUndefined();
expect(warn).toHaveBeenCalledWith(expect.stringContaining("[one] Failed to rebuild routes"), expect.any(Error));
});
});
//# sourceMappingURL=fileSystemRouterPlugin.test.native.js.map