41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import MarkdownCompiler from "../markdown-compiler";
|
|
|
|
const mockMarked = {
|
|
parse: (text: string) => `<p>${text}</p>`,
|
|
};
|
|
const mockParseMetadata = (file: string) => {
|
|
if (file.startsWith("title=Hello\n=+\n")) {
|
|
return { title: "Hello" };
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
// @ts-expect-error Mocked.
|
|
MarkdownCompiler.prototype["marked"] = mockMarked;
|
|
// @ts-expect-error Mocked.
|
|
MarkdownCompiler.prototype["parseMetadata"] = mockParseMetadata;
|
|
|
|
test("MarkdownCompiler compiles markdown to HTML", async () => {
|
|
const plugin = new MarkdownCompiler();
|
|
const input = "# Hello World";
|
|
|
|
const output = await plugin.rewriteFile(input);
|
|
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);
|
|
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);
|
|
expect(output).toContain("Just Markdown");
|
|
});
|