test: guard channel loader jiti mock call

This commit is contained in:
Peter Steinberger
2026-05-12 05:15:49 +01:00
parent be233081e2
commit ff54363dd4
+12 -2
View File
@@ -26,6 +26,16 @@ function createTempDir(): string {
return tempDir;
}
function requireCreateJitiCall(
createJiti: ReturnType<typeof vi.fn>,
): [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) {