@@ -3,6 +3,7 @@ import * as stubs from "./stubs";
3
3
import * as PlatformAddCommandLib from "../lib/commands/add-platform" ;
4
4
import * as PlatformRemoveCommandLib from "../lib/commands/remove-platform" ;
5
5
import * as PlatformUpdateCommandLib from "../lib/commands/update-platform" ;
6
+ import * as PlatformCleanCommandLib from "../lib/commands/platform-clean" ;
6
7
import * as PlatformServiceLib from '../lib/services/platform-service' ;
7
8
import * as StaticConfigLib from "../lib/config" ;
8
9
import * as CommandsServiceLib from "../lib/common/services/commands-service" ;
@@ -19,7 +20,6 @@ import { MobilePlatformsCapabilities } from "../lib/mobile-platforms-capabilitie
19
20
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants" ;
20
21
import { XmlValidator } from "../lib/xml-validator" ;
21
22
import * as ChildProcessLib from "../lib/common/child-process" ;
22
- import { CleanCommand } from "../lib/commands/platform-clean" ;
23
23
import ProjectChangesLib = require( "../lib/services/project-changes-service" ) ;
24
24
25
25
let isCommandExecuted = true ;
@@ -105,6 +105,7 @@ function createTestInjector() {
105
105
testInjector . registerCommand ( "platform|add" , PlatformAddCommandLib . AddPlatformCommand ) ;
106
106
testInjector . registerCommand ( "platform|remove" , PlatformRemoveCommandLib . RemovePlatformCommand ) ;
107
107
testInjector . registerCommand ( "platform|update" , PlatformUpdateCommandLib . UpdatePlatformCommand ) ;
108
+ testInjector . registerCommand ( "platform|clean" , PlatformCleanCommandLib . CleanCommand ) ;
108
109
testInjector . register ( "lockfile" , { } ) ;
109
110
testInjector . register ( "resources" , { } ) ;
110
111
testInjector . register ( "commandsServiceProvider" , {
@@ -146,11 +147,13 @@ function createTestInjector() {
146
147
describe ( 'Platform Service Tests' , ( ) => {
147
148
let platformService : IPlatformService , testInjector : IInjector ;
148
149
let commandsService : ICommandsService ;
150
+ let fs : IFileSystem ;
149
151
beforeEach ( ( ) => {
150
152
testInjector = createTestInjector ( ) ;
151
153
testInjector . register ( "fs" , stubs . FileSystemStub ) ;
152
154
commandsService = testInjector . resolve ( "commands-service" ) ;
153
155
platformService = testInjector . resolve ( "platformService" ) ;
156
+ fs = testInjector . resolve ( "fs" ) ;
154
157
} ) ;
155
158
156
159
describe ( "platform commands tests" , ( ) => {
@@ -301,6 +304,12 @@ describe('Platform Service Tests', () => {
301
304
} ) ;
302
305
303
306
describe ( "#CleanPlatformCommand" , ( ) => {
307
+ beforeEach ( ( ) => {
308
+ fs . exists = ( platform : string ) => {
309
+ return false ;
310
+ } ;
311
+ } ) ;
312
+
304
313
it ( "is not executed when platform is not passed" , async ( ) => {
305
314
isCommandExecuted = false ;
306
315
commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
@@ -330,18 +339,25 @@ describe('Platform Service Tests', () => {
330
339
} ) ;
331
340
332
341
it ( "is executed when platform is valid" , async ( ) => {
342
+ let commandsExecutedCount = 0 ;
333
343
isCommandExecuted = false ;
334
344
commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
335
345
if ( commandName !== "help" ) {
336
346
isCommandExecuted = true ;
347
+ commandsExecutedCount ++ ;
337
348
}
338
349
339
350
return false ;
340
351
} ;
341
352
353
+ fs . exists = ( platform : string ) => {
354
+ return platform === "android" ;
355
+ } ;
356
+
342
357
await commandsService . tryExecuteCommand ( "platform|add" , [ "android" ] ) ;
343
358
await commandsService . tryExecuteCommand ( "platform|clean" , [ "android" ] ) ;
344
359
assert . isTrue ( isCommandExecuted ) ;
360
+ assert . isTrue ( commandsExecutedCount === 2 ) ;
345
361
} ) ;
346
362
347
363
it ( "is not executed when platform is not added" , async ( ) => {
@@ -359,23 +375,30 @@ describe('Platform Service Tests', () => {
359
375
} ) ;
360
376
361
377
it ( "is executed when all platforms are valid" , async ( ) => {
378
+ let commandsExecutedCount = 0 ;
362
379
isCommandExecuted = false ;
363
380
commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
364
381
365
382
if ( commandName !== "help" ) {
366
383
isCommandExecuted = true ;
384
+ commandsExecutedCount ++ ;
367
385
}
368
386
369
387
return false ;
370
388
} ;
371
389
390
+ fs . exists = ( platform : string ) => {
391
+ return [ "android" , "ios" ] . indexOf ( platform ) !== - 1 ;
392
+ } ;
393
+
372
394
await commandsService . tryExecuteCommand ( "platform|add" , [ "android" ] ) ;
373
395
await commandsService . tryExecuteCommand ( "platform|add" , [ "ios" ] ) ;
374
396
await commandsService . tryExecuteCommand ( "platform|clean" , [ "android" , "ios" ] ) ;
375
397
assert . isTrue ( isCommandExecuted ) ;
398
+ assert . isTrue ( commandsExecutedCount === 3 ) ;
376
399
} ) ;
377
400
378
- it ( "is not executed when at least on platform is not added" , async ( ) => {
401
+ it ( "is not executed when at least one platform is not added" , async ( ) => {
379
402
isCommandExecuted = false ;
380
403
commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
381
404
if ( commandName !== "help" ) {
@@ -385,6 +408,10 @@ describe('Platform Service Tests', () => {
385
408
return false ;
386
409
} ;
387
410
411
+ fs . exists = ( platform : string ) => {
412
+ return platform === "android" ;
413
+ } ;
414
+
388
415
await commandsService . tryExecuteCommand ( "platform|clean" , [ "android" , "ios" ] ) ;
389
416
assert . isFalse ( isCommandExecuted ) ;
390
417
} ) ;
@@ -405,7 +432,6 @@ describe('Platform Service Tests', () => {
405
432
406
433
it ( "will call removePlatform and addPlatform on the platformService passing the provided platforms" , async ( ) => {
407
434
let platformActions : { action : string , platforms : string [ ] } [ ] = [ ] ;
408
- testInjector . registerCommand ( "platform|clean" , CleanCommand ) ;
409
435
let cleanCommand = testInjector . resolveCommand ( "platform|clean" ) ;
410
436
411
437
platformService . removePlatforms = async ( platforms : string [ ] ) => {
0 commit comments