Open History to see the last commit
1import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition";
2import { describe, expect, it } from "vite-plus/test";
3
4import { definition } from "./definition.ts";
5
6const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url));
7
8describe("Bitbucket change request URLs", () => {
9 it("reads a pull request on Bitbucket hosts", () => {
10 expect(parse("https://bitbucket.org/workspace/repo/pull-requests/5/diff")).toEqual({
11 host: "bitbucket.org",
12 repository: "workspace/repo",
13 number: 5,
14 repositoryUrl: "https://bitbucket.org/workspace/repo",
15 });
16 expect(parse("https://code.bitbucket.example.test/team/repo/pull-requests/6")).toMatchObject({
17 host: "code.bitbucket.example.test",
18 number: 6,
19 });
20 });
21
22 it("leaves other hosts alone", () => {
23 expect(parse("https://scm.example.test/workspace/repo/pull-requests/5")).toBeNull();
24 });
25
26 it("builds pull request URLs below the repository", () => {
27 expect(
28 definition.changeRequestUrl({ host: "bitbucket.org", repository: "w/repo", number: 5 }),
29 ).toBe("https://bitbucket.org/w/repo/pull-requests/5");
30 expect(
31 definition.changeRequestUrl({
32 host: "bitbucket.org",
33 repository: "w/repo",
34 number: 5,
35 webUrl: "https://bitbucket.org/w/repo",
36 }),
37 ).toBe("https://bitbucket.org/w/repo/pull-requests/5");
38 });
39});
40
41describe("Bitbucket remotes", () => {
42 const recognize = (url: string) => recognizeRemoteWith(definition, url);
43
44 it("recognises bitbucket.org and hosts with a bitbucket label", () => {
45 expect(recognize("git@bitbucket.org:workspace/repo.git")).toEqual({
46 kind: "bitbucket",
47 name: "Bitbucket",
48 baseUrl: "https://bitbucket.org",
49 });
50 expect(recognize("https://bitbucket.example.com/workspace/repo.git")?.name).toBe(
51 "Bitbucket Self-Hosted",
52 );
53 expect(recognize("https://notbitbucket.example.com/workspace/repo.git")).toBeNull();
54 });
55});