@@ -18,16 +18,14 @@ import PlatformsDataLib = require("../lib/platforms-data");
18
18
import ProjectDataServiceLib = require( "../lib/services/project-data-service" ) ;
19
19
import helpers = require( "../lib/common/helpers" ) ;
20
20
import ProjectFilesManagerLib = require( "../lib/services/project-files-manager" ) ;
21
- import os = require( "os" ) ;
22
-
21
+ import { EOL } from "os" ;
23
22
import PluginsServiceLib = require( "../lib/services/plugins-service" ) ;
24
23
import 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" ;
28
27
temp . track ( ) ;
29
28
30
- let assert = require ( "chai" ) . assert ;
31
29
let isErrorThrown = false ;
32
30
33
31
function createTestInjector ( ) {
@@ -114,10 +112,10 @@ function addPluginWhenExpectingToFail(testInjector: IInjector, plugin: string, e
114
112
name : ""
115
113
} ] ;
116
114
} ) . future < IPluginData [ ] > ( ) ( ) ;
117
- }
115
+ } ;
118
116
pluginsService . ensureAllDependenciesAreInstalled = ( ) => {
119
117
return ( ( ) => { } ) . future < void > ( ) ( ) ;
120
- }
118
+ } ;
121
119
122
120
mockBeginCommand ( testInjector , "Exception: " + expectedErrorMessage ) ;
123
121
@@ -185,7 +183,7 @@ describe("Plugins service", () => {
185
183
name : "plugin1"
186
184
} ] ;
187
185
} ) . future < IPluginData [ ] > ( ) ( ) ;
188
- }
186
+ } ;
189
187
190
188
mockBeginCommand ( testInjector , "Exception: " + 'Plugin "plugin1" is already installed.' ) ;
191
189
@@ -224,7 +222,7 @@ describe("Plugins service", () => {
224
222
logger . warn = ( message : string ) => {
225
223
assert . equal ( message , expectedWarningMessage ) ;
226
224
isWarningMessageShown = true ;
227
- }
225
+ } ;
228
226
229
227
// Mock pluginsService
230
228
let pluginsService = testInjector . resolve ( "pluginsService" ) ;
@@ -234,7 +232,7 @@ describe("Plugins service", () => {
234
232
name : ""
235
233
} ] ;
236
234
} ) . future < IPluginData [ ] > ( ) ( ) ;
237
- }
235
+ } ;
238
236
239
237
// Mock platformsData
240
238
let platformsData = testInjector . resolve ( "platformsData" ) ;
@@ -243,10 +241,9 @@ describe("Plugins service", () => {
243
241
appDestinationDirectoryPath : path . join ( projectFolder , "platforms" , "android" ) ,
244
242
frameworkPackageName : "tns-android"
245
243
}
246
- }
244
+ } ;
247
245
248
- let commandsService = testInjector . resolve ( "commandsService" ) ;
249
- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginFolderPath ] ) . wait ( ) ;
246
+ pluginsService . add ( pluginFolderPath ) . wait ( ) ;
250
247
251
248
assert . isTrue ( isWarningMessageShown ) ;
252
249
} ) ;
@@ -261,10 +258,9 @@ describe("Plugins service", () => {
261
258
name : ""
262
259
} ] ;
263
260
} ) . future < IPluginData [ ] > ( ) ( ) ;
264
- }
261
+ } ;
265
262
266
- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
267
- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginName ] ) . wait ( ) ;
263
+ pluginsService . add ( pluginName ) . wait ( ) ;
268
264
269
265
let fs = testInjector . resolve ( "fs" ) ;
270
266
@@ -283,10 +279,9 @@ describe("Plugins service", () => {
283
279
// Asserts that the plugin is added in package.json file
284
280
let packageJsonContent = fs . readJson ( path . join ( projectFolder , "package.json" ) ) . wait ( ) ;
285
281
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 ) ) ;
290
285
} ) ;
291
286
it ( "adds plugin by name and version" , ( ) => {
292
287
let pluginName = "plugin1" ;
@@ -299,10 +294,9 @@ describe("Plugins service", () => {
299
294
name : ""
300
295
} ] ;
301
296
} ) . future < IPluginData [ ] > ( ) ( ) ;
302
- }
297
+ } ;
303
298
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 ( ) ;
306
300
307
301
let fs = testInjector . resolve ( "fs" ) ;
308
302
@@ -321,10 +315,9 @@ describe("Plugins service", () => {
321
315
// Assert that the plugin is added in package.json file
322
316
let packageJsonContent = fs . readJson ( path . join ( projectFolder , "package.json" ) ) . wait ( ) ;
323
317
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 ) ) ;
328
321
} ) ;
329
322
it ( "adds plugin by local path" , ( ) => {
330
323
// Creates a plugin in tempFolder
@@ -350,10 +343,9 @@ describe("Plugins service", () => {
350
343
name : ""
351
344
} ] ;
352
345
} ) . future < IPluginData [ ] > ( ) ( ) ;
353
- }
346
+ } ;
354
347
355
- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
356
- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginFolderPath ] ) . wait ( ) ;
348
+ pluginsService . add ( pluginFolderPath ) . wait ( ) ;
357
349
358
350
// Assert that the all plugin's content is successfully added to node_modules folder
359
351
let nodeModulesFolderPath = path . join ( projectFolder , "node_modules" ) ;
@@ -395,14 +387,13 @@ describe("Plugins service", () => {
395
387
name : ""
396
388
} ] ;
397
389
} ) . future < IPluginData [ ] > ( ) ( ) ;
398
- }
390
+ } ;
399
391
400
392
// Mock options
401
393
let options = testInjector . resolve ( "options" ) ;
402
394
options . production = true ;
403
395
404
- let commandsService = testInjector . resolve ( CommandsServiceLib . CommandsService ) ;
405
- commandsService . tryExecuteCommand ( "plugin|add" , [ pluginFolderPath ] ) . wait ( ) ;
396
+ pluginsService . add ( pluginFolderPath ) . wait ( ) ;
406
397
407
398
let nodeModulesFolderPath = path . join ( projectFolder , "node_modules" ) ;
408
399
assert . isFalse ( fs . exists ( path . join ( nodeModulesFolderPath , pluginName , "node_modules" , "grunt" ) ) . wait ( ) ) ;
@@ -437,7 +428,7 @@ describe("Plugins service", () => {
437
428
name : ""
438
429
} ] ;
439
430
} ) . future < IPluginData [ ] > ( ) ( ) ;
440
- }
431
+ } ;
441
432
442
433
// Mock options
443
434
let options = testInjector . resolve ( "options" ) ;
@@ -481,7 +472,7 @@ describe("Plugins service", () => {
481
472
name : ""
482
473
} ] ;
483
474
} ) . future < IPluginData [ ] > ( ) ( ) ;
484
- }
475
+ } ;
485
476
486
477
let appDestinationDirectoryPath = path . join ( projectFolder , "platforms" , "android" ) ;
487
478
@@ -493,7 +484,7 @@ describe("Plugins service", () => {
493
484
frameworkPackageName : "tns-android" ,
494
485
configurationFileName : "AndroidManifest.xml"
495
486
}
496
- }
487
+ } ;
497
488
498
489
// Ensure the pluginDestinationPath folder exists
499
490
let pluginPlatformsDirPath = path . join ( appDestinationDirectoryPath , "app" , "tns_modules" , pluginName , "platforms" , "android" ) ;
@@ -543,7 +534,7 @@ describe("Plugins service", () => {
543
534
name : ""
544
535
} ] ;
545
536
} ) . future < IPluginData [ ] > ( ) ( ) ;
546
- }
537
+ } ;
547
538
548
539
let appDestinationDirectoryPath = path . join ( projectFolder , "platforms" , "android" ) ;
549
540
@@ -560,7 +551,7 @@ describe("Plugins service", () => {
560
551
preparePluginNativeCode : ( pluginData : IPluginData ) => ( ( ) => { } ) . future < void > ( ) ( )
561
552
}
562
553
}
563
- }
554
+ } ;
564
555
565
556
// Ensure the pluginDestinationPath folder exists
566
557
let pluginPlatformsDirPath = path . join ( appDestinationDirectoryPath , "app" , "tns_modules" , pluginName , "platforms" , "android" ) ;
@@ -577,7 +568,7 @@ describe("Plugins service", () => {
577
568
pluginsService . add ( pluginFolderPath ) . wait ( ) ;
578
569
579
570
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 , "" ) ;
581
572
expectedXml = helpers . stringReplaceAll ( expectedXml , " " , "" ) ;
582
573
583
574
let actualXml = fs . readText ( path . join ( appDestinationDirectoryPath , "AndroidManifest.xml" ) ) . wait ( ) ;
0 commit comments