@@ -187,6 +187,82 @@ describe(commands.PROJECT_UPGRADE, () => {
187187 } ) ;
188188 } ) ;
189189
190+ it ( 'determines correct version from .yo-rc.json for an SP2019 project built using generator v1.10' , ( ) => {
191+ const originalExistsSync = fs . existsSync ;
192+ sinon . stub ( fs , 'existsSync' ) . callsFake ( ( path ) => {
193+ if ( path . toString ( ) . endsWith ( '.yo-rc.json' ) ) {
194+ return true ;
195+ }
196+ else {
197+ return originalExistsSync ( path ) ;
198+ }
199+ } ) ;
200+ const originalReadFileSync = fs . readFileSync ;
201+ const yoRcJson = `{
202+ "@microsoft/generator-sharepoint": {
203+ "isCreatingSolution": true,
204+ "environment": "onprem19",
205+ "version": "1.10.0",
206+ "libraryName": "spfx-1100-sp-2019",
207+ "libraryId": "04b9054d-025f-4e1a-9a85-732c57213b2f",
208+ "packageManager": "npm",
209+ "componentType": "webpart"
210+ }
211+ }` ;
212+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
213+ if ( path . toString ( ) . endsWith ( '.yo-rc.json' ) ) {
214+ return yoRcJson ;
215+ }
216+ else {
217+ return originalReadFileSync ( path , options ) ;
218+ }
219+ } ) ;
220+ const getProjectVersionSpy = sinon . spy ( command as any , 'getProjectVersion' ) ;
221+
222+ cmdInstance . action = command . action ( ) ;
223+ cmdInstance . action ( { options : { toVersion : '1.4.1' } } , ( err ?: any ) => {
224+ assert . strictEqual ( getProjectVersionSpy . lastCall . returnValue , '1.4.1' ) ;
225+ } ) ;
226+ } ) ;
227+
228+ it ( 'determines correct version from .yo-rc.json for an SP2016 project built using generator v1.10' , ( ) => {
229+ const originalExistsSync = fs . existsSync ;
230+ sinon . stub ( fs , 'existsSync' ) . callsFake ( ( path ) => {
231+ if ( path . toString ( ) . endsWith ( '.yo-rc.json' ) ) {
232+ return true ;
233+ }
234+ else {
235+ return originalExistsSync ( path ) ;
236+ }
237+ } ) ;
238+ const originalReadFileSync = fs . readFileSync ;
239+ const yoRcJson = `{
240+ "@microsoft/generator-sharepoint": {
241+ "isCreatingSolution": true,
242+ "environment": "onprem",
243+ "version": "1.10.0",
244+ "libraryName": "spfx-1100-sp-2016",
245+ "libraryId": "300833cb-9264-4b53-8179-2eaf105c1d41",
246+ "packageManager": "npm",
247+ "componentType": "webpart"
248+ }
249+ }` ;
250+ sinon . stub ( fs , 'readFileSync' ) . callsFake ( ( path , options ) => {
251+ if ( path . toString ( ) . endsWith ( '.yo-rc.json' ) ) {
252+ return yoRcJson ;
253+ }
254+ else {
255+ return originalReadFileSync ( path , options ) ;
256+ }
257+ } ) ;
258+ const getProjectVersionSpy = sinon . spy ( command as any , 'getProjectVersion' ) ;
259+
260+ cmdInstance . action = command . action ( ) ;
261+ cmdInstance . action ( { options : { toVersion : '1.1.0' } } , ( err ?: any ) => {
262+ assert . strictEqual ( getProjectVersionSpy . lastCall . returnValue , '1.1.0' ) ;
263+ } ) ;
264+ } ) ;
265+
190266 it ( 'tries to determine the current version from package.json if .yo-rc.json doesn\'t exist' , ( ) => {
191267 const originalExistsSync = fs . existsSync ;
192268 sinon . stub ( fs , 'existsSync' ) . callsFake ( ( path ) => {
0 commit comments