@@ -39,43 +39,50 @@ describe(ChangeFiles.name, () => {
3939 } ) ;
4040
4141 describe ( ChangeFiles . prototype . getAllChangeFilesAsync . name , ( ) => {
42+ const leafChangeDir : string = `${ __dirname } /leafChange` ;
43+ const noChangeDir : string = `${ __dirname } /noChange` ;
44+ const categorizedChangesDir : string = `${ __dirname } /categorizedChanges` ;
45+
4246 it ( 'returns correctly when there is one change file' , async ( ) => {
43- const changesPath : string = `${ __dirname } /leafChange` ;
4447 const changeFiles : ChangeFiles = new ChangeFiles ( {
45- changesFolder : changesPath
48+ changesFolder : leafChangeDir
4649 } as unknown as RushConfiguration ) ;
47- const expectedPath : string = Path . convertToSlashes ( `${ changesPath } /change1.json` ) ;
50+ const expectedPath : string = Path . convertToSlashes ( `${ leafChangeDir } /change1.json` ) ;
4851 await expect ( changeFiles . getAllChangeFilesAsync ( ) ) . resolves . toEqual ( [ expectedPath ] ) ;
4952 } ) ;
5053
5154 it ( 'returns empty array when no change files' , async ( ) => {
52- const changesPath : string = `${ __dirname } /noChange` ;
5355 const changeFiles : ChangeFiles = new ChangeFiles ( {
54- changesFolder : changesPath
56+ changesFolder : noChangeDir
5557 } as unknown as RushConfiguration ) ;
5658 await expect ( changeFiles . getAllChangeFilesAsync ( ) ) . resolves . toHaveLength ( 0 ) ;
5759 } ) ;
5860
5961 it ( 'returns correctly when change files are categorized' , async ( ) => {
60- const changesPath : string = `${ __dirname } /categorizedChanges` ;
6162 const changeFiles : ChangeFiles = new ChangeFiles ( {
62- changesFolder : changesPath
63+ changesFolder : categorizedChangesDir
6364 } as unknown as RushConfiguration ) ;
6465 const files : string [ ] = await changeFiles . getAllChangeFilesAsync ( ) ;
6566 expect ( files ) . toHaveLength ( 3 ) ;
6667
67- const expectedPathA : string = Path . convertToSlashes ( `${ changesPath } /@ms/a/changeA.json` ) ;
68- const expectedPathB : string = Path . convertToSlashes ( `${ changesPath } /@ms/b/changeB.json` ) ;
69- const expectedPathC : string = Path . convertToSlashes ( `${ changesPath } /changeC.json` ) ;
68+ const expectedPathA : string = Path . convertToSlashes ( `${ categorizedChangesDir } /@ms/a/changeA.json` ) ;
69+ const expectedPathB : string = Path . convertToSlashes ( `${ categorizedChangesDir } /@ms/b/changeB.json` ) ;
70+ const expectedPathC : string = Path . convertToSlashes ( `${ categorizedChangesDir } /changeC.json` ) ;
7071 expect ( files ) . toContain ( expectedPathA ) ;
7172 expect ( files ) . toContain ( expectedPathB ) ;
7273 expect ( files ) . toContain ( expectedPathC ) ;
7374 } ) ;
7475 } ) ;
7576
7677 describe ( ChangeFiles . prototype . validateAsync . name , ( ) => {
78+ const leafChangeFile : string = `${ __dirname } /leafChange/change1.json` ;
79+ const hotfixChangeFile : string = `${ __dirname } /multipleHotfixChanges/change1.json` ;
80+ const verifyChangesFile : string = `${ __dirname } /verifyChanges/changes.json` ;
81+ const categorizedChangeFileA : string = `${ __dirname } /categorizedChanges/@ms/a/changeA.json` ;
82+ const categorizedChangeFileB : string = `${ __dirname } /categorizedChanges/@ms/b/changeB.json` ;
83+ const categorizedChangeFileC : string = `${ __dirname } /categorizedChanges/changeC.json` ;
84+
7785 it ( 'throws when there is a patch in a hotfix branch.' , async ( ) => {
78- const changeFile : string = `${ __dirname } /leafChange/change1.json` ;
7986 const changedPackages : string [ ] = [ 'd' ] ;
8087 await expect (
8188 new ChangeFiles ( {
@@ -85,73 +92,69 @@ describe(ChangeFiles.name, () => {
8592 }
8693 } as unknown as RushConfiguration ) . validateAsync ( {
8794 terminal,
88- filesToValidate : [ changeFile ] ,
95+ filesToValidate : [ leafChangeFile ] ,
8996 changedProjectNames : changedPackages
9097 } )
9198 ) . rejects . toThrow ( Error ) ;
9299 } ) ;
93100
94101 it ( 'allows a hotfix in a hotfix branch.' , async ( ) => {
95- const changeFile : string = `${ __dirname } /multipleHotfixChanges/change1.json` ;
96102 const changedPackages : string [ ] = [ 'a' ] ;
97103 await new ChangeFiles ( {
98104 ...rushConfiguration ,
99105 hotfixChangeEnabled : true
100106 } as unknown as RushConfiguration ) . validateAsync ( {
101107 terminal,
102- filesToValidate : [ changeFile ] ,
108+ filesToValidate : [ hotfixChangeFile ] ,
103109 changedProjectNames : changedPackages
104110 } ) ;
105111 } ) ;
106112
107113 it ( 'throws when there is any missing package.' , async ( ) => {
108- const changeFile : string = `${ __dirname } /verifyChanges/changes.json` ;
109114 const changedPackages : string [ ] = [ 'a' , 'b' , 'c' ] ;
110115 await expect (
111116 new ChangeFiles ( rushConfiguration ) . validateAsync ( {
112117 terminal,
113- filesToValidate : [ changeFile ] ,
118+ filesToValidate : [ verifyChangesFile ] ,
114119 changedProjectNames : changedPackages
115120 } )
116121 ) . rejects . toThrow ( Error ) ;
117122 } ) ;
118123
119124 it ( 'does not throw when there is no missing packages' , async ( ) => {
120- const changeFile : string = `${ __dirname } /verifyChanges/changes.json` ;
121125 const changedPackages : string [ ] = [ 'a' ] ;
122126 await new ChangeFiles ( rushConfiguration ) . validateAsync ( {
123127 terminal,
124- filesToValidate : [ changeFile ] ,
128+ filesToValidate : [ verifyChangesFile ] ,
125129 changedProjectNames : changedPackages
126130 } ) ;
127131 } ) ;
128132
129133 it ( 'throws when missing packages from categorized changes' , async ( ) => {
130- const changeFileA : string = `${ __dirname } /categorizedChanges/@ms/a/changeA.json` ;
131- const changeFileB : string = `${ __dirname } /categorizedChanges/@ms/b/changeB.json` ;
132134 const changedPackages : string [ ] = [ '@ms/a' , '@ms/b' , 'c' ] ;
133135 await expect (
134136 new ChangeFiles ( rushConfiguration ) . validateAsync ( {
135137 terminal,
136- filesToValidate : [ changeFileA , changeFileB ] ,
138+ filesToValidate : [ categorizedChangeFileA , categorizedChangeFileB ] ,
137139 changedProjectNames : changedPackages
138140 } )
139141 ) . rejects . toThrow ( Error ) ;
140142 } ) ;
141143
142144 it ( 'does not throw when no missing packages from categorized changes' , async ( ) => {
143- const changeFileA : string = `${ __dirname } /categorizedChanges/@ms/a/changeA.json` ;
144- const changeFileB : string = `${ __dirname } /categorizedChanges/@ms/b/changeB.json` ;
145- const changeFileC : string = `${ __dirname } /categorizedChanges/changeC.json` ;
146145 const changedPackages : string [ ] = [ '@ms/a' , '@ms/b' , 'c' ] ;
147146 await new ChangeFiles ( rushConfiguration ) . validateAsync ( {
148147 terminal,
149- filesToValidate : [ changeFileA , changeFileB , changeFileC ] ,
148+ filesToValidate : [ categorizedChangeFileA , categorizedChangeFileB , categorizedChangeFileC ] ,
150149 changedProjectNames : changedPackages
151150 } ) ;
152151 } ) ;
153152
154153 describe ( 'with strictChangefileValidation' , ( ) => {
154+ const nonexistentProjectChangeFile : string = `${ __dirname } /strictValidation/nonexistentProject.json` ;
155+ const nonMainLockstepChangeFile : string = `${ __dirname } /strictValidation/nonMainLockstep.json` ;
156+ const mainLockstepChangeFile : string = `${ __dirname } /strictValidation/mainLockstep.json` ;
157+
155158 let strictConfig : RushConfiguration ;
156159
157160 function createStrictConfig (
@@ -166,12 +169,11 @@ describe(ChangeFiles.name, () => {
166169 }
167170
168171 it ( 'throws when change file references a nonexistent project' , async ( ) => {
169- const changeFile : string = `${ __dirname } /strictValidation/nonexistentProject.json` ;
170172 strictConfig = createStrictConfig ( ( ) => undefined ) ;
171173 try {
172174 await new ChangeFiles ( strictConfig ) . validateAsync ( {
173175 terminal,
174- filesToValidate : [ changeFile ] ,
176+ filesToValidate : [ nonexistentProjectChangeFile ] ,
175177 changedProjectNames : [ 'nonexistent-package' ]
176178 } ) ;
177179 fail ( 'Expected validateAsync to throw' ) ;
@@ -185,7 +187,6 @@ describe(ChangeFiles.name, () => {
185187 } ) ;
186188
187189 it ( 'throws when change file references a non-main lockstep project' , async ( ) => {
188- const changeFile : string = `${ __dirname } /strictValidation/nonMainLockstep.json` ;
189190 strictConfig = createStrictConfig ( ( name : string ) => {
190191 if ( name === 'lockstep-secondary' ) {
191192 return {
@@ -202,7 +203,7 @@ describe(ChangeFiles.name, () => {
202203 try {
203204 await new ChangeFiles ( strictConfig ) . validateAsync ( {
204205 terminal,
205- filesToValidate : [ changeFile ] ,
206+ filesToValidate : [ nonMainLockstepChangeFile ] ,
206207 changedProjectNames : [ 'lockstep-secondary' ]
207208 } ) ;
208209 fail ( 'Expected validateAsync to throw' ) ;
@@ -216,7 +217,6 @@ describe(ChangeFiles.name, () => {
216217 } ) ;
217218
218219 it ( 'does not throw when change file references the main lockstep project' , async ( ) => {
219- const changeFile : string = `${ __dirname } /strictValidation/mainLockstep.json` ;
220220 strictConfig = createStrictConfig ( ( name : string ) => {
221221 if ( name === 'lockstep-main' ) {
222222 return {
@@ -232,13 +232,12 @@ describe(ChangeFiles.name, () => {
232232 } ) ;
233233 await new ChangeFiles ( strictConfig ) . validateAsync ( {
234234 terminal,
235- filesToValidate : [ changeFile ] ,
235+ filesToValidate : [ mainLockstepChangeFile ] ,
236236 changedProjectNames : [ 'lockstep-main' ]
237237 } ) ;
238238 } ) ;
239239
240240 it ( 'does not throw when change file references a lockstep project with no mainProject' , async ( ) => {
241- const changeFile : string = `${ __dirname } /strictValidation/mainLockstep.json` ;
242241 strictConfig = createStrictConfig ( ( name : string ) => {
243242 if ( name === 'lockstep-main' ) {
244243 return {
@@ -254,40 +253,40 @@ describe(ChangeFiles.name, () => {
254253 } ) ;
255254 await new ChangeFiles ( strictConfig ) . validateAsync ( {
256255 terminal,
257- filesToValidate : [ changeFile ] ,
256+ filesToValidate : [ mainLockstepChangeFile ] ,
258257 changedProjectNames : [ 'lockstep-main' ]
259258 } ) ;
260259 } ) ;
261260
262261 it ( 'does not throw when experiment is disabled' , async ( ) => {
263- const changeFile : string = `${ __dirname } /strictValidation/nonexistentProject.json` ;
264262 const config : RushConfiguration = {
265263 experimentsConfiguration : {
266264 configuration : { strictChangefileValidation : false }
267265 } as ExperimentsConfiguration
268266 } as unknown as RushConfiguration ;
269267 await new ChangeFiles ( config ) . validateAsync ( {
270268 terminal,
271- filesToValidate : [ changeFile ] ,
269+ filesToValidate : [ nonexistentProjectChangeFile ] ,
272270 changedProjectNames : [ 'nonexistent-package' ]
273271 } ) ;
274272 } ) ;
275273 } ) ;
276274 } ) ;
277275
278276 describe ( ChangeFiles . prototype . deleteAllAsync . name , ( ) => {
277+ const multipleChangeFilesDir : string = `${ __dirname } /multipleChangeFiles` ;
278+ const multipleHotfixChangesDir : string = `${ __dirname } /multipleHotfixChanges` ;
279+
279280 it ( 'delete all files when there are no prerelease packages' , async ( ) => {
280- const changesPath : string = `${ __dirname } /multipleChangeFiles` ;
281281 const changeFiles : ChangeFiles = new ChangeFiles ( {
282- changesFolder : changesPath
282+ changesFolder : multipleChangeFilesDir
283283 } as unknown as RushConfiguration ) ;
284284 await expect ( changeFiles . deleteAllAsync ( terminal , false ) ) . resolves . toEqual ( 3 ) ;
285285 } ) ;
286286
287287 it ( 'does not delete change files for package whose change logs do not get updated. ' , async ( ) => {
288- const changesPath : string = `${ __dirname } /multipleChangeFiles` ;
289288 const changeFiles : ChangeFiles = new ChangeFiles ( {
290- changesFolder : changesPath
289+ changesFolder : multipleChangeFilesDir
291290 } as unknown as RushConfiguration ) ;
292291 const updatedChangelogs : IChangelog [ ] = [
293292 {
@@ -303,9 +302,8 @@ describe(ChangeFiles.name, () => {
303302 } ) ;
304303
305304 it ( 'delete all files when there are hotfixes' , async ( ) => {
306- const changesPath : string = `${ __dirname } /multipleHotfixChanges` ;
307305 const changeFiles : ChangeFiles = new ChangeFiles ( {
308- changesFolder : changesPath
306+ changesFolder : multipleHotfixChangesDir
309307 } as unknown as RushConfiguration ) ;
310308 await expect ( changeFiles . deleteAllAsync ( terminal , false ) ) . resolves . toEqual ( 3 ) ;
311309 } ) ;
0 commit comments