|
2 | 2 | import { $ } from "../utils/shell"; |
3 | 3 |
|
4 | 4 | const SUCCESS_SIGNAL = 0; |
5 | | -const shellUrl = "./.github/shell/branchName.sh"; |
6 | | -const executeCommand = `chmod +x ${shellUrl} && ${shellUrl}`; |
| 5 | +const BRANCH_NAME_CHECKER = ".github/shell/branchName.sh"; |
| 6 | +const checkBranchName = (branchName: string) => |
| 7 | + $`chmod +x ${BRANCH_NAME_CHECKER} && ${BRANCH_NAME_CHECKER} ${branchName}` |
| 8 | + .code; |
7 | 9 |
|
8 | 10 | describe("branchNameTest", () => { |
9 | | - it("success branch name", () => { |
10 | | - const res = $`sh ${executeCommand} feature/git-rebase-test`; |
| 11 | + it("correct branch name", () => { |
| 12 | + const code = checkBranchName("feature/git-rebase-test"); |
11 | 13 |
|
12 | | - console.log(`res`, res); |
13 | | - |
14 | | - expect(res.code).toEqual(SUCCESS_SIGNAL); |
| 14 | + expect(code).toEqual(SUCCESS_SIGNAL); |
15 | 15 | }); |
16 | 16 |
|
17 | 17 | it("type error", () => { |
18 | | - const res = $`sh ${executeCommand} test/git-rebase-test`; |
| 18 | + const code = checkBranchName("test/git-rebase-test"); |
| 19 | + |
| 20 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 21 | + }); |
| 22 | + |
| 23 | + it("underline suffix", () => { |
| 24 | + const code = checkBranchName("feature/git-rebase-test_"); |
| 25 | + |
| 26 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 27 | + }); |
| 28 | + |
| 29 | + it("dash suffix", () => { |
| 30 | + const code = checkBranchName("feature/git-rebase-test-"); |
| 31 | + |
| 32 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 33 | + }); |
| 34 | + |
| 35 | + it("mixin camel case branch name", () => { |
| 36 | + const code = checkBranchName("feature/git-rebase-branchName"); |
| 37 | + |
| 38 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 39 | + }); |
| 40 | + |
| 41 | + it("mixin dash case branch name", () => { |
| 42 | + const code = checkBranchName("feature/git-rebase-xxx_xxx"); |
| 43 | + |
| 44 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 45 | + }); |
| 46 | + |
| 47 | + it("missing type", () => { |
| 48 | + const code = checkBranchName("/git-rebase-xxx_xxx"); |
| 49 | + |
| 50 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 51 | + }); |
| 52 | + |
| 53 | + it("missing branch name", () => { |
| 54 | + const code = checkBranchName("feature/"); |
| 55 | + |
| 56 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 57 | + }); |
| 58 | + |
| 59 | + it("missing separator", () => { |
| 60 | + const code = checkBranchName("featurexxxxxx"); |
| 61 | + |
| 62 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
| 63 | + }); |
| 64 | + |
| 65 | + it("include space", () => { |
| 66 | + const code = checkBranchName("feature/ ssss-ssss"); |
19 | 67 |
|
20 | | - expect(res.code).not.toEqual(SUCCESS_SIGNAL); |
| 68 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
21 | 69 | }); |
22 | 70 |
|
23 | | - it("empty branch name error", () => { |
24 | | - const res = $`sh ${executeCommand} feature/`; |
| 71 | + it("invalid symbol", () => { |
| 72 | + const code = checkBranchName("feature/xx&xx"); |
25 | 73 |
|
26 | | - expect(res.code).not.toEqual(SUCCESS_SIGNAL); |
| 74 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
27 | 75 | }); |
28 | 76 |
|
29 | | - it("separator branch name error", () => { |
30 | | - const res = $`chmod +x ${executeCommand} feature/brach_name`; |
| 77 | + it("dash case branch name error", () => { |
| 78 | + const code = checkBranchName("feature/brach_name"); |
31 | 79 |
|
32 | | - expect(res.code).not.toEqual(SUCCESS_SIGNAL); |
| 80 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
33 | 81 | }); |
34 | 82 |
|
35 | | - it("upper Case branch name error", () => { |
36 | | - const res = $`sh ${executeCommand} feature/brachName`; |
| 83 | + it("camel case branch name error", () => { |
| 84 | + const code = checkBranchName("feature/brachName"); |
37 | 85 |
|
38 | | - expect(res.code).not.toEqual(SUCCESS_SIGNAL); |
| 86 | + expect(code).not.toEqual(SUCCESS_SIGNAL); |
39 | 87 | }); |
40 | 88 | }); |
0 commit comments