Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { gitHubReferenceAutolinks } from "./referenceAutolinks.ts";
4
5const repositoryUrl = "https://github.com/team/repo";
6const linked = (text: string) =>
7 gitHubReferenceAutolinks(text, repositoryUrl).map(({ label, url, kind }) => [label, url, kind]);
8
9describe("gitHubReferenceAutolinks", () => {
10 it("links references, cross-repository references, commits and mentions", () => {
11 expect(
12 linked(
13 "Closes #123, fixes other/project#9; other#4 @julius @team/mobile abc1234 other/project@abcdef1",
14 ),
15 ).toEqual([
16 ["#123", "https://github.com/team/repo/issues/123", "reference"],
17 ["other/project#9", "https://github.com/other/project/issues/9", "reference"],
18 ["other#4", "https://github.com/other/repo/issues/4", "reference"],
19 ["@julius", "https://github.com/julius", "mention"],
20 ["@team/mobile", "https://github.com/orgs/team/teams/mobile", "mention"],
21 ["abc1234", "https://github.com/team/repo/commit/abc1234", "commit"],
22 ["other/project@abcdef1", "https://github.com/other/project/commit/abcdef1", "commit"],
23 ]);
24 });
25
26 it("shows a full SHA by its first seven characters", () => {
27 const sha = "0123456789abcdef0123456789abcdef01234567";
28 expect(linked(`Reverts ${sha}.`)).toEqual([
29 ["0123456", `https://github.com/team/repo/commit/${sha}`, "commit"],
30 ]);
31 });
32
33 it("leaves URLs, escapes, emails, words and plain numbers alone", () => {
34 expect(linked("https://example.com/#123 user@example.com \\#123 1234567 issue#x a#1b")).toEqual(
35 [],
36 );
37 });
38
39 it("links against the repository's own host", () => {
40 expect(
41 gitHubReferenceAutolinks("See #5", "https://ghe.example.com/acme/web").map(({ url }) => url),
42 ).toEqual(["https://ghe.example.com/acme/web/issues/5"]);
43 });
44});