diff --git a/lib/common b/lib/common index 30c6fbec7e..cca6ca3f3a 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 30c6fbec7e9bb80d0c9ef987aa5d5063bb77aec0 +Subproject commit cca6ca3f3ad49ea1db6a661a73ab152e9954d0d5 diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index c87af0d611..6377e5c00f 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -1,8 +1,8 @@ /// "use strict"; -import path = require("path"); -import shelljs = require("shelljs"); -import semver = require("semver"); +import * as path from "path"; +import * as shelljs from "shelljs"; +import * as semver from "semver"; import Future = require("fibers/future"); import constants = require("./../constants"); let xmlmerge = require("xmlmerge-js"); @@ -13,7 +13,7 @@ export class PluginsService implements IPluginsService { private static UNINSTALL_COMMAND_NAME = "uninstall"; private static NPM_CONFIG = { save: true - } + }; constructor(private $platformsData: IPlatformsData, private $npm: INodePackageManager, diff --git a/test/plugins-service.ts b/test/plugins-service.ts index 2d7ca69aa8..131f418764 100644 --- a/test/plugins-service.ts +++ b/test/plugins-service.ts @@ -18,16 +18,14 @@ import PlatformsDataLib = require("../lib/platforms-data"); import ProjectDataServiceLib = require("../lib/services/project-data-service"); import helpers = require("../lib/common/helpers"); import ProjectFilesManagerLib = require("../lib/services/project-files-manager"); -import os = require("os"); - +import { EOL } from "os"; import PluginsServiceLib = require("../lib/services/plugins-service"); import AddPluginCommandLib = require("../lib/commands/plugin/add-plugin"); - -import path = require("path"); -import temp = require("temp"); +import { assert } from "chai"; +import * as path from "path"; +import * as temp from "temp"; temp.track(); -let assert = require("chai").assert; let isErrorThrown = false; function createTestInjector() { @@ -114,10 +112,10 @@ function addPluginWhenExpectingToFail(testInjector: IInjector, plugin: string, e name: "" }]; }).future()(); - } + }; pluginsService.ensureAllDependenciesAreInstalled = () => { return (() => { }).future()(); - } + }; mockBeginCommand(testInjector, "Exception: " + expectedErrorMessage); @@ -185,7 +183,7 @@ describe("Plugins service", () => { name: "plugin1" }]; }).future()(); - } + }; mockBeginCommand(testInjector, "Exception: " + 'Plugin "plugin1" is already installed.'); @@ -224,7 +222,7 @@ describe("Plugins service", () => { logger.warn = (message: string) => { assert.equal(message, expectedWarningMessage); isWarningMessageShown = true; - } + }; // Mock pluginsService let pluginsService = testInjector.resolve("pluginsService"); @@ -234,7 +232,7 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; // Mock platformsData let platformsData = testInjector.resolve("platformsData"); @@ -243,10 +241,9 @@ describe("Plugins service", () => { appDestinationDirectoryPath: path.join(projectFolder, "platforms", "android"), frameworkPackageName: "tns-android" } - } + }; - let commandsService = testInjector.resolve("commandsService"); - commandsService.tryExecuteCommand("plugin|add", [pluginFolderPath]).wait(); + pluginsService.add(pluginFolderPath).wait(); assert.isTrue(isWarningMessageShown); }); @@ -261,10 +258,9 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; - let commandsService = testInjector.resolve(CommandsServiceLib.CommandsService); - commandsService.tryExecuteCommand("plugin|add", [pluginName]).wait(); + pluginsService.add(pluginName).wait(); let fs = testInjector.resolve("fs"); @@ -283,10 +279,9 @@ describe("Plugins service", () => { // Asserts that the plugin is added in package.json file let packageJsonContent = fs.readJson(path.join(projectFolder, "package.json")).wait(); let actualDependencies = packageJsonContent.dependencies; - let expectedDependencies = { - "plugin1": "^1.0.3" - }; - assert.deepEqual(actualDependencies, expectedDependencies); + let expectedDependencies = { "plugin1": "^1.0.3" }; + let expectedDependenciesExact = { "plugin1": "1.0.3" }; + assert.isTrue(_.isEqual(actualDependencies, expectedDependencies) || _.isEqual(actualDependencies, expectedDependenciesExact)); }); it("adds plugin by name and version", () => { let pluginName = "plugin1"; @@ -299,10 +294,9 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; - let commandsService = testInjector.resolve(CommandsServiceLib.CommandsService); - commandsService.tryExecuteCommand("plugin|add", [pluginName+"@1.0.0"]).wait(); + pluginsService.add(pluginName+"@1.0.0").wait(); let fs = testInjector.resolve("fs"); @@ -321,10 +315,9 @@ describe("Plugins service", () => { // Assert that the plugin is added in package.json file let packageJsonContent = fs.readJson(path.join(projectFolder, "package.json")).wait(); let actualDependencies = packageJsonContent.dependencies; - let expectedDependencies = { - "plugin1": "^1.0.0" - }; - assert.deepEqual(actualDependencies, expectedDependencies); + let expectedDependencies = { "plugin1": "^1.0.0" }; + let expectedDependenciesExact = { "plugin1": "1.0.0" }; + assert.isTrue(_.isEqual(actualDependencies, expectedDependencies) || _.isEqual(actualDependencies, expectedDependenciesExact)); }); it("adds plugin by local path", () => { // Creates a plugin in tempFolder @@ -350,10 +343,9 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; - let commandsService = testInjector.resolve(CommandsServiceLib.CommandsService); - commandsService.tryExecuteCommand("plugin|add", [pluginFolderPath]).wait(); + pluginsService.add(pluginFolderPath).wait(); // Assert that the all plugin's content is successfully added to node_modules folder let nodeModulesFolderPath = path.join(projectFolder, "node_modules"); @@ -395,14 +387,13 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; // Mock options let options = testInjector.resolve("options"); options.production = true; - let commandsService = testInjector.resolve(CommandsServiceLib.CommandsService); - commandsService.tryExecuteCommand("plugin|add", [pluginFolderPath]).wait(); + pluginsService.add(pluginFolderPath).wait(); let nodeModulesFolderPath = path.join(projectFolder, "node_modules"); assert.isFalse(fs.exists(path.join(nodeModulesFolderPath, pluginName, "node_modules", "grunt")).wait()); @@ -437,7 +428,7 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; // Mock options let options = testInjector.resolve("options"); @@ -481,7 +472,7 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; let appDestinationDirectoryPath = path.join(projectFolder, "platforms", "android"); @@ -493,7 +484,7 @@ describe("Plugins service", () => { frameworkPackageName: "tns-android", configurationFileName: "AndroidManifest.xml" } - } + }; // Ensure the pluginDestinationPath folder exists let pluginPlatformsDirPath = path.join(appDestinationDirectoryPath, "app", "tns_modules", pluginName, "platforms", "android"); @@ -543,7 +534,7 @@ describe("Plugins service", () => { name: "" }]; }).future()(); - } + }; let appDestinationDirectoryPath = path.join(projectFolder, "platforms", "android"); @@ -560,7 +551,7 @@ describe("Plugins service", () => { preparePluginNativeCode: (pluginData: IPluginData) => (() => {}).future()() } } - } + }; // Ensure the pluginDestinationPath folder exists let pluginPlatformsDirPath = path.join(appDestinationDirectoryPath, "app", "tns_modules", pluginName, "platforms", "android"); @@ -577,7 +568,7 @@ describe("Plugins service", () => { pluginsService.add(pluginFolderPath).wait(); let expectedXml = ''; - expectedXml = helpers.stringReplaceAll(expectedXml, os.EOL, ""); + expectedXml = helpers.stringReplaceAll(expectedXml, EOL, ""); expectedXml = helpers.stringReplaceAll(expectedXml, " ", ""); let actualXml = fs.readText(path.join(appDestinationDirectoryPath, "AndroidManifest.xml")).wait();