Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { definition, parsePullRequestUrl } from "./definition.ts";
4
5describe("TanStack Source definition", () => {
6 it("reads pull requests and commits only on its own host", () => {
7 expect(
8 definition.parseCommitUrl?.(
9 new URL(
10 "https://source.tanstack.com/@TanStack/router/commit/cebaf84a4fe3776f27359ef1d978f0650d6b0e51",
11 ),
12 ),
13 ).toMatchObject({ repository: "tanstack/router" });
14 for (const url of [
15 "https://github.com/TanStack/router/pull/1",
16 "https://source.tanstack.com.evil.test/@TanStack/router/pull/1",
17 "https://source.tanstack.com/@TanStack/router/pull/0",
18 ])
19 expect(parsePullRequestUrl(url), url).toBeNull();
20 // Some clients send the owner's `@` percent-encoded.
21 expect(
22 definition.parseIssueUrl?.(new URL("https://source.tanstack.com/%40TanStack/ai/issues/12")),
23 ).toEqual({ host: "source.tanstack.com", scope: "tanstack/ai", key: "12" });
24 });
25
26 it("builds links with the owner's @ and reads src's checkout command", () => {
27 expect(
28 definition.changeRequestUrl({
29 host: "source.tanstack.com",
30 repository: "TanStack/router",
31 number: 7,
32 }),
33 ).toBe("https://source.tanstack.com/@TanStack/router/pull/7");
34 // A stored link or an older client may name the repository as the web spells it.
35 for (const repository of ["@TanStack/router", "%40TanStack/router"])
36 expect(
37 definition.changeRequestUrl({ host: "source.tanstack.com", repository, number: 7 }),
38 repository,
39 ).toBe("https://source.tanstack.com/@TanStack/router/pull/7");
40 expect(definition.checkoutCommandArgument("src pr checkout 7")).toBe("7");
41 expect(definition.checkoutCommandArgument("gh pr checkout 7")).toBeNull();
42 });
43
44 it.each(["tanstack/router", "@tanstack/router", "%40tanstack/router"])(
45 "keys %s as the API's owner/name",
46 (repository) => {
47 expect(definition.canonicalRepositoryKey?.(`source.tanstack.com/${repository}`)).toBe(
48 "source.tanstack.com/tanstack/router",
49 );
50 expect(definition.canonicalRepositoryKey?.(`github.com/${repository}`)).toBeNull();
51 },
52 );
53});