fix test again

This commit is contained in:
Nate 2025-07-14 21:25:28 -07:00
parent 5482da2ad4
commit ef2e822eb8
5 changed files with 59 additions and 5 deletions

View file

@ -7,13 +7,19 @@ export default {
},
moduleNameMapper: {
"^highlight\\.js/lib/languages/(.+)\\.js$": "<rootDir>/src/ui/__mocks__/highlightLanguage.js",
"^lowlight$": "<rootDir>/src/ui/__mocks__/lowlight.js",
"(.+)\\.js": "$1",
"^ink-testing-library$": "<rootDir>/node_modules/ink-testing-library/build/index.js",
"^./SyntaxHighlighter\\.js$": "<rootDir>/src/ui/__mocks__/SyntaxHighlighter.ts",
},
extensionsToTreatAsEsm: [".ts", ".tsx"],
preset: "ts-jest/presets/default-esm",
testTimeout: 10000,
testEnvironment: "node",
testPathIgnorePatterns: [
"<rootDir>/dist/"
],
transformIgnorePatterns: [
"node_modules/(?!(highlight.js|lowlight)/)"
],

View file

@ -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);
});
});
});

View file

@ -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';
}

View file

@ -0,0 +1,7 @@
// Mock for highlight.js language modules
export default function mockLanguage() {
return {
keywords: 'mock keywords',
contains: []
};
}

View file

@ -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 }]
})
};
}