Skip to content

Commit a70e6b8

Browse files
author
youncccat
committed
[Test::workflow] append some test cases for branch name checker
1 parent 6f490a2 commit a70e6b8

File tree

1 file changed

+66
-18
lines changed

1 file changed

+66
-18
lines changed

packages/commitlint-wizardoc-e2e-tests/src/tests/shell.test.ts

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,87 @@
22
import { $ } from "../utils/shell";
33

44
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;
79

810
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");
1113

12-
console.log(`res`, res);
13-
14-
expect(res.code).toEqual(SUCCESS_SIGNAL);
14+
expect(code).toEqual(SUCCESS_SIGNAL);
1515
});
1616

1717
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");
1967

20-
expect(res.code).not.toEqual(SUCCESS_SIGNAL);
68+
expect(code).not.toEqual(SUCCESS_SIGNAL);
2169
});
2270

23-
it("empty branch name error", () => {
24-
const res = $`sh ${executeCommand} feature/`;
71+
it("invalid symbol", () => {
72+
const code = checkBranchName("feature/xx&xx");
2573

26-
expect(res.code).not.toEqual(SUCCESS_SIGNAL);
74+
expect(code).not.toEqual(SUCCESS_SIGNAL);
2775
});
2876

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");
3179

32-
expect(res.code).not.toEqual(SUCCESS_SIGNAL);
80+
expect(code).not.toEqual(SUCCESS_SIGNAL);
3381
});
3482

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");
3785

38-
expect(res.code).not.toEqual(SUCCESS_SIGNAL);
86+
expect(code).not.toEqual(SUCCESS_SIGNAL);
3987
});
4088
});

0 commit comments

Comments
 (0)