@@ -207,31 +207,6 @@ async function addPluginWhenExpectingToFail(testInjector: IInjector, plugin: str
207
207
assert . isTrue ( isErrorThrown ) ;
208
208
}
209
209
210
- function createAndroidManifestFile ( projectFolder : string , fs : IFileSystem ) : void {
211
- const manifest = `
212
- <?xml version="1.0" encoding="UTF-8"?>
213
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.basiccontactables" android:versionCode="1" android:versionName="1.0" >
214
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
215
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
216
- <uses-permission android:name="android.permission.INTERNET"/>
217
- <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.Sample" >
218
- <activity android:name="com.example.android.basiccontactables.MainActivity" android:label="@string/app_name" android:launchMode="singleTop">
219
- <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
220
- <intent-filter>
221
- <action android:name="android.intent.action.SEARCH" />
222
- </intent-filter>
223
- <intent-filter>
224
- <action android:name="android.intent.action.MAIN" />
225
- </intent-filter>
226
- </activity>
227
- </application>
228
- </manifest>` ;
229
-
230
- fs . createDirectory ( path . join ( projectFolder , "platforms" ) ) ;
231
- fs . createDirectory ( path . join ( projectFolder , "platforms" , "android" ) ) ;
232
- fs . writeFile ( path . join ( projectFolder , "platforms" , "android" , "AndroidManifest.xml" ) , manifest ) ;
233
- }
234
-
235
210
describe ( "Plugins service" , ( ) => {
236
211
let testInjector : IInjector ;
237
212
const commands = [ "add" , "install" ] ;
@@ -505,76 +480,6 @@ describe("Plugins service", () => {
505
480
} ) ;
506
481
} ) ;
507
482
508
- describe ( "merge xmls tests" , ( ) => {
509
- beforeEach ( ( ) => {
510
- testInjector = createTestInjector ( ) ;
511
- testInjector . registerCommand ( "plugin|add" , AddPluginCommand ) ;
512
- } ) ;
513
- it ( "fails if the plugin contains incorrect xml" , async ( ) => {
514
- const pluginName = "mySamplePlugin" ;
515
- const projectFolder = createProjectFile ( testInjector ) ;
516
- const pluginFolderPath = path . join ( projectFolder , pluginName ) ;
517
- const pluginJsonData : IDependencyData = {
518
- name : pluginName ,
519
- nativescript : {
520
- platforms : {
521
- android : "0.10.0"
522
- }
523
- } ,
524
- depth : 0 ,
525
- directory : "some dir"
526
- } ;
527
- const fs = testInjector . resolve ( "fs" ) ;
528
- fs . writeJson ( path . join ( pluginFolderPath , "package.json" ) , pluginJsonData ) ;
529
-
530
- // Adds AndroidManifest.xml file in platforms/android folder
531
- createAndroidManifestFile ( projectFolder , fs ) ;
532
-
533
- // Mock plugins service
534
- const pluginsService : IPluginsService = testInjector . resolve ( "pluginsService" ) ;
535
- pluginsService . getAllInstalledPlugins = async ( pData : IProjectData ) => {
536
- return < any [ ] > [ { name : "" } ] ;
537
- } ;
538
-
539
- const appDestinationDirectoryPath = path . join ( projectFolder , "platforms" , "android" ) ;
540
-
541
- // Mock platformsDataService
542
- const platformsDataService = testInjector . resolve ( "platformsDataService" ) ;
543
- platformsDataService . getPlatformData = ( platform : string ) => {
544
- return {
545
- appDestinationDirectoryPath : appDestinationDirectoryPath ,
546
- frameworkPackageName : "tns-android" ,
547
- configurationFileName : "AndroidManifest.xml" ,
548
- normalizedPlatformName : "Android" ,
549
- platformProjectService : {
550
- preparePluginNativeCode : ( pluginData : IPluginData ) => Promise . resolve ( )
551
- }
552
- } ;
553
- } ;
554
-
555
- // Ensure the pluginDestinationPath folder exists
556
- const pluginPlatformsDirPath = path . join ( projectFolder , "node_modules" , pluginName , "platforms" , "android" ) ;
557
- const projectData : IProjectData = testInjector . resolve ( "projectData" ) ;
558
- projectData . initializeProjectData ( ) ;
559
- fs . ensureDirectoryExists ( pluginPlatformsDirPath ) ;
560
-
561
- // Creates invalid plugin's AndroidManifest.xml file
562
- const xml = '<?xml version="1.0" encoding="UTF-8"?>' +
563
- '<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.basiccontactables" android:versionCode="1" android:versionName="1.0" >' +
564
- '<uses-permission android:name="android.permission.READ_CONTACTS"/>' ;
565
- const pluginConfigurationFilePath = path . join ( pluginPlatformsDirPath , "AndroidManifest.xml" ) ;
566
- fs . writeFile ( pluginConfigurationFilePath , xml ) ;
567
-
568
- // Expected error message. The assertion happens in mockBeginCommand
569
- const expectedErrorMessage = `Exception: Invalid xml file ${ pluginConfigurationFilePath } . Additional technical information: element parse error: Exception: Invalid xml file ` +
570
- `${ pluginConfigurationFilePath } . Additional technical information: unclosed xml attribute` +
571
- `\n@#[line:1,col:39].` +
572
- `\n@#[line:1,col:39].` ;
573
- mockBeginCommand ( testInjector , expectedErrorMessage ) ;
574
- await pluginsService . preparePluginNativeCode ( { pluginData : pluginsService . convertToPluginData ( pluginJsonData , projectData . projectDir ) , platform : "android" , projectData} ) ;
575
- } ) ;
576
- } ) ;
577
-
578
483
describe ( "preparePluginNativeCode" , ( ) => {
579
484
const setupTest = ( opts : { hasChangesInShasums ?: boolean , newPluginHashes ?: IStringDictionary , buildDataFileExists ?: boolean , hasPluginPlatformsDir ?: boolean } ) : any => {
580
485
const testData : any = {
@@ -599,7 +504,8 @@ describe("Plugins service", () => {
599
504
const pluginHashes = opts . newPluginHashes || { "file1" : "hash1" } ;
600
505
const samplePluginData : IPluginData = < any > {
601
506
fullPath : "plugin_full_path" ,
602
- name : "plugin_name"
507
+ name : "plugin_name" ,
508
+ pluginPlatformsFolderPath : ( _platform : string ) => path . join ( "plugin_dir" , "platforms" , _platform . toLowerCase ( ) )
603
509
} ;
604
510
605
511
unitTestsInjector . register ( "filesHashService" , {
@@ -646,22 +552,85 @@ describe("Plugins service", () => {
646
552
647
553
it ( "does not prepare the files when plugin does not have platforms dir" , async ( ) => {
648
554
const testData = setupTest ( { hasPluginPlatformsDir : false } ) ;
649
- await testData . pluginsService . preparePluginNativeCode ( { pluginData : testData . pluginData , platform, projectData} ) ;
555
+ await testData . pluginsService . preparePluginNativeCode ( { pluginData : testData . pluginData , platform, projectData } ) ;
650
556
assert . isFalse ( testData . isPreparePluginNativeCodeCalled ) ;
651
557
} ) ;
652
558
653
559
it ( "prepares the files when plugin has platforms dir and has not been built before" , async ( ) => {
654
560
const newPluginHashes = { "file" : "hash" } ;
655
561
const testData = setupTest ( { newPluginHashes, hasPluginPlatformsDir : true } ) ;
656
- await testData . pluginsService . preparePluginNativeCode ( { pluginData : testData . pluginData , platform, projectData} ) ;
562
+ await testData . pluginsService . preparePluginNativeCode ( { pluginData : testData . pluginData , platform, projectData } ) ;
657
563
assert . isTrue ( testData . isPreparePluginNativeCodeCalled ) ;
658
564
assert . deepEqual ( testData . dataPassedToWriteJson , { [ testData . pluginData . name ] : newPluginHashes } ) ;
659
565
} ) ;
660
566
661
567
it ( "does not prepare the files when plugin has platforms dir and files have not changed since then" , async ( ) => {
662
568
const testData = setupTest ( { hasChangesInShasums : false , buildDataFileExists : true , hasPluginPlatformsDir : true } ) ;
663
- await testData . pluginsService . preparePluginNativeCode ( { pluginData : testData . pluginData , platform, projectData} ) ;
569
+ await testData . pluginsService . preparePluginNativeCode ( { pluginData : testData . pluginData , platform, projectData } ) ;
664
570
assert . isFalse ( testData . isPreparePluginNativeCodeCalled ) ;
665
571
} ) ;
666
572
} ) ;
573
+
574
+ describe ( "convertToPluginData" , ( ) => {
575
+ const createUnitTestsInjector = ( ) => {
576
+ const unitTestsInjector = new Yok ( ) ;
577
+ unitTestsInjector . register ( "platformsDataService" , { } ) ;
578
+ unitTestsInjector . register ( "filesHashService" , { } ) ;
579
+ unitTestsInjector . register ( "fs" , { } ) ;
580
+ unitTestsInjector . register ( "packageManager" , { } ) ;
581
+ unitTestsInjector . register ( "options" , { } ) ;
582
+ unitTestsInjector . register ( "logger" , { } ) ;
583
+ unitTestsInjector . register ( "errors" , { } ) ;
584
+ unitTestsInjector . register ( "injector" , unitTestsInjector ) ;
585
+ unitTestsInjector . register ( "mobileHelper" , MobileHelper ) ;
586
+ unitTestsInjector . register ( "devicePlatformsConstants" , DevicePlatformsConstants ) ;
587
+ unitTestsInjector . register ( "nodeModulesDependenciesBuilder" , { } ) ;
588
+ return unitTestsInjector ;
589
+ } ;
590
+
591
+ const pluginDir = "pluginDir" ;
592
+ const dataFromPluginPackageJson = {
593
+ name : "name" ,
594
+ version : "1.0.0" ,
595
+ directory : pluginDir ,
596
+ nativescript : {
597
+ platforms : {
598
+ ios : "6.0.0" ,
599
+ android : "6.0.0"
600
+ }
601
+ }
602
+ } ;
603
+
604
+ it ( "returns correct pluginData" , ( ) => {
605
+ const unitTestsInjector = createUnitTestsInjector ( ) ;
606
+ const pluginsService : PluginsService = unitTestsInjector . resolve ( PluginsService ) ;
607
+ const pluginData = pluginsService . convertToPluginData ( dataFromPluginPackageJson , "my project dir" ) ;
608
+ // Remove the comparison of a function
609
+ delete pluginData [ "pluginPlatformsFolderPath" ] ;
610
+ assert . deepEqual ( pluginData , < any > {
611
+ name : "name" ,
612
+ version : "1.0.0" ,
613
+ fullPath : pluginDir ,
614
+ isPlugin : true ,
615
+ platformsData : { android : "6.0.0" , ios : "6.0.0" } ,
616
+ pluginVariables : undefined
617
+ } ) ;
618
+ } ) ;
619
+
620
+ it ( "always returns lowercased platform in the path to plugins dir" , ( ) => {
621
+ const unitTestsInjector = createUnitTestsInjector ( ) ;
622
+ const pluginsService : PluginsService = unitTestsInjector . resolve ( PluginsService ) ;
623
+ const pluginData = pluginsService . convertToPluginData ( dataFromPluginPackageJson , "my project dir" ) ;
624
+
625
+ const expectediOSPath = path . join ( pluginDir , "platforms" , "ios" ) ;
626
+ const expectedAndroidPath = path . join ( pluginDir , "platforms" , "android" ) ;
627
+ assert . equal ( pluginData . pluginPlatformsFolderPath ( "iOS" ) , expectediOSPath ) ;
628
+ assert . equal ( pluginData . pluginPlatformsFolderPath ( "ios" ) , expectediOSPath ) ;
629
+ assert . equal ( pluginData . pluginPlatformsFolderPath ( "IOS" ) , expectediOSPath ) ;
630
+
631
+ assert . equal ( pluginData . pluginPlatformsFolderPath ( "Android" ) , expectedAndroidPath ) ;
632
+ assert . equal ( pluginData . pluginPlatformsFolderPath ( "android" ) , expectedAndroidPath ) ;
633
+ assert . equal ( pluginData . pluginPlatformsFolderPath ( "ANDROID" ) , expectedAndroidPath ) ;
634
+ } ) ;
635
+ } ) ;
667
636
} ) ;
0 commit comments