import { dirname, join } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { describe, expect, it, vi } from "vitest"; function sharedHighlighterUrl(tag: string) { const diffsEntry = fileURLToPath(import.meta.resolve("@pierre/diffs")); return `${pathToFileURL(join(dirname(diffsEntry), "highlighter/shared_highlighter.js")).href}?${tag}`; } describe("@pierre/diffs theme registration", () => { it("does not log duplicate Pierre built-in themes when highlighter module is reloaded", async () => { const error = vi.spyOn(console, "error").mockImplementation(() => {}); let duplicateLogs: unknown[][] = []; try { await import(sharedHighlighterUrl("first")); await import(sharedHighlighterUrl("second")); duplicateLogs = error.mock.calls.filter( (call) => call[0] === "SharedHighlight.registerCustomTheme: theme name already registered", ); } finally { error.mockRestore(); } expect(duplicateLogs).toEqual([]); }); });