@@ -18,7 +18,7 @@ describe(commands.PROJECT_AZUREDEVOPS_PIPELINE_ADD, () => {
1818 let log : any [ ] ;
1919 let logger : Logger ;
2020 let commandInfo : CommandInfo ;
21- const projectPath : string = ' test-project';
21+ const projectPath : string = path . resolve ( '/fake/path/to/ test-project') ;
2222
2323 before ( ( ) => {
2424 sinon . stub ( telemetry , 'trackEvent' ) . resolves ( ) ;
@@ -66,38 +66,38 @@ describe(commands.PROJECT_AZUREDEVOPS_PIPELINE_ADD, () => {
6666 } ) ;
6767
6868 it ( 'creates a default workflow with specifying options' , async ( ) => {
69- sinon . stub ( command as any , 'getProjectRoot' ) . returns ( path . join ( process . cwd ( ) , projectPath ) ) ;
69+ sinon . stub ( command as any , 'getProjectRoot' ) . returns ( projectPath ) ;
7070
7171 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( fakePath ) => {
72- if ( fakePath . toString ( ) . endsWith ( 'pipelines' ) ) {
72+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' , 'pipelines' ) ) {
7373 return true ;
7474 }
7575
7676 return false ;
7777 } ) ;
7878
79- sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
80- if ( path . toString ( ) . endsWith ( 'package.json' ) && options === 'utf-8' ) {
79+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( fakePath , options ) => {
80+ if ( fakePath . toString ( ) === path . join ( projectPath , 'package.json' ) && options === 'utf-8' ) {
8181 return '{"name": "test"}' ;
8282 }
8383
84- return '' ;
84+ throw `Invalid path: ${ fakePath } ` ;
8585 } ) ;
8686
87- sinon . stub ( fs , 'mkdirSync' ) . callsFake ( ( path , options ) => {
88- if ( path . toString ( ) . endsWith ( '.azuredevops' ) && ( options as fs . MakeDirectoryOptions ) . recursive ) {
89- return ` ${ projectPath } / .azuredevops` ;
87+ sinon . stub ( fs , 'mkdirSync' ) . callsFake ( ( fakePath , options ) => {
88+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' ) && ( options as fs . MakeDirectoryOptions ) . recursive ) {
89+ return path . join ( projectPath , ' .azuredevops' ) ;
9090 }
9191
92- return '' ;
92+ throw `Invalid path: ${ fakePath } ` ;
9393 } ) ;
9494
9595 sinon . stub ( command as any , 'getProjectVersion' ) . returns ( '1.16.0' ) ;
9696
9797 const writeFileSyncStub : sinon . SinonStub = sinon . stub ( fs , 'writeFileSync' ) . resolves ( { } ) ;
9898
9999 await command . action ( logger , { options : { name : 'test' , branchName : 'dev' , skipFeatureDeployment : true , loginMethod : 'user' , scope : 'sitecollection' , siteUrl : 'https://contoso.sharepoint.com/sites/project' } } as any ) ;
100- assert ( writeFileSyncStub . calledWith ( path . join ( process . cwd ( ) , projectPath , '/ .azuredevops' , 'pipelines' , 'deploy-spfx-solution.yml' ) ) , 'workflow file not created' ) ;
100+ assert ( writeFileSyncStub . calledWith ( path . resolve ( path . join ( projectPath , '.azuredevops' , 'pipelines' , 'deploy-spfx-solution.yml' ) ) ) , 'workflow file not created' ) ;
101101 } ) ;
102102
103103 it ( 'fails validation if loginMethod is not valid type' , async ( ) => {
@@ -133,84 +133,84 @@ describe(commands.PROJECT_AZUREDEVOPS_PIPELINE_ADD, () => {
133133 } ) ;
134134
135135 it ( 'creates a default workflow (debug)' , async ( ) => {
136- sinon . stub ( command as any , 'getProjectRoot' ) . returns ( path . join ( process . cwd ( ) , projectPath ) ) ;
136+ sinon . stub ( command as any , 'getProjectRoot' ) . returns ( projectPath ) ;
137137 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( fakePath ) => {
138- if ( fakePath . toString ( ) . endsWith ( '.azuredevops' ) ) {
138+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' ) ) {
139139 return true ;
140140 }
141- else if ( fakePath . toString ( ) . endsWith ( 'pipelines' ) ) {
141+ else if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' , 'pipelines' ) ) {
142142 return true ;
143143 }
144144
145- return false ;
145+ throw `Invalid path: ${ fakePath } ` ;
146146 } ) ;
147147
148- sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
149- if ( path . toString ( ) . endsWith ( 'package.json' ) && options === 'utf-8' ) {
148+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( filePath , options ) => {
149+ if ( filePath . toString ( ) === path . join ( projectPath , 'package.json' ) && options === 'utf-8' ) {
150150 return '{"name": "test"}' ;
151151 }
152152
153- return '' ;
153+ throw `Invalid path: ${ filePath } ` ;
154154 } ) ;
155155
156156 sinon . stub ( command as any , 'getProjectVersion' ) . returns ( '1.21.1' ) ;
157157
158158 const writeFileSyncStub : sinon . SinonStub = sinon . stub ( fs , 'writeFileSync' ) . resolves ( { } ) ;
159159
160160 await command . action ( logger , { options : { debug : true } } as any ) ;
161- assert ( writeFileSyncStub . calledWith ( path . join ( process . cwd ( ) , projectPath , '/ .azuredevops' , 'pipelines' , 'deploy-spfx-solution.yml' ) ) , 'workflow file not created' ) ;
161+ assert ( writeFileSyncStub . calledWith ( path . resolve ( path . join ( projectPath , '.azuredevops' , 'pipelines' , 'deploy-spfx-solution.yml' ) ) ) , 'workflow file not created' ) ;
162162 } ) ;
163163
164164 it ( 'handles error with unknown minor version of SPFx when missing minor version' , async ( ) => {
165- sinon . stub ( command as any , 'getProjectRoot' ) . returns ( path . join ( process . cwd ( ) , projectPath ) ) ;
165+ sinon . stub ( command as any , 'getProjectRoot' ) . returns ( projectPath ) ;
166166
167- sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
168- if ( path . toString ( ) . endsWith ( 'package.json' ) && options === 'utf-8' ) {
167+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( filePath , options ) => {
168+ if ( filePath . toString ( ) === path . join ( projectPath , 'package.json' ) && options === 'utf-8' ) {
169169 return '{"name": "test"}' ;
170170 }
171171
172- return '' ;
172+ throw `Invalid path: ${ filePath } ` ;
173173 } ) ;
174174
175175 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( fakePath ) => {
176- if ( fakePath . toString ( ) . endsWith ( '.azuredevops' ) ) {
176+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' ) ) {
177177 return true ;
178178 }
179- else if ( fakePath . toString ( ) . endsWith ( 'pipelines' ) ) {
179+ else if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' , 'pipelines' ) ) {
180180 return true ;
181181 }
182182
183- return false ;
183+ throw `Invalid path: ${ fakePath } ` ;
184184 } ) ;
185185
186186 sinon . stub ( command as any , 'getProjectVersion' ) . returns ( '' ) ;
187187
188188 sinon . stub ( fs , 'writeFileSync' ) . throws ( new Error ( 'writeFileSync failed' ) ) ;
189189
190190 await assert . rejects ( command . action ( logger , { options : { } } as any ) ,
191- new CommandError ( 'Unable to determine the version of the current SharePoint Framework project. Could not find the correct version based on @microsoft/generator-sharepoint property in the .yo-rc.json file.' ) ) ;
191+ new CommandError ( 'Unable to determine the version of the current SharePoint Framework project. Could not find the correct version based on the version property in the .yo-rc.json file.' ) ) ;
192192 } ) ;
193193
194194 it ( 'handles error with not found node version' , async ( ) => {
195- sinon . stub ( command as any , 'getProjectRoot' ) . returns ( path . join ( process . cwd ( ) , projectPath ) ) ;
195+ sinon . stub ( command as any , 'getProjectRoot' ) . returns ( projectPath ) ;
196196
197- sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
198- if ( path . toString ( ) . endsWith ( 'package.json' ) && options === 'utf-8' ) {
197+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( filePath , options ) => {
198+ if ( filePath . toString ( ) === path . join ( projectPath , 'package.json' ) && options === 'utf-8' ) {
199199 return '{"name": "test"}' ;
200200 }
201201
202- return '' ;
202+ throw `Invalid path: ${ filePath } ` ;
203203 } ) ;
204204
205205 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( fakePath ) => {
206- if ( fakePath . toString ( ) . endsWith ( '.azuredevops' ) ) {
206+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' ) ) {
207207 return true ;
208208 }
209- else if ( fakePath . toString ( ) . endsWith ( 'pipelines' ) ) {
209+ else if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' , 'pipelines' ) ) {
210210 return true ;
211211 }
212212
213- return false ;
213+ throw `Invalid path: ${ fakePath } ` ;
214214 } ) ;
215215
216216 sinon . stub ( command as any , 'getProjectVersion' ) . returns ( '99.99.99' ) ;
@@ -222,25 +222,25 @@ describe(commands.PROJECT_AZUREDEVOPS_PIPELINE_ADD, () => {
222222 } ) ;
223223
224224 it ( 'handles unexpected error' , async ( ) => {
225- sinon . stub ( command as any , 'getProjectRoot' ) . returns ( path . join ( process . cwd ( ) , projectPath ) ) ;
225+ sinon . stub ( command as any , 'getProjectRoot' ) . returns ( projectPath ) ;
226226
227- sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
228- if ( path . toString ( ) . endsWith ( 'package.json' ) && options === 'utf-8' ) {
227+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( filePath , options ) => {
228+ if ( filePath . toString ( ) === path . join ( projectPath , 'package.json' ) && options === 'utf-8' ) {
229229 return '{"name": "test"}' ;
230230 }
231231
232- return '' ;
232+ throw `Invalid path: ${ filePath } ` ;
233233 } ) ;
234234
235235 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( fakePath ) => {
236- if ( fakePath . toString ( ) . endsWith ( '.azuredevops' ) ) {
236+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' ) ) {
237237 return true ;
238238 }
239- else if ( fakePath . toString ( ) . endsWith ( 'pipelines' ) ) {
239+ else if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' , 'pipelines' ) ) {
240240 return true ;
241241 }
242242
243- return false ;
243+ throw `Invalid path: ${ fakePath } ` ;
244244 } ) ;
245245
246246 sinon . stub ( command as any , 'getProjectVersion' ) . returns ( '1.21.1' ) ;
@@ -252,25 +252,25 @@ describe(commands.PROJECT_AZUREDEVOPS_PIPELINE_ADD, () => {
252252 } ) ;
253253
254254 it ( 'handles unexpected non-error value' , async ( ) => {
255- sinon . stub ( command as any , 'getProjectRoot' ) . returns ( path . join ( process . cwd ( ) , projectPath ) ) ;
255+ sinon . stub ( command as any , 'getProjectRoot' ) . returns ( projectPath ) ;
256256
257- sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
258- if ( path . toString ( ) . endsWith ( 'package.json' ) && options === 'utf-8' ) {
257+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( filePath , options ) => {
258+ if ( filePath . toString ( ) === path . join ( projectPath , 'package.json' ) && options === 'utf-8' ) {
259259 return '{"name": "test"}' ;
260260 }
261261
262- return '' ;
262+ throw `Invalid path: ${ filePath } ` ;
263263 } ) ;
264264
265265 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( fakePath ) => {
266- if ( fakePath . toString ( ) . endsWith ( '.azuredevops' ) ) {
266+ if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' ) ) {
267267 return true ;
268268 }
269- else if ( fakePath . toString ( ) . endsWith ( 'pipelines' ) ) {
269+ else if ( fakePath . toString ( ) === path . join ( projectPath , '.azuredevops' , 'pipelines' ) ) {
270270 return true ;
271271 }
272272
273- return false ;
273+ throw `Invalid path: ${ fakePath } ` ;
274274 } ) ;
275275
276276 sinon . stub ( command as any , 'getProjectVersion' ) . returns ( '1.21.1' ) ;
0 commit comments