Skip to content

Commit 89ca889

Browse files
authored
Fixed the platform-clean to execute only when the Platform is Valid and Installed. Add the "platform|clean" module to the test injector - now after platform|clean the code is actually executed. (#2592)
1 parent b3795dc commit 89ca889

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

lib/commands/platform-clean.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class CleanCommand implements ICommand {
1818
this.$errors.fail("No platform specified. Please specify a platform to clean");
1919
}
2020

21-
_.each(args, arg => this.$platformService.validatePlatform(arg, this.$projectData));
21+
_.each(args, arg => this.$platformService.validatePlatformInstalled(arg, this.$projectData));
2222

2323
return true;
2424
}

lib/definitions/platform.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ interface IPlatformService extends NodeJS.EventEmitter {
130130

131131
cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
132132
validatePlatformInstalled(platform: string, projectData: IProjectData): void;
133+
134+
/**
135+
* Ensures the passed platform is a valid one (from the supported ones)
136+
* and that it can be built on the current OS
137+
*/
133138
validatePlatform(platform: string, projectData: IProjectData): void;
134139

135140
/**

test/platform-commands.ts

+29-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as stubs from "./stubs";
33
import * as PlatformAddCommandLib from "../lib/commands/add-platform";
44
import * as PlatformRemoveCommandLib from "../lib/commands/remove-platform";
55
import * as PlatformUpdateCommandLib from "../lib/commands/update-platform";
6+
import * as PlatformCleanCommandLib from "../lib/commands/platform-clean";
67
import * as PlatformServiceLib from '../lib/services/platform-service';
78
import * as StaticConfigLib from "../lib/config";
89
import * as CommandsServiceLib from "../lib/common/services/commands-service";
@@ -19,7 +20,6 @@ import { MobilePlatformsCapabilities } from "../lib/mobile-platforms-capabilitie
1920
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants";
2021
import { XmlValidator } from "../lib/xml-validator";
2122
import * as ChildProcessLib from "../lib/common/child-process";
22-
import { CleanCommand } from "../lib/commands/platform-clean";
2323
import ProjectChangesLib = require("../lib/services/project-changes-service");
2424

2525
let 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() {
146147
describe('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

Comments
 (0)