Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import { describe, expect, it } from "vitest";import { renderDocument, renderMarkup } from "$lib/markup/render";import type { MarkupContext } from "$lib/markup/paths";
const ctx: MarkupContext = { repo: "ada.test/infra", ref: "main", host: "tangled.org" };
const keyOf = (html: string | null): string => { const key = /^<div data-markup-key="([^"]+)">/.exec(html ?? "")?.[1]; if (!key) throw new Error(`no markup key in ${html}`); return key;};
describe("renderDocument", () => { it("wraps what it renders under a key", async () => { const html = await renderDocument("README.md", "# hello", ctx); expect(keyOf(html)).toMatch(/^[0-9a-z]+\.[0-9a-z]+\.[0-9a-z]+$/); expect(html).toContain("<h1"); expect(html).toContain("hello"); });
it("keeps a document that is not markdown away from the renderer", async () => { expect(await renderDocument("notes.txt", "# hello", ctx)).toBeNull(); });
it("keys the same contents rendered elsewhere apart", async () => { const here = keyOf(await renderDocument("README.md", "see [x](y)", ctx)); const elsewhere = keyOf( await renderDocument("README.md", "see [x](y)", { ...ctx, ref: "dev" }) ); const copied = keyOf(await renderDocument("docs/README.md", "see [x](y)", ctx)); expect(elsewhere).not.toBe(here); expect(copied).not.toBe(here); });
it("keys different contents apart", async () => { expect(keyOf(await renderDocument("README.md", "# a", ctx))).not.toBe( keyOf(await renderDocument("README.md", "# b", ctx)) ); });
it("gives the same contents the same key every time", async () => { expect(keyOf(await renderDocument("README.md", "# a", ctx))).toBe( keyOf(await renderDocument("README.md", "# a", ctx)) ); });});
describe("renderMarkup", () => { // a body and a file with the same contents need different keys it("wraps a body under a key of its own", async () => { const html = await renderMarkup("a **body**", ctx); expect(html).toContain("<strong>body</strong>"); expect(keyOf(html)).not.toBe(keyOf(await renderDocument("README.md", "a **body**", ctx))); });});