mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:30:42 +00:00
test(plugin): harden source loader fallback tests
This commit is contained in:
@@ -82,7 +82,7 @@ describe("channel plugin module loader helpers", () => {
|
||||
expect(createJiti).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("loads TypeScript channel plugin modules through Jiti when no native hook exists", async () => {
|
||||
it("loads TypeScript channel plugin modules through Jiti when native loading is unavailable", async () => {
|
||||
const loadWithJiti = vi.fn((target: string) => ({
|
||||
loadedBy: "jiti",
|
||||
target,
|
||||
@@ -103,7 +103,7 @@ describe("channel plugin module loader helpers", () => {
|
||||
const rootDir = createTempDir();
|
||||
const modulePath = path.join(rootDir, "extensions", "demo", "index.ts");
|
||||
fs.mkdirSync(path.dirname(modulePath), { recursive: true });
|
||||
fs.writeFileSync(modulePath, "export const ok = true;\n", "utf8");
|
||||
fs.writeFileSync(modulePath, 'throw new Error("native source load failed");\n', "utf8");
|
||||
|
||||
try {
|
||||
expect(
|
||||
|
||||
@@ -285,7 +285,7 @@ describe("loadBundledEntryExportSync", () => {
|
||||
});
|
||||
|
||||
it("keeps Windows dist sidecar loads off source-transform loading", async () => {
|
||||
const createJiti = vi.fn(() => vi.fn(() => ({ load: 42 })));
|
||||
const createJiti = vi.fn(() => vi.fn(() => ({ load: 0 })));
|
||||
stubPluginModuleLoaderJitiFactory(createJiti as unknown as PluginModuleLoaderFactory);
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
|
||||
@@ -300,22 +300,17 @@ describe("loadBundledEntryExportSync", () => {
|
||||
fs.mkdirSync(pluginRoot, { recursive: true });
|
||||
|
||||
const importerPath = path.join(pluginRoot, "index.js");
|
||||
const helperPath = path.join(pluginRoot, "helper.ts");
|
||||
const helperPath = path.join(pluginRoot, "helper.cjs");
|
||||
fs.writeFileSync(importerPath, "export default {};\n", "utf8");
|
||||
fs.writeFileSync(helperPath, "export const load = 42;\n", "utf8");
|
||||
fs.writeFileSync(helperPath, "module.exports = { load: 42 };\n", "utf8");
|
||||
|
||||
expect(
|
||||
channelEntryContract.loadBundledEntryExportSync<number>(pathToFileURL(importerPath).href, {
|
||||
specifier: "./helper.ts",
|
||||
specifier: "./helper.cjs",
|
||||
exportName: "load",
|
||||
}),
|
||||
).toBe(42);
|
||||
expect(createJiti).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.objectContaining({
|
||||
tryNative: false,
|
||||
}),
|
||||
);
|
||||
expect(createJiti).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user