add all of the testing
This commit is contained in:
parent
d5b4341487
commit
91f39a80a7
12 changed files with 485 additions and 69 deletions
43
src/plugins/__tests__/markdown-compiler.test.ts
Normal file
43
src/plugins/__tests__/markdown-compiler.test.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { expect, test } from "bun:test";
|
||||
import MarkdownCompiler from "../markdown-compiler";
|
||||
|
||||
// Mock marked and parseMetadata for isolated testing
|
||||
const mockMarked = {
|
||||
parse: (text: string) => `<p>${text}</p>`,
|
||||
};
|
||||
const mockParseMetadata = (file: string) => {
|
||||
if (file.startsWith("title=Hello\n=+\n")) {
|
||||
return { title: "Hello" };
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
// Patch dependencies
|
||||
// @ts-expect-error
|
||||
MarkdownCompiler.prototype["marked"] = mockMarked;
|
||||
// @ts-expect-error
|
||||
MarkdownCompiler.prototype["parseMetadata"] = mockParseMetadata;
|
||||
|
||||
test("MarkdownCompiler compiles markdown to HTML", async () => {
|
||||
const plugin = new MarkdownCompiler();
|
||||
const input = "# Hello World";
|
||||
// Simulate marked.parse
|
||||
const output = await plugin.rewriteFile(input, "test.md");
|
||||
expect(typeof output).toBe("string");
|
||||
expect(output).toContain("Hello World");
|
||||
});
|
||||
|
||||
test("MarkdownCompiler uses metadata title if present", async () => {
|
||||
const plugin = new MarkdownCompiler();
|
||||
const input = "title=Hello\n=+\n# Some Content";
|
||||
const output = await plugin.rewriteFile(input, "test.md");
|
||||
expect(output).toContain("Hello");
|
||||
expect(output).toContain("Some Content");
|
||||
});
|
||||
|
||||
test("MarkdownCompiler returns HTML for markdown without metadata", async () => {
|
||||
const plugin = new MarkdownCompiler();
|
||||
const input = "# Just Markdown";
|
||||
const output = await plugin.rewriteFile(input, "test.md");
|
||||
expect(output).toContain("Just Markdown");
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue