Skip to content

Improve platform-clean command check for Platform #2592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/commands/platform-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CleanCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify a platform to clean");
}

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

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ interface IPlatformService extends NodeJS.EventEmitter {

cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
validatePlatformInstalled(platform: string, projectData: IProjectData): void;

/**
* Ensures the passed platform is a valid one (from the supported ones)
* and that it can be built on the current OS
*/
validatePlatform(platform: string, projectData: IProjectData): void;

/**
Expand Down
32 changes: 29 additions & 3 deletions test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as stubs from "./stubs";
import * as PlatformAddCommandLib from "../lib/commands/add-platform";
import * as PlatformRemoveCommandLib from "../lib/commands/remove-platform";
import * as PlatformUpdateCommandLib from "../lib/commands/update-platform";
import * as PlatformCleanCommandLib from "../lib/commands/platform-clean";
import * as PlatformServiceLib from '../lib/services/platform-service';
import * as StaticConfigLib from "../lib/config";
import * as CommandsServiceLib from "../lib/common/services/commands-service";
Expand All @@ -19,7 +20,6 @@ import { MobilePlatformsCapabilities } from "../lib/mobile-platforms-capabilitie
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants";
import { XmlValidator } from "../lib/xml-validator";
import * as ChildProcessLib from "../lib/common/child-process";
import { CleanCommand } from "../lib/commands/platform-clean";
import ProjectChangesLib = require("../lib/services/project-changes-service");

let isCommandExecuted = true;
Expand Down Expand Up @@ -105,6 +105,7 @@ function createTestInjector() {
testInjector.registerCommand("platform|add", PlatformAddCommandLib.AddPlatformCommand);
testInjector.registerCommand("platform|remove", PlatformRemoveCommandLib.RemovePlatformCommand);
testInjector.registerCommand("platform|update", PlatformUpdateCommandLib.UpdatePlatformCommand);
testInjector.registerCommand("platform|clean", PlatformCleanCommandLib.CleanCommand);
testInjector.register("lockfile", {});
testInjector.register("resources", {});
testInjector.register("commandsServiceProvider", {
Expand Down Expand Up @@ -146,11 +147,13 @@ function createTestInjector() {
describe('Platform Service Tests', () => {
let platformService: IPlatformService, testInjector: IInjector;
let commandsService: ICommandsService;
let fs: IFileSystem;
beforeEach(() => {
testInjector = createTestInjector();
testInjector.register("fs", stubs.FileSystemStub);
commandsService = testInjector.resolve("commands-service");
platformService = testInjector.resolve("platformService");
fs = testInjector.resolve("fs");
});

describe("platform commands tests", () => {
Expand Down Expand Up @@ -301,6 +304,12 @@ describe('Platform Service Tests', () => {
});

describe("#CleanPlatformCommand", () => {
beforeEach(() => {
fs.exists = (platform: string) => {
return false;
};
});

it("is not executed when platform is not passed", async () => {
isCommandExecuted = false;
commandsService.executeCommandUnchecked = async (commandName: string): Promise<boolean> => {
Expand Down Expand Up @@ -330,18 +339,25 @@ describe('Platform Service Tests', () => {
});

it("is executed when platform is valid", async () => {
let commandsExecutedCount = 0;
isCommandExecuted = false;
commandsService.executeCommandUnchecked = async (commandName: string): Promise<boolean> => {
if (commandName !== "help") {
isCommandExecuted = true;
commandsExecutedCount++;
}

return false;
};

fs.exists = (platform: string) => {
return platform === "android";
};

await commandsService.tryExecuteCommand("platform|add", ["android"]);
await commandsService.tryExecuteCommand("platform|clean", ["android"]);
assert.isTrue(isCommandExecuted);
assert.isTrue(commandsExecutedCount === 2);
});

it("is not executed when platform is not added", async () => {
Expand All @@ -359,23 +375,30 @@ describe('Platform Service Tests', () => {
});

it("is executed when all platforms are valid", async () => {
let commandsExecutedCount = 0;
isCommandExecuted = false;
commandsService.executeCommandUnchecked = async (commandName: string): Promise<boolean> => {

if (commandName !== "help") {
isCommandExecuted = true;
commandsExecutedCount++;
}

return false;
};

fs.exists = (platform: string) => {
return ["android", "ios"].indexOf(platform) !== -1;
};

await commandsService.tryExecuteCommand("platform|add", ["android"]);
await commandsService.tryExecuteCommand("platform|add", ["ios"]);
await commandsService.tryExecuteCommand("platform|clean", ["android", "ios"]);
assert.isTrue(isCommandExecuted);
assert.isTrue(commandsExecutedCount === 3);
});

it("is not executed when at least on platform is not added", async () => {
it("is not executed when at least one platform is not added", async () => {
isCommandExecuted = false;
commandsService.executeCommandUnchecked = async (commandName: string): Promise<boolean> => {
if (commandName !== "help") {
Expand All @@ -385,6 +408,10 @@ describe('Platform Service Tests', () => {
return false;
};

fs.exists = (platform: string) => {
return platform === "android";
};

await commandsService.tryExecuteCommand("platform|clean", ["android", "ios"]);
assert.isFalse(isCommandExecuted);
});
Expand All @@ -405,7 +432,6 @@ describe('Platform Service Tests', () => {

it("will call removePlatform and addPlatform on the platformService passing the provided platforms", async () => {
let platformActions: { action: string, platforms: string[] }[] = [];
testInjector.registerCommand("platform|clean", CleanCommand);
let cleanCommand = testInjector.resolveCommand("platform|clean");

platformService.removePlatforms = async (platforms: string[]) => {
Expand Down