@@ -8,7 +8,6 @@ import { Options } from "../lib/options";
8
8
import { AndroidProjectService } from "../lib/services/android-project-service" ;
9
9
import { StaticConfig } from "../lib/config" ;
10
10
import { SettingsService } from "../lib/common/test/unit-tests/stubs" ;
11
- import * as shelljs from "shelljs" ;
12
11
const projectFolder = "test" ;
13
12
14
13
function createTestInjector (
@@ -72,7 +71,7 @@ function createTestInjector(
72
71
return testInjector ;
73
72
}
74
73
75
- describe ( "update command method tests" , ( ) => {
74
+ describe . only ( "update command method tests" , ( ) => {
76
75
describe ( "canExecute" , ( ) => {
77
76
it ( "calls platform service validate" , async ( ) => {
78
77
let validated = false ;
@@ -129,7 +128,6 @@ describe("update command method tests", () => {
129
128
} ) ;
130
129
131
130
it ( "calls backup and executeCore" , async ( ) => {
132
- sandbox . stub ( shelljs ) ;
133
131
const testInjector = createTestInjector ( ) ;
134
132
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
135
133
const executeCoreStub : sinon . SinonStub = sinon . stub ( updateCommand as any , "executeCore" ) ;
@@ -141,16 +139,16 @@ describe("update command method tests", () => {
141
139
} ) ;
142
140
143
141
it ( "if backup fails, execute core not called and temp removed" , async ( ) => {
144
- sandbox . stub ( shelljs ) ;
145
- const rmStub : sinon . SinonStub = shelljs . rm as sinon . SinonStub ;
146
142
const testInjector = createTestInjector ( ) ;
143
+ const fs = testInjector . resolve ( "fs" ) ;
144
+ const deleteDirectory : sinon . SinonStub = sandbox . stub ( fs , "deleteDirectory" ) ;
147
145
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
148
146
sandbox . stub ( updateCommand as any , "backup" ) . throws ( ) ;
149
147
const executeCoreStub : sinon . SinonStub = sinon . stub ( updateCommand as any , "executeCore" ) ;
150
148
updateCommand . execute ( [ "3.3.0" ] ) ;
151
149
152
150
assert . isFalse ( executeCoreStub . called ) ;
153
- assert . isTrue ( rmStub . calledWith ( "-fr" , path . join ( projectFolder , ( updateCommand as any ) . tempFolder ) ) ) ;
151
+ assert . isTrue ( deleteDirectory . calledWith ( path . join ( projectFolder , ( updateCommand as any ) . tempFolder ) ) ) ;
154
152
} ) ;
155
153
} ) ;
156
154
@@ -166,16 +164,16 @@ describe("update command method tests", () => {
166
164
} ) ;
167
165
168
166
it ( "calls copy to temp for package.json and folders" , async ( ) => {
169
- sandbox . stub ( shelljs ) ;
170
- const cpStub : sinon . SinonStub = shelljs . cp as sinon . SinonStub ;
171
167
const testInjector = createTestInjector ( ) ;
168
+ const fs = testInjector . resolve ( "fs" ) ;
169
+ const copyFileStub = sandbox . stub ( fs , "copyFile" ) ;
172
170
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
173
171
sinon . stub ( updateCommand as any , "executeCore" ) ;
174
172
updateCommand . execute ( [ "3.3.0" ] ) ;
175
173
176
- assert . isTrue ( cpStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
174
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
177
175
for ( const folder of ( updateCommand as any ) . folders ) {
178
- assert . isTrue ( cpStub . calledWith ( "-rf" , path . join ( projectFolder , folder ) ) ) ;
176
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , folder ) ) ) ;
179
177
}
180
178
} ) ;
181
179
} ) ;
@@ -192,17 +190,17 @@ describe("update command method tests", () => {
192
190
} ) ;
193
191
194
192
it ( "calls copy to temp for package.json and folders" , async ( ) => {
195
- sandbox . stub ( shelljs ) ;
196
- const cpStub : sinon . SinonStub = shelljs . cp as sinon . SinonStub ;
197
193
const testInjector = createTestInjector ( ) ;
194
+ const fs = testInjector . resolve ( "fs" ) ;
195
+ const copyFileStub = sandbox . stub ( fs , "copyFile" ) ;
198
196
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
199
197
const tempDir = path . join ( projectFolder , ( updateCommand as any ) . tempFolder ) ;
200
198
sinon . stub ( updateCommand as any , "executeCore" ) ;
201
199
( updateCommand as any ) . backup ( tempDir ) ;
202
200
203
- assert . isTrue ( cpStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
201
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , "package.json" ) ) ) ;
204
202
for ( const folder of ( updateCommand as any ) . folders ) {
205
- assert . isTrue ( cpStub . calledWith ( "-rf" , path . join ( projectFolder , folder ) ) ) ;
203
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( projectFolder , folder ) ) ) ;
206
204
}
207
205
} ) ;
208
206
} ) ;
@@ -219,17 +217,17 @@ describe("update command method tests", () => {
219
217
} ) ;
220
218
221
219
it ( "calls copy to temp for package.json and folders" , async ( ) => {
222
- sandbox . stub ( shelljs ) ;
223
- const cpStub : sinon . SinonStub = shelljs . cp as sinon . SinonStub ;
224
220
const testInjector = createTestInjector ( ) ;
221
+ const fs = testInjector . resolve ( "fs" ) ;
222
+ const copyFileStub = sandbox . stub ( fs , "copyFile" ) ;
225
223
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
226
224
const tempDir = path . join ( projectFolder , ( updateCommand as any ) . tempFolder , projectFolder ) ;
227
225
sinon . stub ( updateCommand as any , "executeCore" ) ;
228
226
( updateCommand as any ) . restoreBackup ( tempDir ) ;
229
227
230
- assert . isTrue ( cpStub . calledWith ( "-f" , path . join ( tempDir , "package.json" ) , projectFolder ) ) ;
228
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( tempDir , "package.json" ) , projectFolder ) ) ;
231
229
for ( const folder of ( updateCommand as any ) . folders ) {
232
- assert . isTrue ( cpStub . calledWith ( "-fr" , path . join ( tempDir , folder ) , projectFolder ) ) ;
230
+ assert . isTrue ( copyFileStub . calledWith ( path . join ( tempDir , folder ) , projectFolder ) ) ;
233
231
}
234
232
} ) ;
235
233
} ) ;
@@ -246,19 +244,18 @@ describe("update command method tests", () => {
246
244
} ) ;
247
245
248
246
it ( "calls remove for all falders" , async ( ) => {
249
- sandbox . stub ( shelljs ) ;
250
- const rmStub : sinon . SinonStub = shelljs . rm as sinon . SinonStub ;
251
247
const testInjector = createTestInjector ( ) ;
248
+ const fs = testInjector . resolve ( "fs" ) ;
249
+ const deleteDirectory : sinon . SinonStub = sandbox . stub ( fs , "deleteDirectory" ) ;
252
250
const updateCommand = testInjector . resolve < UpdateCommand > ( UpdateCommand ) ;
253
251
return ( updateCommand as any ) . executeCore ( [ ] ) . then ( ( ) => {
254
252
for ( const folder of ( updateCommand as any ) . folders ) {
255
- assert . isTrue ( rmStub . calledWith ( "-rf" , path . join ( projectFolder , folder ) ) ) ;
253
+ assert . isTrue ( deleteDirectory . calledWith ( path . join ( projectFolder , folder ) ) ) ;
256
254
}
257
255
} ) ;
258
256
} ) ;
259
257
260
258
it ( "calls remove platforms and add platforms" , async ( ) => {
261
- sandbox . stub ( shelljs ) ;
262
259
const installedPlatforms : string [ ] = [ "android" ] ;
263
260
const testInjector = createTestInjector ( installedPlatforms ) ;
264
261
const platformService = testInjector . resolve ( "platformService" ) ;
@@ -272,7 +269,6 @@ describe("update command method tests", () => {
272
269
} ) ;
273
270
274
271
it ( "call add platforms with specific verison" , async ( ) => {
275
- sandbox . stub ( shelljs ) ;
276
272
const version = "3.3.0" ;
277
273
const installedPlatforms : string [ ] = [ "android" ] ;
278
274
const testInjector = createTestInjector ( installedPlatforms ) ;
@@ -286,7 +282,6 @@ describe("update command method tests", () => {
286
282
} ) ;
287
283
288
284
it ( "calls remove and add of core modules and widgets" , async ( ) => {
289
- sandbox . stub ( shelljs ) ;
290
285
const testInjector = createTestInjector ( ) ;
291
286
const pluginsService = testInjector . resolve ( "pluginsService" ) ;
292
287
sandbox . spy ( pluginsService , "remove" ) ;
@@ -302,7 +297,6 @@ describe("update command method tests", () => {
302
297
} ) ;
303
298
304
299
it ( "calls add of core modules with specific version" , async ( ) => {
305
- sandbox . stub ( shelljs ) ;
306
300
const version = "3.3.0" ;
307
301
const testInjector = createTestInjector ( ) ;
308
302
const pluginsService = testInjector . resolve ( "pluginsService" ) ;
0 commit comments