1
1
import path from "path" ;
2
2
import check from "../INCORRECT_REPOSITORY_FIELD" ;
3
- import { getWS , getFakeWS } from "../../test-helpers" ;
3
+ import { getWS , getFakeWS , getFakeString } from "../../test-helpers" ;
4
4
5
5
describe ( "incorrect repository field" , ( ) => {
6
6
describe ( "github" , ( ) => {
7
7
it ( "should work" , ( ) => {
8
8
let ws = getWS ( ) ;
9
9
let rootWorkspace = getFakeWS ( "root" ) ;
10
+ let defaultBranch = `b${ getFakeString ( 5 ) } ` ;
10
11
11
12
( rootWorkspace . packageJson as any ) . repository =
12
13
"https://github.com/Thinkmill/manypkg" ;
@@ -15,27 +16,30 @@ describe("incorrect repository field", () => {
15
16
workspace . dir = path . join ( __dirname , "packages/no-repository-field" ) ;
16
17
ws . set ( "depends-on-one" , workspace ) ;
17
18
ws . set ( "root" , rootWorkspace ) ;
18
- let errors = check . validate ( workspace , ws , rootWorkspace ) ;
19
+ let errors = check . validate ( workspace , ws , rootWorkspace , {
20
+ defaultBranch
21
+ } ) ;
19
22
expect ( errors . map ( ( { workspace, ...x } : any ) => x ) )
20
23
. toMatchInlineSnapshot ( `
21
24
Array [
22
25
Object {
23
- "correctRepositoryField": "https://github.com/Thinkmill/manypkg/tree/master /packages/no-repository-field",
26
+ "correctRepositoryField": "https://github.com/Thinkmill/manypkg/tree/${ defaultBranch } /packages/no-repository-field",
24
27
"currentRepositoryField": undefined,
25
28
"type": "INCORRECT_REPOSITORY_FIELD",
26
29
},
27
30
]
28
31
` ) ;
29
32
30
- check . fix ( errors [ 0 ] ) ;
33
+ check . fix ( errors [ 0 ] , { } ) ;
31
34
32
35
expect ( ( workspace . packageJson as any ) . repository ) . toBe (
33
- " https://github.com/Thinkmill/manypkg/tree/master /packages/no-repository-field"
36
+ ` https://github.com/Thinkmill/manypkg/tree/${ defaultBranch } /packages/no-repository-field`
34
37
) ;
35
38
} ) ;
36
39
it ( "should fix root in a different format" , ( ) => {
37
40
let ws = getWS ( ) ;
38
41
let rootWorkspace = getFakeWS ( "root" ) ;
42
+ let defaultBranch = `b${ getFakeString ( 5 ) } ` ;
39
43
40
44
( rootWorkspace . packageJson as any ) . repository =
41
45
"https://github.com/Thinkmill/manypkg.git" ;
@@ -45,7 +49,9 @@ describe("incorrect repository field", () => {
45
49
workspace . dir = path . join ( __dirname , "packages/no-repository-field" ) ;
46
50
ws . set ( "depends-on-one" , workspace ) ;
47
51
ws . set ( "root" , rootWorkspace ) ;
48
- let errors = check . validate ( rootWorkspace , ws , rootWorkspace ) ;
52
+ let errors = check . validate ( rootWorkspace , ws , rootWorkspace , {
53
+ defaultBranch
54
+ } ) ;
49
55
expect ( errors . map ( ( { workspace, ...x } : any ) => x ) )
50
56
. toMatchInlineSnapshot ( `
51
57
Array [
@@ -57,7 +63,7 @@ describe("incorrect repository field", () => {
57
63
]
58
64
` ) ;
59
65
60
- check . fix ( errors [ 0 ] ) ;
66
+ check . fix ( errors [ 0 ] , { } ) ;
61
67
62
68
expect ( ( rootWorkspace . packageJson as any ) . repository ) . toBe (
63
69
"https://github.com/Thinkmill/manypkg"
@@ -66,6 +72,7 @@ describe("incorrect repository field", () => {
66
72
it ( "should do nothing if already in good format" , ( ) => {
67
73
let ws = getWS ( ) ;
68
74
let rootWorkspace = getFakeWS ( "root" ) ;
75
+ let defaultBranch = `b${ getFakeString ( 5 ) } ` ;
69
76
70
77
( rootWorkspace . packageJson as any ) . repository =
71
78
"https://github.com/Thinkmill/manypkg" ;
@@ -75,7 +82,9 @@ describe("incorrect repository field", () => {
75
82
workspace . dir = path . join ( __dirname , "packages/no-repository-field" ) ;
76
83
ws . set ( "depends-on-one" , workspace ) ;
77
84
ws . set ( "root" , rootWorkspace ) ;
78
- let errors = check . validate ( rootWorkspace , ws , rootWorkspace ) ;
85
+ let errors = check . validate ( rootWorkspace , ws , rootWorkspace , {
86
+ defaultBranch
87
+ } ) ;
79
88
expect ( errors . map ( ( { workspace, ...x } : any ) => x ) ) . toMatchInlineSnapshot (
80
89
`Array []`
81
90
) ;
@@ -90,6 +99,7 @@ describe("incorrect repository field", () => {
90
99
it ( "should work" , ( ) => {
91
100
let ws = getWS ( ) ;
92
101
let rootWorkspace = getFakeWS ( "root" ) ;
102
+ let defaultBranch = `b${ getFakeString ( 5 ) } ` ;
93
103
94
104
( rootWorkspace . packageJson as any ) . repository =
95
105
"https://dev.azure.com/Thinkmill/monorepos/_git/manypkg" ;
@@ -98,27 +108,30 @@ describe("incorrect repository field", () => {
98
108
workspace . dir = path . join ( __dirname , "packages/no-repository-field" ) ;
99
109
ws . set ( "depends-on-one" , workspace ) ;
100
110
ws . set ( "root" , rootWorkspace ) ;
101
- let errors = check . validate ( workspace , ws , rootWorkspace ) ;
111
+ let errors = check . validate ( workspace , ws , rootWorkspace , {
112
+ defaultBranch
113
+ } ) ;
102
114
expect ( errors . map ( ( { workspace, ...x } : any ) => x ) )
103
115
. toMatchInlineSnapshot ( `
104
116
Array [
105
117
Object {
106
- "correctRepositoryField": "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg?path=packages/no-repository-field&version=GBmaster &_a=contents",
118
+ "correctRepositoryField": "https://dev.azure.com/Thinkmill/monorepos/_git/manypkg?path=packages/no-repository-field&version=GB ${ defaultBranch } &_a=contents",
107
119
"currentRepositoryField": undefined,
108
120
"type": "INCORRECT_REPOSITORY_FIELD",
109
121
},
110
122
]
111
123
` ) ;
112
124
113
- check . fix ( errors [ 0 ] ) ;
125
+ check . fix ( errors [ 0 ] , { } ) ;
114
126
115
127
expect ( ( workspace . packageJson as any ) . repository ) . toBe (
116
- " https://dev.azure.com/Thinkmill/monorepos/_git/manypkg?path=packages/no-repository-field&version=GBmaster &_a=contents"
128
+ ` https://dev.azure.com/Thinkmill/monorepos/_git/manypkg?path=packages/no-repository-field&version=GB ${ defaultBranch } &_a=contents`
117
129
) ;
118
130
} ) ;
119
131
it ( "should fix root in a different format" , ( ) => {
120
132
let ws = getWS ( ) ;
121
133
let rootWorkspace = getFakeWS ( "root" ) ;
134
+ let defaultBranch = `b${ getFakeString ( 5 ) } ` ;
122
135
123
136
( rootWorkspace . packageJson as any ) . repository =
124
137
"https://[email protected] /Thinkmill/monorepos/_git/manypkg" ;
@@ -128,7 +141,9 @@ describe("incorrect repository field", () => {
128
141
workspace . dir = path . join ( __dirname , "packages/no-repository-field" ) ;
129
142
ws . set ( "depends-on-one" , workspace ) ;
130
143
ws . set ( "root" , rootWorkspace ) ;
131
- let errors = check . validate ( rootWorkspace , ws , rootWorkspace ) ;
144
+ let errors = check . validate ( rootWorkspace , ws , rootWorkspace , {
145
+ defaultBranch
146
+ } ) ;
132
147
expect ( errors . map ( ( { workspace, ...x } : any ) => x ) )
133
148
. toMatchInlineSnapshot ( `
134
149
Array [
@@ -140,7 +155,7 @@ describe("incorrect repository field", () => {
140
155
]
141
156
` ) ;
142
157
143
- check . fix ( errors [ 0 ] ) ;
158
+ check . fix ( errors [ 0 ] , { } ) ;
144
159
145
160
expect ( ( rootWorkspace . packageJson as any ) . repository ) . toBe (
146
161
"https://dev.azure.com/Thinkmill/monorepos/_git/manypkg"
@@ -149,6 +164,7 @@ describe("incorrect repository field", () => {
149
164
it ( "should do nothing if already in good format" , ( ) => {
150
165
let ws = getWS ( ) ;
151
166
let rootWorkspace = getFakeWS ( "root" ) ;
167
+ let defaultBranch = `b${ getFakeString ( 5 ) } ` ;
152
168
153
169
( rootWorkspace . packageJson as any ) . repository =
154
170
"https://dev.azure.com/Thinkmill/monorepos/_git/manypkg" ;
@@ -158,7 +174,9 @@ describe("incorrect repository field", () => {
158
174
workspace . dir = path . join ( __dirname , "packages/no-repository-field" ) ;
159
175
ws . set ( "depends-on-one" , workspace ) ;
160
176
ws . set ( "root" , rootWorkspace ) ;
161
- let errors = check . validate ( rootWorkspace , ws , rootWorkspace ) ;
177
+ let errors = check . validate ( rootWorkspace , ws , rootWorkspace , {
178
+ defaultBranch
179
+ } ) ;
162
180
expect ( errors . map ( ( { workspace, ...x } : any ) => x ) ) . toMatchInlineSnapshot (
163
181
`Array []`
164
182
) ;
0 commit comments