@@ -71,7 +71,7 @@ function createTestInjector(
71
71
return testInjector ;
72
72
}
73
73
74
- describe . only ( "update command method tests" , ( ) => {
74
+ describe ( "update command method tests" , ( ) => {
75
75
describe ( "canExecute" , ( ) => {
76
76
it ( "calls platform service validate" , async ( ) => {
77
77
let validated = false ;
@@ -127,129 +127,64 @@ describe.only("update command method tests", () => {
127
127
sandbox . restore ( ) ;
128
128
} ) ;
129
129
130
- it ( "calls backup and executeCore" , async ( ) => {
131
- const testInjector = createTestInjector ( ) ;
132
- const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
133
- const executeCoreStub : sinon . SinonStub = sinon . stub ( updateCommand as any , "executeCore" ) ;
134
- const backupStub : sinon . SinonStub = sinon . stub ( updateCommand as any , "backup" ) ;
135
- updateCommand . execute ( [ "3.3.0" ] ) ;
136
-
137
- assert . isTrue ( backupStub . called ) ;
138
- assert . isTrue ( executeCoreStub . called ) ;
139
- } ) ;
140
-
141
- it ( "if backup fails, execute core not called and temp removed" , async ( ) => {
142
- const testInjector = createTestInjector ( ) ;
130
+ it ( "if backup fails, pltforms not deleted and added, temp removed" , async ( ) => {
131
+ const installedPlatforms : string [ ] = [ "android" ] ;
132
+ const testInjector = createTestInjector ( installedPlatforms ) ;
143
133
const fs = testInjector . resolve ( "fs" ) ;
144
134
const deleteDirectory : sinon . SinonStub = sandbox . stub ( fs , "deleteDirectory" ) ;
135
+ const platformService = testInjector . resolve ( "platformService" ) ;
136
+ sandbox . stub ( fs , "copyFile" ) . throws ( ) ;
137
+ sandbox . spy ( platformService , "addPlatforms" ) ;
138
+ sandbox . spy ( platformService , "removePlatforms" ) ;
145
139
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
146
- sandbox . stub ( updateCommand as any , "backup" ) . throws ( ) ;
147
- const executeCoreStub : sinon . SinonStub = sinon . stub ( updateCommand as any , "executeCore" ) ;
148
- updateCommand . execute ( [ "3.3.0" ] ) ;
149
-
150
- assert . isFalse ( executeCoreStub . called ) ;
151
- assert . isTrue ( deleteDirectory . calledWith ( path . join ( projectFolder , ( updateCommand as any ) . tempFolder ) ) ) ;
152
- } ) ;
153
- } ) ;
154
-
155
- describe ( "backup" , ( ) => {
156
- let sandbox : sinon . SinonSandbox ;
157
-
158
- beforeEach ( ( ) => {
159
- sandbox = sinon . sandbox . create ( ) ;
160
- } ) ;
161
-
162
- afterEach ( ( ) => {
163
- sandbox . restore ( ) ;
164
- } ) ;
165
-
166
- it ( "calls copy to temp for package.json and folders" , async ( ) => {
167
- const testInjector = createTestInjector ( ) ;
168
- const fs = testInjector . resolve ( "fs" ) ;
169
- const copyFileStub = sandbox . stub ( fs , "copyFile" ) ;
170
- const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
171
- sinon . stub ( updateCommand as any , "executeCore" ) ;
172
- updateCommand . execute ( [ "3.3.0" ] ) ;
173
-
174
- assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
175
- for ( const folder of ( updateCommand as any ) . folders ) {
176
- assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , folder ) ) ) ;
177
- }
178
- } ) ;
179
- } ) ;
180
-
181
- describe ( "backup" , ( ) => {
182
- let sandbox : sinon . SinonSandbox ;
183
140
184
- beforeEach ( ( ) => {
185
- sandbox = sinon . sandbox . create ( ) ;
186
- } ) ;
187
-
188
- afterEach ( ( ) => {
189
- sandbox . restore ( ) ;
141
+ return updateCommand . execute ( [ "3.3.0" ] ) . then ( ( ) => {
142
+ assert . isTrue ( deleteDirectory . calledWith ( path . join ( projectFolder , UpdateCommand . tempFolder ) ) ) ;
143
+ assert . isFalse ( platformService . removePlatforms . calledWith ( installedPlatforms ) ) ;
144
+ assert . isFalse ( platformService . addPlatforms . calledWith ( installedPlatforms ) ) ;
145
+ } ) ;
190
146
} ) ;
191
147
192
- it ( "calls copy to temp for package.json and folders" , async ( ) => {
148
+ it ( "calls copy to temp for package.json and folders(backup) " , async ( ) => {
193
149
const testInjector = createTestInjector ( ) ;
194
150
const fs = testInjector . resolve ( "fs" ) ;
195
151
const copyFileStub = sandbox . stub ( fs , "copyFile" ) ;
196
152
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
197
- const tempDir = path . join ( projectFolder , ( updateCommand as any ) . tempFolder ) ;
198
- sinon . stub ( updateCommand as any , "executeCore" ) ;
199
- ( updateCommand as any ) . backup ( tempDir ) ;
200
-
201
- assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
202
- for ( const folder of ( updateCommand as any ) . folders ) {
203
- assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , folder ) ) ) ;
204
- }
205
- } ) ;
206
- } ) ;
207
-
208
- describe ( "restoreBackup" , ( ) => {
209
- let sandbox : sinon . SinonSandbox ;
210
-
211
- beforeEach ( ( ) => {
212
- sandbox = sinon . sandbox . create ( ) ;
213
- } ) ;
214
-
215
- afterEach ( ( ) => {
216
- sandbox . restore ( ) ;
153
+ return updateCommand . execute ( [ "3.3.0" ] ) . then ( ( ) => {
154
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
155
+ for ( const folder of UpdateCommand . folders ) {
156
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , folder ) ) ) ;
157
+ }
158
+ } ) ;
217
159
} ) ;
218
160
219
- it ( "calls copy to temp for package.json and folders" , async ( ) => {
161
+ it ( "calls copy from temp for package.json and folders to project folder(restore) " , async ( ) => {
220
162
const testInjector = createTestInjector ( ) ;
163
+ testInjector . resolve ( "platformService" ) . removePlatforms = ( ) => {
164
+ throw new Error ( ) ;
165
+ } ;
221
166
const fs = testInjector . resolve ( "fs" ) ;
167
+ const deleteDirectoryStub : sinon . SinonStub = sandbox . stub ( fs , "deleteDirectory" ) ;
222
168
const copyFileStub = sandbox . stub ( fs , "copyFile" ) ;
223
169
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
224
- const tempDir = path . join ( projectFolder , ( updateCommand as any ) . tempFolder , projectFolder ) ;
225
- sinon . stub ( updateCommand as any , "executeCore" ) ;
226
- ( updateCommand as any ) . restoreBackup ( tempDir ) ;
227
-
228
- assert . isTrue ( copyFileStub . calledWith ( path . join ( tempDir , "package.json" ) , projectFolder ) ) ;
229
- for ( const folder of ( updateCommand as any ) . folders ) {
230
- assert . isTrue ( copyFileStub . calledWith ( path . join ( tempDir , folder ) , projectFolder ) ) ;
231
- }
232
- } ) ;
233
- } ) ;
234
-
235
- describe ( "executeCore" , ( ) => {
236
- let sandbox : sinon . SinonSandbox ;
170
+ const tempDir = path . join ( projectFolder , UpdateCommand . tempFolder ) ;
237
171
238
- beforeEach ( ( ) => {
239
- sandbox = sinon . sandbox . create ( ) ;
240
- } ) ;
241
-
242
- afterEach ( ( ) => {
243
- sandbox . restore ( ) ;
172
+ return updateCommand . execute ( [ "3.3.0" ] ) . then ( ( ) => {
173
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( tempDir , "package.json" ) , projectFolder ) ) ;
174
+ for ( const folder of UpdateCommand . folders ) {
175
+ assert . isTrue ( deleteDirectoryStub . calledWith ( path . join ( projectFolder , folder ) ) ) ;
176
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( tempDir , folder ) , projectFolder ) ) ;
177
+ }
178
+ } ) ;
244
179
} ) ;
245
180
246
181
it ( "calls remove for all falders" , async ( ) => {
247
182
const testInjector = createTestInjector ( ) ;
248
183
const fs = testInjector . resolve ( "fs" ) ;
249
184
const deleteDirectory : sinon . SinonStub = sandbox . stub ( fs , "deleteDirectory" ) ;
250
185
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
251
- return ( updateCommand as any ) . executeCore ( [ ] ) . then ( ( ) => {
252
- for ( const folder of ( updateCommand as any ) . folders ) {
186
+ return updateCommand . execute ( [ ] ) . then ( ( ) => {
187
+ for ( const folder of UpdateCommand . folders ) {
253
188
assert . isTrue ( deleteDirectory . calledWith ( path . join ( projectFolder , folder ) ) ) ;
254
189
}
255
190
} ) ;
@@ -262,7 +197,7 @@ describe.only("update command method tests", () => {
262
197
sandbox . spy ( platformService , "addPlatforms" ) ;
263
198
sandbox . spy ( platformService , "removePlatforms" ) ;
264
199
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
265
- return ( updateCommand as any ) . executeCore ( [ ] ) . then ( ( ) => {
200
+ return updateCommand . execute ( [ ] ) . then ( ( ) => {
266
201
assert ( platformService . removePlatforms . calledWith ( installedPlatforms ) ) ;
267
202
assert ( platformService . addPlatforms . calledWith ( installedPlatforms ) ) ;
268
203
} ) ;
@@ -276,7 +211,7 @@ describe.only("update command method tests", () => {
276
211
sandbox . spy ( platformService , "addPlatforms" ) ;
277
212
sandbox . spy ( platformService , "removePlatforms" ) ;
278
213
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
279
- return ( updateCommand as any ) . executeCore ( [ version ] ) . then ( ( ) => {
214
+ return updateCommand . execute ( [ version ] ) . then ( ( ) => {
280
215
assert ( platformService . addPlatforms . calledWith ( [ `${ installedPlatforms } @${ version } ` ] ) ) ;
281
216
} ) ;
282
217
} ) ;
@@ -288,7 +223,7 @@ describe.only("update command method tests", () => {
288
223
sandbox . spy ( pluginsService , "add" ) ;
289
224
sandbox . spy ( pluginsService , "ensureAllDependenciesAreInstalled" ) ;
290
225
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
291
- return ( updateCommand as any ) . executeCore ( [ ] ) . then ( ( ) => {
226
+ return updateCommand . execute ( [ ] ) . then ( ( ) => {
292
227
assert ( pluginsService . add . calledWith ( "tns-core-modules" ) ) ;
293
228
assert ( pluginsService . remove . calledWith ( "tns-core-modules" ) ) ;
294
229
assert ( pluginsService . remove . calledWith ( "tns-core-modules-widgets" ) ) ;
@@ -304,7 +239,7 @@ describe.only("update command method tests", () => {
304
239
sandbox . spy ( pluginsService , "add" ) ;
305
240
sandbox . spy ( pluginsService , "ensureAllDependenciesAreInstalled" ) ;
306
241
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
307
- return ( updateCommand as any ) . executeCore ( [ version ] ) . then ( ( ) => {
242
+ return updateCommand . execute ( [ version ] ) . then ( ( ) => {
308
243
assert ( pluginsService . add . calledWith ( `tns-core-modules@${ version } ` ) ) ;
309
244
} ) ;
310
245
} ) ;
0 commit comments