Skip to content

g1t/apps/web/app/lib/markdown-plugins.test.ts

35 lines1,441 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { rehypeReferences } from "./markdown-plugins.ts";
5
6type Node = { type: string; value?: string; tagName?: string; properties?: Record<string, unknown>; children?: Node[] };
7
8/** The links a paragraph of `text` gets: each one's href and text. */
9function links(text: string): [string, string][] {
10 const tree: Node = { type: "root", children: [{ type: "element", tagName: "p", properties: {}, children: [{ type: "text", value: text }] }] };
11 rehypeReferences({ repo: { namespace: "acme", name: "web" } })(tree as never);
12 return (tree.children![0]!.children ?? [])
13 .filter((node) => node.tagName === "a")
14 .map((node) => [String(node.properties!.href), node.children![0]!.value!]);
15}
16
17test("@name links to the person or workspace", () => {
18 assert.deepEqual(links("thanks @Ana."), [["/ana", "@Ana"]]);
19 assert.deepEqual(links("me@example.com"), []);
20});
21
22test("@workspace/team links to the team", () => {
23 assert.deepEqual(links("cc @acme/backend, @ana"), [
24 ["/acme/-/teams/backend", "@acme/backend"],
25 ["/ana", "@ana"],
26 ]);
27 assert.deepEqual(links("(@Acme/Web-Platform)"), [["/acme/-/teams/web-platform", "@Acme/Web-Platform"]]);
28});
29
30test("issues and pull requests still link", () => {
31 assert.deepEqual(links("see #12 and other/repo#3"), [
32 ["/acme/web/issues/12", "#12"],
33 ["/other/repo/issues/3", "other/repo#3"],
34 ]);
35});