import { servicenowImageAssetPlugin } from "../../src/vite/image-asset"; type PluginRecord = Record; const applyConfig = (plugin: PluginRecord, config?: any) => { const c = config ?? {}; plugin.config(c, {} as any); return c; }; describe("servicenowImageAssetPlugin", () => { const plugin = () => servicenowImageAssetPlugin({ scope: "x_myapp" }) as PluginRecord; describe("config (renderBuiltUrl)", () => { test("rewrites image paths to scoped absolute URLs", () => { const config = applyConfig(plugin()); const result = config.experimental.renderBuiltUrl("assets/logo.svg", { hostType: "js", }); expect(result).toBe("/x_myapp/assets/logo.svg"); }); test("rewrites PNG paths", () => { const config = applyConfig(plugin()); const result = config.experimental.renderBuiltUrl("assets/icon.png", { hostType: "js", }); expect(result).toBe("/x_myapp/assets/icon.png"); }); test("rewrites image paths in CSS", () => { const config = applyConfig(plugin()); const result = config.experimental.renderBuiltUrl("assets/bg.jpg", { hostType: "css", }); expect(result).toBe("/x_myapp/assets/bg.jpg"); }); test("does not rewrite non-image assets", () => { const config = applyConfig(plugin()); const result = config.experimental.renderBuiltUrl("assets/data.json", { hostType: "js", }); expect(result).toEqual({ relative: true }); }); test("chains with existing renderBuiltUrl for non-images", () => { const existing = jest.fn().mockReturnValue("/custom/path"); const config = applyConfig(plugin(), { experimental: { renderBuiltUrl: existing }, }); const result = config.experimental.renderBuiltUrl("style.css", { hostType: "js", }); expect(existing).toHaveBeenCalledWith("style.css", { hostType: "js", }); expect(result).toBe("/custom/path"); }); }); });