Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

definition.test.ts

37 lines1.4 KB

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 expect(definition.checkoutCommandArgument("src pr checkout 7")).toBe("7");
35 expect(definition.checkoutCommandArgument("gh pr checkout 7")).toBeNull();
36 });
37});