diff --git a/jest.config.mjs b/jest.config.mjs index 749883881..8b9c36065 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -7,13 +7,19 @@ export default { }, moduleNameMapper: { + "^highlight\\.js/lib/languages/(.+)\\.js$": "/src/ui/__mocks__/highlightLanguage.js", + "^lowlight$": "/src/ui/__mocks__/lowlight.js", "(.+)\\.js": "$1", "^ink-testing-library$": "/node_modules/ink-testing-library/build/index.js", + "^./SyntaxHighlighter\\.js$": "/src/ui/__mocks__/SyntaxHighlighter.ts", }, extensionsToTreatAsEsm: [".ts", ".tsx"], preset: "ts-jest/presets/default-esm", testTimeout: 10000, testEnvironment: "node", + testPathIgnorePatterns: [ + "/dist/" + ], transformIgnorePatterns: [ "node_modules/(?!(highlight.js|lowlight)/)" ], diff --git a/src/ui/MarkdownRenderer.test.tsx b/src/ui/MarkdownRenderer.test.tsx index c9797dbf4..516b8e41d 100644 --- a/src/ui/MarkdownRenderer.test.tsx +++ b/src/ui/MarkdownRenderer.test.tsx @@ -1,4 +1,5 @@ import React from "react"; +import { Text } from "ink"; import MarkdownRenderer from "./MarkdownRenderer.js"; describe("MarkdownRenderer", () => { @@ -156,7 +157,7 @@ describe("MarkdownRenderer", () => { expect(result.length).toBe(1); expect(React.isValidElement(result[0])).toBe(true); // The result should be a Text element containing syntax highlighted code - expect((result[0] as any).type).toBe("ink-text"); + expect((result[0] as any).type).toBe(Text); expect((result[0] as any).props.children).toBeDefined(); expect(Array.isArray((result[0] as any).props.children)).toBe(true); }); @@ -165,7 +166,7 @@ describe("MarkdownRenderer", () => { const result = renderMarkdown("```console.log('hello')```"); expect(result.length).toBe(1); expect(React.isValidElement(result[0])).toBe(true); - expect((result[0] as any).type).toBe("ink-text"); + expect((result[0] as any).type).toBe(Text); expect((result[0] as any).props.children).toBeDefined(); }); @@ -173,7 +174,7 @@ describe("MarkdownRenderer", () => { const result = renderMarkdown("```javascript\nconst x = 1;\n```"); expect(result.length).toBe(1); expect(React.isValidElement(result[0])).toBe(true); - expect((result[0] as any).type).toBe("ink-text"); + expect((result[0] as any).type).toBe(Text); expect((result[0] as any).props.children).toBeDefined(); }); @@ -184,7 +185,7 @@ describe("MarkdownRenderer", () => { expect(result.length).toBe(5); expect(result[0]).toBe("Here's some code:\n"); expect(React.isValidElement(result[1])).toBe(true); - expect((result[1] as any).type).toBe("ink-text"); + expect((result[1] as any).type).toBe(Text); expect(result[2]).toBe("\nAnd "); expect((result[3] as any).props.bold).toBe(true); expect((result[3] as any).props.children).toBe("bold"); @@ -195,7 +196,7 @@ describe("MarkdownRenderer", () => { const result = renderMarkdown("``````"); expect(result.length).toBe(1); expect(React.isValidElement(result[0])).toBe(true); - expect((result[0] as any).type).toBe("ink-text"); + expect((result[0] as any).type).toBe(Text); }); }); }); diff --git a/src/ui/__mocks__/SyntaxHighlighter.ts b/src/ui/__mocks__/SyntaxHighlighter.ts new file mode 100644 index 000000000..c0f7a4633 --- /dev/null +++ b/src/ui/__mocks__/SyntaxHighlighter.ts @@ -0,0 +1,28 @@ +import { Text } from 'ink'; +import React from 'react'; + +export interface SyntaxHighlighterTheme { + keyword: string; + string: string; + comment: string; + number: string; + operator: string; +} + +export const defaultTheme: SyntaxHighlighterTheme = { + keyword: 'blue', + string: 'green', + comment: 'gray', + number: 'yellow', + operator: 'cyan', +}; + +export function highlightCode(code: string, language?: string): React.ReactNode[] { + // Mock implementation that just returns the code as plain text + return [React.createElement('ink-text', { key: 'mock-code' }, code)]; +} + +export function detectLanguage(code: string): string { + // Mock implementation + return 'javascript'; +} \ No newline at end of file diff --git a/src/ui/__mocks__/highlightLanguage.js b/src/ui/__mocks__/highlightLanguage.js new file mode 100644 index 000000000..c123584e1 --- /dev/null +++ b/src/ui/__mocks__/highlightLanguage.js @@ -0,0 +1,7 @@ +// Mock for highlight.js language modules +export default function mockLanguage() { + return { + keywords: 'mock keywords', + contains: [] + }; +} \ No newline at end of file diff --git a/src/ui/__mocks__/lowlight.js b/src/ui/__mocks__/lowlight.js new file mode 100644 index 000000000..95d7779e1 --- /dev/null +++ b/src/ui/__mocks__/lowlight.js @@ -0,0 +1,12 @@ +// Mock for lowlight +export function createLowlight() { + return { + register: () => {}, + highlight: (lang, code) => ({ + children: [{ type: 'text', value: code }] + }), + highlightAuto: (code) => ({ + children: [{ type: 'text', value: code }] + }) + }; +} \ No newline at end of file