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
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 = "";
|
|
const result = normalizeMarkdownImageUrls(markdown, "https://example.com");
|
|
|
|
expect(result).toBe("");
|
|
});
|
|
|
|
test("keeps absolute http/https image links unchanged", () => {
|
|
const markdown = [
|
|
"",
|
|
"",
|
|
].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 = [
|
|
"",
|
|
"",
|
|
].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");
|
|
});
|
|
});
|
|
|