11package monorepo_test
22
33import (
4- "path/filepath"
54 "sort"
65 "testing"
76
87 "github.com/microsoft/beachball/internal/monorepo"
8+ "github.com/microsoft/beachball/internal/testutil"
99 "github.com/microsoft/beachball/internal/types"
1010)
1111
12- func makeInfos (root string , folders map [string ]string ) types.PackageInfos {
13- infos := make (types.PackageInfos )
14- for folder , name := range folders {
15- infos [name ] = & types.PackageInfo {
16- Name : name ,
17- Version : "1.0.0" ,
18- PackageJSONPath : filepath .Join (root , folder , "package.json" ),
19- }
20- }
21- return infos
22- }
12+ var root = testutil .FakeRoot ()
2313
2414func TestGetPackageGroups_ReturnsEmptyIfNoGroups (t * testing.T ) {
25- infos := makeInfos ( "/repo" , map [string ]string {
15+ infos := testutil . MakePackageInfos ( root , map [string ]string {
2616 "packages/foo" : "foo" ,
2717 })
28- result := monorepo .GetPackageGroups (infos , "/repo" , nil )
18+ result := monorepo .GetPackageGroups (infos , root , nil )
2919 if len (result ) != 0 {
3020 t .Fatalf ("expected empty map, got: %v" , result )
3121 }
3222}
3323
3424func TestGetPackageGroups_ReturnsGroupsBasedOnSpecificFolders (t * testing.T ) {
35- infos := makeInfos ( "/repo" , map [string ]string {
25+ infos := testutil . MakePackageInfos ( root , map [string ]string {
3626 "packages/foo" : "foo" ,
3727 "packages/bar" : "bar" ,
3828 "packages/baz" : "baz" ,
@@ -43,7 +33,7 @@ func TestGetPackageGroups_ReturnsGroupsBasedOnSpecificFolders(t *testing.T) {
4333 Include : []string {"packages/foo" , "packages/bar" },
4434 },
4535 }
46- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
36+ result := monorepo .GetPackageGroups (infos , root , groups )
4737 if len (result ) != 1 {
4838 t .Fatalf ("expected 1 group, got %d" , len (result ))
4939 }
@@ -61,7 +51,7 @@ func TestGetPackageGroups_ReturnsGroupsBasedOnSpecificFolders(t *testing.T) {
6151}
6252
6353func TestGetPackageGroups_HandlesSingleLevelGlobs (t * testing.T ) {
64- infos := makeInfos ( "/repo" , map [string ]string {
54+ infos := testutil . MakePackageInfos ( root , map [string ]string {
6555 "packages/ui-button" : "ui-button" ,
6656 "packages/ui-input" : "ui-input" ,
6757 "packages/core-utils" : "core-utils" ,
@@ -72,7 +62,7 @@ func TestGetPackageGroups_HandlesSingleLevelGlobs(t *testing.T) {
7262 Include : []string {"packages/ui-*" },
7363 },
7464 }
75- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
65+ result := monorepo .GetPackageGroups (infos , root , groups )
7666 grp := result ["ui" ]
7767 if grp == nil {
7868 t .Fatal ("expected ui group to exist" )
@@ -87,7 +77,7 @@ func TestGetPackageGroups_HandlesSingleLevelGlobs(t *testing.T) {
8777}
8878
8979func TestGetPackageGroups_HandlesMultiLevelGlobs (t * testing.T ) {
90- infos := makeInfos ( "/repo" , map [string ]string {
80+ infos := testutil . MakePackageInfos ( root , map [string ]string {
9181 "packages/ui/button" : "ui-button" ,
9282 "packages/ui/input" : "ui-input" ,
9383 "packages/core" : "core" ,
@@ -98,7 +88,7 @@ func TestGetPackageGroups_HandlesMultiLevelGlobs(t *testing.T) {
9888 Include : []string {"packages/ui/**" },
9989 },
10090 }
101- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
91+ result := monorepo .GetPackageGroups (infos , root , groups )
10292 grp := result ["ui" ]
10393 if grp == nil {
10494 t .Fatal ("expected ui group to exist" )
@@ -113,7 +103,7 @@ func TestGetPackageGroups_HandlesMultiLevelGlobs(t *testing.T) {
113103}
114104
115105func TestGetPackageGroups_HandlesMultipleIncludePatterns (t * testing.T ) {
116- infos := makeInfos ( "/repo" , map [string ]string {
106+ infos := testutil . MakePackageInfos ( root , map [string ]string {
117107 "packages/foo" : "foo" ,
118108 "libs/bar" : "bar" ,
119109 "other/baz" : "baz" ,
@@ -124,7 +114,7 @@ func TestGetPackageGroups_HandlesMultipleIncludePatterns(t *testing.T) {
124114 Include : []string {"packages/*" , "libs/*" },
125115 },
126116 }
127- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
117+ result := monorepo .GetPackageGroups (infos , root , groups )
128118 grp := result ["mixed" ]
129119 if grp == nil {
130120 t .Fatal ("expected mixed group to exist" )
@@ -139,7 +129,7 @@ func TestGetPackageGroups_HandlesMultipleIncludePatterns(t *testing.T) {
139129}
140130
141131func TestGetPackageGroups_HandlesExcludePatterns (t * testing.T ) {
142- infos := makeInfos ( "/repo" , map [string ]string {
132+ infos := testutil . MakePackageInfos ( root , map [string ]string {
143133 "packages/foo" : "foo" ,
144134 "packages/bar" : "bar" ,
145135 "packages/internal" : "internal" ,
@@ -151,7 +141,7 @@ func TestGetPackageGroups_HandlesExcludePatterns(t *testing.T) {
151141 Exclude : []string {"packages/internal" },
152142 },
153143 }
154- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
144+ result := monorepo .GetPackageGroups (infos , root , groups )
155145 grp := result ["public" ]
156146 if grp == nil {
157147 t .Fatal ("expected public group to exist" )
@@ -166,7 +156,7 @@ func TestGetPackageGroups_HandlesExcludePatterns(t *testing.T) {
166156}
167157
168158func TestGetPackageGroups_HandlesGlobExclude (t * testing.T ) {
169- infos := makeInfos ( "/repo" , map [string ]string {
159+ infos := testutil . MakePackageInfos ( root , map [string ]string {
170160 "packages/ui/button" : "ui-button" ,
171161 "packages/ui/input" : "ui-input" ,
172162 "packages/core/utils" : "core-utils" ,
@@ -178,7 +168,7 @@ func TestGetPackageGroups_HandlesGlobExclude(t *testing.T) {
178168 Exclude : []string {"packages/core/*" },
179169 },
180170 }
181- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
171+ result := monorepo .GetPackageGroups (infos , root , groups )
182172 grp := result ["non-core" ]
183173 if grp == nil {
184174 t .Fatal ("expected non-core group to exist" )
@@ -193,7 +183,7 @@ func TestGetPackageGroups_HandlesGlobExclude(t *testing.T) {
193183}
194184
195185func TestGetPackageGroups_OmitsEmptyGroups (t * testing.T ) {
196- infos := makeInfos ( "/repo" , map [string ]string {
186+ infos := testutil . MakePackageInfos ( root , map [string ]string {
197187 "packages/foo" : "foo" ,
198188 })
199189 groups := []types.VersionGroupOptions {
@@ -202,7 +192,7 @@ func TestGetPackageGroups_OmitsEmptyGroups(t *testing.T) {
202192 Include : []string {"nonexistent/*" },
203193 },
204194 }
205- result := monorepo .GetPackageGroups (infos , "/repo" , groups )
195+ result := monorepo .GetPackageGroups (infos , root , groups )
206196 grp := result ["empty" ]
207197 if grp == nil {
208198 t .Fatal ("expected empty group key to exist" )
0 commit comments