Repository navigation
Expand file tree
/
Copy pathgithubMarkdownLinks.test.ts
More file actions
35 lines (34 loc) · 1.97 KB
/
Copy pathgithubMarkdownLinks.test.ts
File metadata and controls
35 lines (34 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, expect, it } from "vite-plus/test";
import { githubMarkdownLinks } from "./githubMarkdownLinks.ts";
const url = "https://github.com/team/repo/pull/8";
describe("githubMarkdownLinks", () => {
it("links closing references, cross-repository references, commits and mentions", () => {
expect(
githubMarkdownLinks(
"Closes #123, fixes other/project#9; other#4 @julius @team/mobile abc1234 other/project@abcdef1",
url,
),
).toBe(
"Closes [#123](https://github.com/team/repo/issues/123), fixes [other/project#9](https://github.com/other/project/issues/9); [other#4](https://github.com/other/repo/issues/4) [@julius](https://github.com/julius) [@team/mobile](https://github.com/orgs/team/teams/mobile) [abc1234](https://github.com/team/repo/commit/abc1234) [other/project@abcdef1](https://github.com/other/project/commit/abcdef1)",
);
});
it("leaves code, links, images, URLs, escapes, emails, and plain numbers alone", () => {
const text =
"`#123 @person abc1234`\n\n```\n#123\n```\n\n[#123](https://example.com)  https://example.com/#123 user@example.com \\#123 1234567\n\n[ref]: https://example.com/#123";
expect(githubMarkdownLinks(text, url)).toBe(text);
});
it("keeps formatting and links references in lists and quotes", () => {
expect(githubMarkdownLinks("> **Fixes #42**\n\n- See #9", url)).toBe(
"> **Fixes [#42](https://github.com/team/repo/issues/42)**\n\n- See [#9](https://github.com/team/repo/issues/9)",
);
});
it("does nothing without repository context", () => {
expect(githubMarkdownLinks("#123", null)).toBe("#123");
});
it("does not nest links inside HTML anchors or code", () => {
const text = 'See <a href="https://example.com">#12</a> and <code>#13</code>, then #14.';
expect(githubMarkdownLinks(text, url)).toBe(
'See <a href="https://example.com">#12</a> and <code>#13</code>, then [#14](https://github.com/team/repo/issues/14).',
);
});
});