import { afterEach, describe, expect, it } from "vitest"; import { faviconUrl } from "./favicon"; describe("shared favicon", () => { afterEach(() => { delete (globalThis as { chrome?: typeof chrome }).chrome; }); it("faviconUrl returns a chrome-extension favicon URL when runtime.getURL exists", () => { (globalThis as { chrome?: typeof chrome }).chrome = { runtime: { getURL: (path: string) => `chrome-extension://peach${path}`, }, } as unknown as typeof chrome; const url = faviconUrl("github.com"); expect(url).toContain("chrome-extension://peach/_favicon/"); expect(url).toContain("pageUrl=https%3A%2F%2Fgithub.com"); expect(url).toContain("size=32"); }); it("faviconUrl returns null when the runtime API is unavailable", () => { expect(faviconUrl("github.com")).toBeNull(); }); it("faviconUrl never returns an external URL", () => { (globalThis as { chrome?: typeof chrome }).chrome = { runtime: { getURL: (path: string) => `chrome-extension://peach${path}`, }, } as unknown as typeof chrome; const url = faviconUrl("github.com"); expect(url).not.toContain("http://"); expect(url?.startsWith("chrome-extension://")).toBe(true); }); });