Skip to content
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/common
8 changes: 4 additions & 4 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
///<reference path="../.d.ts"/>
"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");
Expand All @@ -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,
Expand Down
71 changes: 31 additions & 40 deletions test/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -114,10 +112,10 @@ function addPluginWhenExpectingToFail(testInjector: IInjector, plugin: string, e
name: ""
}];
}).future<IPluginData[]>()();
}
};
pluginsService.ensureAllDependenciesAreInstalled = () => {
return (() => { }).future<void>()();
}
};

mockBeginCommand(testInjector, "Exception: " + expectedErrorMessage);

Expand Down Expand Up @@ -185,7 +183,7 @@ describe("Plugins service", () => {
name: "plugin1"
}];
}).future<IPluginData[]>()();
}
};

mockBeginCommand(testInjector, "Exception: " + 'Plugin "plugin1" is already installed.');

Expand Down Expand Up @@ -224,7 +222,7 @@ describe("Plugins service", () => {
logger.warn = (message: string) => {
assert.equal(message, expectedWarningMessage);
isWarningMessageShown = true;
}
};

// Mock pluginsService
let pluginsService = testInjector.resolve("pluginsService");
Expand All @@ -234,7 +232,7 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

// Mock platformsData
let platformsData = testInjector.resolve("platformsData");
Expand All @@ -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);
});
Expand All @@ -261,10 +258,9 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

let commandsService = testInjector.resolve(CommandsServiceLib.CommandsService);
commandsService.tryExecuteCommand("plugin|add", [pluginName]).wait();
pluginsService.add(pluginName).wait();

let fs = testInjector.resolve("fs");

Expand All @@ -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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use deepEqual here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_.isEqual compares deeply

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we consider both syntax are correct (^1.0.3 and 1.0.3) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have updated PR description.

});
it("adds plugin by name and version", () => {
let pluginName = "plugin1";
Expand All @@ -299,10 +294,9 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

let commandsService = testInjector.resolve(CommandsServiceLib.CommandsService);
commandsService.tryExecuteCommand("plugin|add", [pluginName+"@1.0.0"]).wait();
pluginsService.add(pluginName+"@1.0.0").wait();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe ${pluginName}@1.0.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agreed to leave the code as is.


let fs = testInjector.resolve("fs");

Expand All @@ -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
Expand All @@ -350,10 +343,9 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

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");
Expand Down Expand Up @@ -395,14 +387,13 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

// 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());
Expand Down Expand Up @@ -437,7 +428,7 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

// Mock options
let options = testInjector.resolve("options");
Expand Down Expand Up @@ -481,7 +472,7 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

let appDestinationDirectoryPath = path.join(projectFolder, "platforms", "android");

Expand All @@ -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");
Expand Down Expand Up @@ -543,7 +534,7 @@ describe("Plugins service", () => {
name: ""
}];
}).future<IPluginData[]>()();
}
};

let appDestinationDirectoryPath = path.join(projectFolder, "platforms", "android");

Expand All @@ -560,7 +551,7 @@ describe("Plugins service", () => {
preparePluginNativeCode: (pluginData: IPluginData) => (() => {}).future<void>()()
}
}
}
};

// Ensure the pluginDestinationPath folder exists
let pluginPlatformsDirPath = path.join(appDestinationDirectoryPath, "app", "tns_modules", pluginName, "platforms", "android");
Expand All @@ -577,7 +568,7 @@ describe("Plugins service", () => {
pluginsService.add(pluginFolderPath).wait();

let expectedXml = '<?xmlversion="1.0"encoding="UTF-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.example.android.basiccontactables"android:versionCode="1"android:versionName="1.0"><uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permissionandroid:name="android.permission.INTERNET"/><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/Theme.Sample"><activityandroid:name="com.example.android.basiccontactables.MainActivity"android:label="@string/app_name"android:launchMode="singleTop"><meta-dataandroid:name="android.app.searchable"android:resource="@xml/searchable"/><intent-filter><actionandroid:name="android.intent.action.SEARCH"/></intent-filter><intent-filter><actionandroid:name="android.intent.action.MAIN"/></intent-filter></activity></application><uses-permissionandroid:name="android.permission.READ_CONTACTS"/></manifest>';
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();
Expand Down