|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | +import { getRepoConfig } from "../src"; |
| 3 | + |
| 4 | +describe("repo", () => { |
| 5 | + describe("getRepoConfig", () => { |
| 6 | + describe("when `m.repo` and `m.provider` are defined", () => { |
| 7 | + test.each([ |
| 8 | + { |
| 9 | + input: "github:donaldsh/test", |
| 10 | + output: { |
| 11 | + domain: "github.com", |
| 12 | + provider: "github", |
| 13 | + repo: "donaldsh/test", |
| 14 | + }, |
| 15 | + }, |
| 16 | + { |
| 17 | + input: "gitlab:donaldsh/test.git", |
| 18 | + output: { |
| 19 | + domain: "gitlab.com", |
| 20 | + provider: "gitlab", |
| 21 | + repo: "donaldsh/test", |
| 22 | + }, |
| 23 | + }, |
| 24 | + { |
| 25 | + input: "gitlab:donaldsh/test.git", |
| 26 | + output: { |
| 27 | + domain: "gitlab.com", |
| 28 | + provider: "gitlab", |
| 29 | + repo: "donaldsh/test", |
| 30 | + }, |
| 31 | + }, |
| 32 | + { |
| 33 | + input: "[email protected]:donaldsh/test.git", |
| 34 | + output: { |
| 35 | + domain: "bitbucket.org", |
| 36 | + provider: "bitbucket", |
| 37 | + repo: "donaldsh/test", |
| 38 | + }, |
| 39 | + }, |
| 40 | + { |
| 41 | + input: "a@x:b/c", |
| 42 | + output: { |
| 43 | + domain: "x", |
| 44 | + provider: "x", |
| 45 | + repo: "b/c", |
| 46 | + }, |
| 47 | + }, |
| 48 | + ])("url=$input should return RepoConfig", ({ input, output }) => { |
| 49 | + expect(getRepoConfig(input)).toEqual(output); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe("when `url` is defined", () => { |
| 54 | + test.each([ |
| 55 | + { |
| 56 | + input: "https://github.com/unjs/changelogen.git", |
| 57 | + output: { |
| 58 | + domain: "github.com", |
| 59 | + provider: "github", |
| 60 | + repo: "unjs/changelogen", |
| 61 | + }, |
| 62 | + }, |
| 63 | + { |
| 64 | + input: "https://github.com/unjs/changelogen", |
| 65 | + output: { |
| 66 | + domain: "github.com", |
| 67 | + provider: "github", |
| 68 | + repo: "unjs/changelogen", |
| 69 | + }, |
| 70 | + }, |
| 71 | + { |
| 72 | + input: "https://github.com/myproject.git", |
| 73 | + output: { |
| 74 | + domain: "github.com", |
| 75 | + provider: "github", |
| 76 | + repo: "myproject", |
| 77 | + }, |
| 78 | + }, |
| 79 | + { |
| 80 | + input: "https://github.com/account/project/sub1/sub2/myproject.git", |
| 81 | + output: { |
| 82 | + domain: "github.com", |
| 83 | + provider: "github", |
| 84 | + repo: "account/project/sub1/sub2/myproject", |
| 85 | + }, |
| 86 | + }, |
| 87 | + ])("url=$input should return RepoConfig", ({ input, output }) => { |
| 88 | + expect(getRepoConfig(input)).toEqual(output); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe("when only `m.repo` is defined", () => { |
| 93 | + test.each([ |
| 94 | + { |
| 95 | + input: "donaldsh/test.git", |
| 96 | + output: { |
| 97 | + domain: "github.com", |
| 98 | + provider: "github", |
| 99 | + repo: "donaldsh/test", |
| 100 | + }, |
| 101 | + }, |
| 102 | + { |
| 103 | + input: "unjs/changelogen", |
| 104 | + output: { |
| 105 | + domain: "github.com", |
| 106 | + provider: "github", |
| 107 | + repo: "unjs/changelogen", |
| 108 | + }, |
| 109 | + }, |
| 110 | + ])("url=$input should return RepoConfig", ({ input, output }) => { |
| 111 | + expect(getRepoConfig(input)).toEqual(output); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + describe("when `repoUrl` is empty", () => { |
| 116 | + test("should return empty RepoConfig", () => { |
| 117 | + expect(getRepoConfig()).toEqual({}); |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments