From ff54363dd43cc78ce88de63a74e8339fbb228b32 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 05:15:49 +0100 Subject: [PATCH] test: guard channel loader jiti mock call --- src/channels/plugins/module-loader.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/channels/plugins/module-loader.test.ts b/src/channels/plugins/module-loader.test.ts index 8bd5039062a0..28181bfff42e 100644 --- a/src/channels/plugins/module-loader.test.ts +++ b/src/channels/plugins/module-loader.test.ts @@ -26,6 +26,16 @@ function createTempDir(): string { return tempDir; } +function requireCreateJitiCall( + createJiti: ReturnType, +): [string, { tryNative?: boolean }] { + const call = createJiti.mock.calls.at(0); + if (!call) { + throw new Error("expected createJiti call"); + } + return call as [string, { tryNative?: boolean }]; +} + describe("channel plugin module loader helpers", () => { it("resolves extensionless plugin module specifiers to the first existing extension", () => { const rootDir = createTempDir(); @@ -102,9 +112,9 @@ describe("channel plugin module loader helpers", () => { target: fs.realpathSync.native(modulePath), }); expect(createJiti).toHaveBeenCalledOnce(); - const [loaderFilename, loaderOptions] = createJiti.mock.calls[0] ?? []; + const [loaderFilename, loaderOptions] = requireCreateJitiCall(createJiti); expect(loaderFilename).toContain("module-loader.ts"); - expect(loaderOptions?.tryNative).toBe(false); + expect(loaderOptions.tryNative).toBe(false); expect(loadWithJiti).toHaveBeenCalledWith(fs.realpathSync.native(modulePath)); } finally { for (const [extension, hook] of sourceHooks) {