@@ -3,6 +3,7 @@ import * as stubs from "./stubs";
33import * as PlatformAddCommandLib from "../lib/commands/add-platform" ;
44import * as PlatformRemoveCommandLib from "../lib/commands/remove-platform" ;
55import * as PlatformUpdateCommandLib from "../lib/commands/update-platform" ;
6+ import * as PlatformCleanCommandLib from "../lib/commands/platform-clean" ;
67import * as PlatformServiceLib from '../lib/services/platform-service' ;
78import * as StaticConfigLib from "../lib/config" ;
89import * as CommandsServiceLib from "../lib/common/services/commands-service" ;
@@ -19,7 +20,6 @@ import { MobilePlatformsCapabilities } from "../lib/mobile-platforms-capabilitie
1920import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants" ;
2021import { XmlValidator } from "../lib/xml-validator" ;
2122import * as ChildProcessLib from "../lib/common/child-process" ;
22- import { CleanCommand } from "../lib/commands/platform-clean" ;
2323import ProjectChangesLib = require( "../lib/services/project-changes-service" ) ;
2424
2525let isCommandExecuted = true ;
@@ -105,6 +105,7 @@ function createTestInjector() {
105105 testInjector . registerCommand ( "platform|add" , PlatformAddCommandLib . AddPlatformCommand ) ;
106106 testInjector . registerCommand ( "platform|remove" , PlatformRemoveCommandLib . RemovePlatformCommand ) ;
107107 testInjector . registerCommand ( "platform|update" , PlatformUpdateCommandLib . UpdatePlatformCommand ) ;
108+ testInjector . registerCommand ( "platform|clean" , PlatformCleanCommandLib . CleanCommand ) ;
108109 testInjector . register ( "lockfile" , { } ) ;
109110 testInjector . register ( "resources" , { } ) ;
110111 testInjector . register ( "commandsServiceProvider" , {
@@ -146,11 +147,13 @@ function createTestInjector() {
146147describe ( 'Platform Service Tests' , ( ) => {
147148 let platformService : IPlatformService , testInjector : IInjector ;
148149 let commandsService : ICommandsService ;
150+ let fs : IFileSystem ;
149151 beforeEach ( ( ) => {
150152 testInjector = createTestInjector ( ) ;
151153 testInjector . register ( "fs" , stubs . FileSystemStub ) ;
152154 commandsService = testInjector . resolve ( "commands-service" ) ;
153155 platformService = testInjector . resolve ( "platformService" ) ;
156+ fs = testInjector . resolve ( "fs" ) ;
154157 } ) ;
155158
156159 describe ( "platform commands tests" , ( ) => {
@@ -301,6 +304,12 @@ describe('Platform Service Tests', () => {
301304 } ) ;
302305
303306 describe ( "#CleanPlatformCommand" , ( ) => {
307+ beforeEach ( ( ) => {
308+ fs . exists = ( platform : string ) => {
309+ return false ;
310+ } ;
311+ } ) ;
312+
304313 it ( "is not executed when platform is not passed" , async ( ) => {
305314 isCommandExecuted = false ;
306315 commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
@@ -330,18 +339,25 @@ describe('Platform Service Tests', () => {
330339 } ) ;
331340
332341 it ( "is executed when platform is valid" , async ( ) => {
342+ let commandsExecutedCount = 0 ;
333343 isCommandExecuted = false ;
334344 commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
335345 if ( commandName !== "help" ) {
336346 isCommandExecuted = true ;
347+ commandsExecutedCount ++ ;
337348 }
338349
339350 return false ;
340351 } ;
341352
353+ fs . exists = ( platform : string ) => {
354+ return platform === "android" ;
355+ } ;
356+
342357 await commandsService . tryExecuteCommand ( "platform|add" , [ "android" ] ) ;
343358 await commandsService . tryExecuteCommand ( "platform|clean" , [ "android" ] ) ;
344359 assert . isTrue ( isCommandExecuted ) ;
360+ assert . isTrue ( commandsExecutedCount === 2 ) ;
345361 } ) ;
346362
347363 it ( "is not executed when platform is not added" , async ( ) => {
@@ -359,23 +375,30 @@ describe('Platform Service Tests', () => {
359375 } ) ;
360376
361377 it ( "is executed when all platforms are valid" , async ( ) => {
378+ let commandsExecutedCount = 0 ;
362379 isCommandExecuted = false ;
363380 commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
364381
365382 if ( commandName !== "help" ) {
366383 isCommandExecuted = true ;
384+ commandsExecutedCount ++ ;
367385 }
368386
369387 return false ;
370388 } ;
371389
390+ fs . exists = ( platform : string ) => {
391+ return [ "android" , "ios" ] . indexOf ( platform ) !== - 1 ;
392+ } ;
393+
372394 await commandsService . tryExecuteCommand ( "platform|add" , [ "android" ] ) ;
373395 await commandsService . tryExecuteCommand ( "platform|add" , [ "ios" ] ) ;
374396 await commandsService . tryExecuteCommand ( "platform|clean" , [ "android" , "ios" ] ) ;
375397 assert . isTrue ( isCommandExecuted ) ;
398+ assert . isTrue ( commandsExecutedCount === 3 ) ;
376399 } ) ;
377400
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 ( ) => {
379402 isCommandExecuted = false ;
380403 commandsService . executeCommandUnchecked = async ( commandName : string ) : Promise < boolean > => {
381404 if ( commandName !== "help" ) {
@@ -385,6 +408,10 @@ describe('Platform Service Tests', () => {
385408 return false ;
386409 } ;
387410
411+ fs . exists = ( platform : string ) => {
412+ return platform === "android" ;
413+ } ;
414+
388415 await commandsService . tryExecuteCommand ( "platform|clean" , [ "android" , "ios" ] ) ;
389416 assert . isFalse ( isCommandExecuted ) ;
390417 } ) ;
@@ -405,7 +432,6 @@ describe('Platform Service Tests', () => {
405432
406433 it ( "will call removePlatform and addPlatform on the platformService passing the provided platforms" , async ( ) => {
407434 let platformActions : { action : string , platforms : string [ ] } [ ] = [ ] ;
408- testInjector . registerCommand ( "platform|clean" , CleanCommand ) ;
409435 let cleanCommand = testInjector . resolveCommand ( "platform|clean" ) ;
410436
411437 platformService . removePlatforms = async ( platforms : string [ ] ) => {
0 commit comments