2424 - append: test`
2525 ) ;
2626
27- const result = await runUpgradeTasks ( ) ;
27+ const result = await runUpgradeTasks ( undefined ) ;
2828
2929 expect ( result . didRun ) . toBeTruthy ( ) ;
3030 expect ( mockRunTask ) . toHaveBeenCalledWith ( {
@@ -52,13 +52,13 @@ tasks:
5252 - append: test`
5353 ) ;
5454
55- const result = await runUpgradeTasks ( ) ;
55+ const result = await runUpgradeTasks ( undefined ) ;
5656
5757 expect ( result . didRun ) . toBeTruthy ( ) ;
5858 expect ( mockRunTask ) . not . toHaveBeenCalled ( ) ;
5959 } ) ;
6060 it ( 'should handle not finding upgrade.yml' , async ( ) => {
61- const result = await runUpgradeTasks ( ) ;
61+ const result = await runUpgradeTasks ( undefined ) ;
6262
6363 expect ( result . didRun ) . toBeFalsy ( ) ;
6464 } ) ;
6767 path . join ( getProjectPath ( ) , '.upgrade/upgrade.yml' ) ,
6868 'random'
6969 ) ;
70- const result = await runUpgradeTasks ( ) ;
70+ const result = await runUpgradeTasks ( undefined ) ;
7171
7272 expect ( result . didRun ) . toBeFalsy ( ) ;
7373 } ) ;
@@ -82,11 +82,69 @@ tasks:
8282 - append: test`
8383 ) ;
8484
85- const result = await runUpgradeTasks ( ) ;
85+ const result = await runUpgradeTasks ( undefined ) ;
8686
8787 expect ( result . didRun ) . toBeTruthy ( ) ;
8888 if ( result . didRun ) {
8989 expect ( result . failedTaskCount ) . toBe ( 1 ) ;
9090 }
9191 } ) ;
92+ it ( 'should execute upgrade.yml imports' , async ( ) => {
93+ mockFs . writeFileSync ( '/oldProject/path/some.file' , 'random' ) ;
94+ mockFs . writeFileSync (
95+ path . join ( getProjectPath ( ) , '.upgrade/upgrade.yml' ) ,
96+ `
97+ imports:
98+ - path
99+ - path/some.file`
100+ ) ;
101+
102+ const result = await runUpgradeTasks ( '/oldProject' ) ;
103+
104+ expect ( result . didRun ) . toBeTruthy ( ) ;
105+ expect ( mockFs . readFileSync ( getProjectPath ( ) + '/path/some.file' ) ) . toBe (
106+ 'random'
107+ ) ;
108+ } ) ;
109+ it ( 'should skip non existing upgrade.yml imports' , async ( ) => {
110+ mockFs . writeFileSync (
111+ path . join ( getProjectPath ( ) , '.upgrade/upgrade.yml' ) ,
112+ `
113+ imports:
114+ - path/some.file`
115+ ) ;
116+ mockFs . lstatSync . mockClear ( ) ;
117+ const result = await runUpgradeTasks ( '/oldProject' ) ;
118+
119+ expect ( result . didRun ) . toBeTruthy ( ) ;
120+ expect ( mockFs . lstatSync ) . not . toHaveBeenCalled ( ) ;
121+ } ) ;
122+ it ( 'should skip when no old project path specified' , async ( ) => {
123+ mockFs . writeFileSync (
124+ path . join ( getProjectPath ( ) , '.upgrade/upgrade.yml' ) ,
125+ `
126+ imports:
127+ - path/some.file`
128+ ) ;
129+ mockFs . lstatSync . mockClear ( ) ;
130+ const result = await runUpgradeTasks ( undefined ) ;
131+
132+ expect ( result . didRun ) . toBeTruthy ( ) ;
133+ expect ( mockFs . lstatSync ) . not . toHaveBeenCalled ( ) ;
134+ } ) ;
135+ it ( 'should handle copy error' , async ( ) => {
136+ mockFs . writeFileSync ( '/oldProject/path/some.file' , 'random' ) ;
137+ mockFs . writeFileSync (
138+ path . join ( getProjectPath ( ) , '.upgrade/upgrade.yml' ) ,
139+ `
140+ imports:
141+ - path/some.file`
142+ ) ;
143+ mockFs . copyFile . mockImplementationOnce (
144+ ( from : string , to : string , cb : CallableFunction ) => {
145+ cb ( new Error ( 'random' ) ) ;
146+ }
147+ ) ;
148+ await expect ( runUpgradeTasks ( '/oldProject' ) ) . rejects . toThrow ( 'random' ) ;
149+ } ) ;
92150} ) ;
0 commit comments