From 6e8cdd7d59b548fcd3f11a20024254f2e7a22478 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 3 May 2026 22:59:10 -0700 Subject: [PATCH] test(plugin): harden source loader fallback tests --- src/channels/plugins/module-loader.test.ts | 4 ++-- src/plugin-sdk/channel-entry-contract.test.ts | 15 +++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/channels/plugins/module-loader.test.ts b/src/channels/plugins/module-loader.test.ts index e9a9b0cca90..67876b8848d 100644 --- a/src/channels/plugins/module-loader.test.ts +++ b/src/channels/plugins/module-loader.test.ts @@ -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( diff --git a/src/plugin-sdk/channel-entry-contract.test.ts b/src/plugin-sdk/channel-entry-contract.test.ts index ecea63e15b6..3521011cb2b 100644 --- a/src/plugin-sdk/channel-entry-contract.test.ts +++ b/src/plugin-sdk/channel-entry-contract.test.ts @@ -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(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(); }