You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.8 KiB

import { describe, expect, test } from "bun:test";
import {
buildMarkdownExportFileName,
normalizeMarkdownImageUrls,
} from "./markdown-export";
describe("normalizeMarkdownImageUrls", () => {
test("converts /public/assets image links to absolute URLs", () => {
const markdown = "![cover](/public/assets/posts/cover.png)";
const result = normalizeMarkdownImageUrls(markdown, "https://example.com");
expect(result).toBe("![cover](https://example.com/public/assets/posts/cover.png)");
});
test("keeps absolute http/https image links unchanged", () => {
const markdown = [
"![a](http://cdn.example.com/a.png)",
"![b](https://cdn.example.com/b.png)",
].join("\n");
const result = normalizeMarkdownImageUrls(markdown, "https://example.com");
expect(result).toBe(markdown);
});
test("keeps protocol-relative and data URI image links unchanged", () => {
const markdown = [
"![protocol](//cdn.example.com/p.png)",
"![inline](data:image/png;base64,AAAB)",
].join("\n");
const result = normalizeMarkdownImageUrls(markdown, "https://example.com");
expect(result).toBe(markdown);
});
test("does not change normal markdown links", () => {
const markdown = "[read more](/public/assets/posts/cover.png)";
const result = normalizeMarkdownImageUrls(markdown, "https://example.com");
expect(result).toBe(markdown);
});
});
describe("buildMarkdownExportFileName", () => {
test("prefers slug when slug is not empty", () => {
const result = buildMarkdownExportFileName({ slug: "hello-world", id: 42 });
expect(result).toBe("hello-world.md");
});
test("falls back to post-<id>.md when slug is empty", () => {
const result = buildMarkdownExportFileName({ slug: "", id: 42 });
expect(result).toBe("post-42.md");
});
});