@@ -14,38 +14,59 @@ describe("utils", () => {
14
14
} ) ;
15
15
16
16
describe ( "getBranchNameFromRef" , ( ) => {
17
+ // We want to assert that the props are properly set in
18
+ // the union of the return type
19
+ interface BranchNameResultUnion {
20
+ branchName ?: string ;
21
+ isTag : boolean ;
22
+ ref : string ;
23
+ }
24
+
17
25
it ( "should return the branch name for a valid branch ref" , ( ) => {
18
26
const branchName = "cool_feature" ;
19
27
const ref = `/refs/heads/${ branchName } ` ;
20
- const branch = getBranchName ( ref ) ;
28
+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
21
29
22
- expect ( branch ) . toStrictEqual ( branchName ) ;
30
+ expect ( branch . isTag ) . toStrictEqual ( false ) ;
31
+ expect ( branch . branchName ) . toStrictEqual ( branchName ) ;
32
+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
23
33
} ) ;
24
34
25
35
it ( "should return the branch name for a valid branch ref without a leading slash" , ( ) => {
26
36
const branchName = "cool_feature" ;
27
37
const ref = `refs/heads/${ branchName } ` ;
28
- const branch = getBranchName ( ref ) ;
38
+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
29
39
30
- expect ( branch ) . toStrictEqual ( branchName ) ;
40
+ expect ( branch . isTag ) . toStrictEqual ( false ) ;
41
+ expect ( branch . branchName ) . toStrictEqual ( branchName ) ;
42
+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
31
43
} ) ;
32
44
33
45
it ( "should return undefined for an invalid branch ref" , ( ) => {
34
- const branch = getBranchName ( "refs/heads/" ) ;
46
+ const ref = "refs/heads/" ;
47
+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
35
48
36
- expect ( branch ) . toBeUndefined ( ) ;
49
+ expect ( branch . isTag ) . toStrictEqual ( false ) ;
50
+ expect ( branch . branchName ) . toBeUndefined ( ) ;
51
+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
37
52
} ) ;
38
53
39
- it ( "should return undefined if the ref is for a tag" , ( ) => {
40
- const branch = getBranchName ( "refs/tags/v1.0.1" ) ;
54
+ it ( "should return isTag true if the ref is for a tag" , ( ) => {
55
+ const ref = "refs/tags/v1.0.1" ;
56
+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
41
57
42
- expect ( branch ) . toBeUndefined ( ) ;
58
+ expect ( branch . isTag ) . toStrictEqual ( true ) ;
59
+ expect ( branch . branchName ) . toBeUndefined ( ) ;
60
+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
43
61
} ) ;
44
62
45
- it ( "should return undefined if the ref is for an invalid tag" , ( ) => {
46
- const branch = getBranchName ( "refs/tags/" ) ;
63
+ it ( "should return isTag true if the ref is for an invalid tag" , ( ) => {
64
+ const ref = "refs/tags/" ;
65
+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
47
66
48
- expect ( branch ) . toBeUndefined ( ) ;
67
+ expect ( branch . isTag ) . toStrictEqual ( true ) ;
68
+ expect ( branch . branchName ) . toBeUndefined ( ) ;
69
+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
49
70
} ) ;
50
71
} ) ;
51
72
} ) ;
0 commit comments