@@ -18,16 +18,14 @@ import PlatformsDataLib = require("../lib/platforms-data");
1818import ProjectDataServiceLib = require( "../lib/services/project-data-service" ) ;
1919import helpers = require( "../lib/common/helpers" ) ;
2020import ProjectFilesManagerLib = require( "../lib/services/project-files-manager" ) ;
21- import os = require( "os" ) ;
22-
21+ import { EOL } from "os" ;
2322import PluginsServiceLib = require( "../lib/services/plugins-service" ) ;
2423import AddPluginCommandLib = require( "../lib/commands/plugin/add-plugin" ) ;
25-
26- import path = require ( "path" ) ;
27- import temp = require ( "temp" ) ;
24+ import { assert } from "chai" ;
25+ import * as path from "path" ;
26+ import * as temp from "temp" ;
2827temp . track ( ) ;
2928
30- let assert = require ( "chai" ) . assert ;
3129let isErrorThrown = false ;
3230
3331function createTestInjector ( ) {
@@ -114,10 +112,10 @@ function addPluginWhenExpectingToFail(testInjector: IInjector, plugin: string, e
114112 name : ""
115113 } ] ;
116114 } ) . future < IPluginData [ ] > ( ) ( ) ;
117- }
115+ } ;
118116 pluginsService . ensureAllDependenciesAreInstalled = ( ) => {
119117 return ( ( ) => { } ) . future < void > ( ) ( ) ;
120- }
118+ } ;
121119
122120 mockBeginCommand ( testInjector , "Exception: " + expectedErrorMessage ) ;
123121
@@ -185,7 +183,7 @@ describe("Plugins service", () => {
185183 name : "plugin1"
186184 } ] ;
187185 } ) . future < IPluginData [ ] > ( ) ( ) ;
188- }
186+ } ;
189187
190188 mockBeginCommand ( testInjector , "Exception: " + 'Plugin "plugin1" is already installed.' ) ;
191189
@@ -224,7 +222,7 @@ describe("Plugins service", () => {
224222 logger . warn = ( message : string ) => {
225223 assert . equal ( message , expectedWarningMessage ) ;
226224 isWarningMessageShown = true ;
227- }
225+ } ;
228226
229227 // Mock pluginsService
230228 let pluginsService = testInjector . resolve ( "pluginsService" ) ;
@@ -234,7 +232,7 @@ describe("Plugins service", () => {
234232 name : ""
235233 } ] ;
236234 } ) . future < IPluginData [ ] > ( ) ( ) ;
237- }
235+ } ;
238236
239237 // Mock platformsData
240238 let platformsData = testInjector . resolve ( "platformsData" ) ;
@@ -243,10 +241,9 @@ describe("Plugins service", () => {
243241 appDestinationDirectoryPath : path . join ( projectFolder , "platforms" , "android" ) ,
244242 frameworkPackageName : "tns-android"
245243 }
246- }
244+ } ;
247245
248- let commandsService = testInjector . resolve ( "commandsService" ) ;
249- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginFolderPath ] ) . wait ( ) ;
246+ pluginsService . add ( pluginFolderPath ) . wait ( ) ;
250247
251248 assert . isTrue ( isWarningMessageShown ) ;
252249 } ) ;
@@ -261,10 +258,9 @@ describe("Plugins service", () => {
261258 name : ""
262259 } ] ;
263260 } ) . future < IPluginData [ ] > ( ) ( ) ;
264- }
261+ } ;
265262
266- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
267- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginName ] ) . wait ( ) ;
263+ pluginsService . add ( pluginName ) . wait ( ) ;
268264
269265 let fs = testInjector . resolve ( "fs" ) ;
270266
@@ -283,10 +279,9 @@ describe("Plugins service", () => {
283279 // Asserts that the plugin is added in package.json file
284280 let packageJsonContent = fs . readJson ( path . join ( projectFolder , "package.json" ) ) . wait ( ) ;
285281 let actualDependencies = packageJsonContent . dependencies ;
286- let expectedDependencies = {
287- "plugin1" : "^1.0.3"
288- } ;
289- assert . deepEqual ( actualDependencies , expectedDependencies ) ;
282+ let expectedDependencies = { "plugin1" : "^1.0.3" } ;
283+ let expectedDependenciesExact = { "plugin1" : "1.0.3" } ;
284+ assert . isTrue ( _ . isEqual ( actualDependencies , expectedDependencies ) || _ . isEqual ( actualDependencies , expectedDependenciesExact ) ) ;
290285 } ) ;
291286 it ( "adds plugin by name and version" , ( ) => {
292287 let pluginName = "plugin1" ;
@@ -299,10 +294,9 @@ describe("Plugins service", () => {
299294 name : ""
300295 } ] ;
301296 } ) . future < IPluginData [ ] > ( ) ( ) ;
302- }
297+ } ;
303298
304- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
305- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginName + "@1.0.0" ] ) . wait ( ) ;
299+ pluginsService . add ( pluginName + "@1.0.0" ) . wait ( ) ;
306300
307301 let fs = testInjector . resolve ( "fs" ) ;
308302
@@ -321,10 +315,9 @@ describe("Plugins service", () => {
321315 // Assert that the plugin is added in package.json file
322316 let packageJsonContent = fs . readJson ( path . join ( projectFolder , "package.json" ) ) . wait ( ) ;
323317 let actualDependencies = packageJsonContent . dependencies ;
324- let expectedDependencies = {
325- "plugin1" : "^1.0.0"
326- } ;
327- assert . deepEqual ( actualDependencies , expectedDependencies ) ;
318+ let expectedDependencies = { "plugin1" : "^1.0.0" } ;
319+ let expectedDependenciesExact = { "plugin1" : "1.0.0" } ;
320+ assert . isTrue ( _ . isEqual ( actualDependencies , expectedDependencies ) || _ . isEqual ( actualDependencies , expectedDependenciesExact ) ) ;
328321 } ) ;
329322 it ( "adds plugin by local path" , ( ) => {
330323 // Creates a plugin in tempFolder
@@ -350,10 +343,9 @@ describe("Plugins service", () => {
350343 name : ""
351344 } ] ;
352345 } ) . future < IPluginData [ ] > ( ) ( ) ;
353- }
346+ } ;
354347
355- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
356- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginFolderPath ] ) . wait ( ) ;
348+ pluginsService . add ( pluginFolderPath ) . wait ( ) ;
357349
358350 // Assert that the all plugin's content is successfully added to node_modules folder
359351 let nodeModulesFolderPath = path . join ( projectFolder , "node_modules" ) ;
@@ -395,14 +387,13 @@ describe("Plugins service", () => {
395387 name : ""
396388 } ] ;
397389 } ) . future < IPluginData [ ] > ( ) ( ) ;
398- }
390+ } ;
399391
400392 // Mock options
401393 let options = testInjector . resolve ( "options" ) ;
402394 options . production = true ;
403395
404- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
405- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginFolderPath ] ) . wait ( ) ;
396+ pluginsService . add ( pluginFolderPath ) . wait ( ) ;
406397
407398 let nodeModulesFolderPath = path . join ( projectFolder , "node_modules" ) ;
408399 assert . isFalse ( fs . exists ( path . join ( nodeModulesFolderPath , pluginName , "node_modules" , "grunt" ) ) . wait ( ) ) ;
@@ -437,7 +428,7 @@ describe("Plugins service", () => {
437428 name : ""
438429 } ] ;
439430 } ) . future < IPluginData [ ] > ( ) ( ) ;
440- }
431+ } ;
441432
442433 // Mock options
443434 let options = testInjector . resolve ( "options" ) ;
@@ -481,7 +472,7 @@ describe("Plugins service", () => {
481472 name : ""
482473 } ] ;
483474 } ) . future < IPluginData [ ] > ( ) ( ) ;
484- }
475+ } ;
485476
486477 let appDestinationDirectoryPath = path . join ( projectFolder , "platforms" , "android" ) ;
487478
@@ -493,7 +484,7 @@ describe("Plugins service", () => {
493484 frameworkPackageName : "tns-android" ,
494485 configurationFileName : "AndroidManifest.xml"
495486 }
496- }
487+ } ;
497488
498489 // Ensure the pluginDestinationPath folder exists
499490 let pluginPlatformsDirPath = path . join ( appDestinationDirectoryPath , "app" , "tns_modules" , pluginName , "platforms" , "android" ) ;
@@ -543,7 +534,7 @@ describe("Plugins service", () => {
543534 name : ""
544535 } ] ;
545536 } ) . future < IPluginData [ ] > ( ) ( ) ;
546- }
537+ } ;
547538
548539 let appDestinationDirectoryPath = path . join ( projectFolder , "platforms" , "android" ) ;
549540
@@ -560,7 +551,7 @@ describe("Plugins service", () => {
560551 preparePluginNativeCode : ( pluginData : IPluginData ) => ( ( ) => { } ) . future < void > ( ) ( )
561552 }
562553 }
563- }
554+ } ;
564555
565556 // Ensure the pluginDestinationPath folder exists
566557 let pluginPlatformsDirPath = path . join ( appDestinationDirectoryPath , "app" , "tns_modules" , pluginName , "platforms" , "android" ) ;
@@ -577,7 +568,7 @@ describe("Plugins service", () => {
577568 pluginsService . add ( pluginFolderPath ) . wait ( ) ;
578569
579570 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>' ;
580- expectedXml = helpers . stringReplaceAll ( expectedXml , os . EOL , "" ) ;
571+ expectedXml = helpers . stringReplaceAll ( expectedXml , EOL , "" ) ;
581572 expectedXml = helpers . stringReplaceAll ( expectedXml , " " , "" ) ;
582573
583574 let actualXml = fs . readText ( path . join ( appDestinationDirectoryPath , "AndroidManifest.xml" ) ) . wait ( ) ;
0 commit comments