favicon.test.ts

1.2 KB · raw

1import { afterEach, describe, expect, it } from "vitest";23import { faviconUrl } from "./favicon";45describe("shared favicon", () => {6  afterEach(() => {7    delete (globalThis as { chrome?: typeof chrome }).chrome;8  });910  it("faviconUrl returns a chrome-extension favicon URL when runtime.getURL exists", () => {11    (globalThis as { chrome?: typeof chrome }).chrome = {12      runtime: {13        getURL: (path: string) => `chrome-extension://peach${path}`,14      },15    } as unknown as typeof chrome;1617    const url = faviconUrl("github.com");1819    expect(url).toContain("chrome-extension://peach/_favicon/");20    expect(url).toContain("pageUrl=https%3A%2F%2Fgithub.com");21    expect(url).toContain("size=32");22  });2324  it("faviconUrl returns null when the runtime API is unavailable", () => {25    expect(faviconUrl("github.com")).toBeNull();26  });2728  it("faviconUrl never returns an external URL", () => {29    (globalThis as { chrome?: typeof chrome }).chrome = {30      runtime: {31        getURL: (path: string) => `chrome-extension://peach${path}`,32      },33    } as unknown as typeof chrome;3435    const url = faviconUrl("github.com");3637    expect(url).not.toContain("http://");38    expect(url?.startsWith("chrome-extension://")).toBe(true);39  });40});