


















@@ -1,11 +1,4 @@
1-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2-3-const cliHighlightMocks = vi.hoisted(() => ({
4-highlight: vi.fn((code: string) => code),
5-supportsLanguage: vi.fn((_lang: string) => true),
6-}));
7-8-vi.mock("cli-highlight", () => cliHighlightMocks);
1+import { afterEach, describe, expect, it, vi } from "vitest";
92103const { markdownTheme, searchableSelectListTheme, selectListTheme, theme } =
114await import("./theme.js");
@@ -34,41 +27,14 @@ function contrastRatio(foreground: string, background: string): number {
34273528describe("markdownTheme", () => {
3629describe("highlightCode", () => {
37-beforeEach(() => {
38-cliHighlightMocks.highlight.mockClear();
39-cliHighlightMocks.supportsLanguage.mockClear();
40-cliHighlightMocks.highlight.mockImplementation((code: string) => code);
41-cliHighlightMocks.supportsLanguage.mockReturnValue(true);
42-});
43-44-it("passes supported language through to the highlighter", () => {
45-markdownTheme.highlightCode!("const x = 42;", "javascript");
46-expect(cliHighlightMocks.supportsLanguage).toHaveBeenCalledWith("javascript");
47-expect(cliHighlightMocks.highlight).toHaveBeenCalledWith(
48-"const x = 42;",
49-expect.objectContaining({ language: "javascript" }),
50-);
51-});
52-53-it("falls back to auto-detect for unknown language and preserves lines", () => {
54-cliHighlightMocks.supportsLanguage.mockReturnValue(false);
55-cliHighlightMocks.highlight.mockImplementation((code: string) => `${code}\nline-2`);
30+it("renders code blocks with the theme code color and preserves lines", () => {
5631const result = markdownTheme.highlightCode!(`echo "hello"`, "not-a-real-language");
57-expect(cliHighlightMocks.highlight).toHaveBeenCalledWith(
58-`echo "hello"`,
59-expect.objectContaining({ language: undefined }),
60-);
6132expect(stripAnsi(result[0] ?? "")).toContain("echo");
62-expect(stripAnsi(result[1] ?? "")).toBe("line-2");
6333});
643465-it("returns plain highlighted lines when highlighting throws", () => {
66-cliHighlightMocks.highlight.mockImplementation(() => {
67-throw new Error("boom");
68-});
69-const result = markdownTheme.highlightCode!("echo hello", "javascript");
70-expect(result).toHaveLength(1);
71-expect(stripAnsi(result[0] ?? "")).toBe("echo hello");
35+it("preserves multi-line code blocks", () => {
36+const result = markdownTheme.highlightCode!("line-1\nline-2", "javascript");
37+expect(result.map((line) => stripAnsi(line))).toEqual(["line-1", "line-2"]);
7238});
7339});
7440});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。