@@ -4,6 +4,7 @@ import { CocoaPodsService } from "../lib/services/cocoapods-service";
4
4
import { EOL } from "os" ;
5
5
import { LoggerStub , ErrorsStub } from "./stubs" ;
6
6
import { XcconfigService } from "../lib/services/xcconfig-service" ;
7
+ import * as path from "path" ;
7
8
8
9
interface IMergePodfileHooksTestCase {
9
10
input : string ;
@@ -905,4 +906,177 @@ end`
905
906
906
907
} ) ;
907
908
} ) ;
909
+
910
+ describe ( "removeDuplicatedPlatfomsFromProjectPodFile" , ( ) => {
911
+ const projectRoot = "my/project/platforms/ios" ;
912
+ const projectPodfilePath = path . join ( projectRoot , "testProjectPodfilePath" ) ;
913
+ const testCases = [
914
+ {
915
+ name : "should not change the Podfile when no platform" ,
916
+ projectPodfileContent : `use_frameworks!
917
+ target "projectName" do
918
+
919
+ # Begin Podfile - pluginPlatformsFolderPath1/Podfile
920
+
921
+ pod 'Firebase', '~> 3.1'
922
+ # End Podfile` ,
923
+ expectedProjectPodfileContent : `use_frameworks!
924
+ target "projectName" do
925
+
926
+ # Begin Podfile - pluginPlatformsFolderPath1/Podfile
927
+
928
+ pod 'Firebase', '~> 3.1'
929
+ # End Podfile`
930
+ } ,
931
+ {
932
+ name : "should not change the Podfile when there is only one platform" ,
933
+ projectPodfileContent : `use_frameworks!
934
+ target "projectName" do
935
+
936
+ # Begin Podfile - pluginPlatformsFolderPath1/Podfile
937
+
938
+ platform :ios, '9.0'
939
+ # End Podfile` ,
940
+ expectedProjectPodfileContent : `use_frameworks!
941
+ target "projectName" do
942
+
943
+ # Begin Podfile - pluginPlatformsFolderPath1/Podfile
944
+
945
+ platform :ios, '9.0'
946
+ # End Podfile`
947
+ } ,
948
+ {
949
+ name : "should select the platform from Podfile in App_Resources" ,
950
+ projectPodfileContent : `use_frameworks!
951
+ target "projectName" do
952
+
953
+ # Begin Podfile - ${ projectRoot } /App_Resources/iOS/Podfile
954
+
955
+ platform :ios, '9.0'
956
+ # End Podfile
957
+
958
+ # Begin Podfile - node_modules/myPluginWithPlatform/Podfile
959
+
960
+ platform :ios, '10.0'
961
+ # End Podfile
962
+
963
+ # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
964
+ myPod ~> 0.3.4
965
+ # End Podfile` ,
966
+ expectedProjectPodfileContent : `use_frameworks!
967
+ target "projectName" do
968
+
969
+ # Begin Podfile - ${ projectRoot } /App_Resources/iOS/Podfile
970
+
971
+ platform :ios, '9.0'
972
+ # End Podfile
973
+
974
+ # Begin Podfile - node_modules/myPluginWithPlatform/Podfile
975
+
976
+
977
+ # End Podfile
978
+
979
+ # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
980
+ myPod ~> 0.3.4
981
+ # End Podfile`
982
+ } ,
983
+ {
984
+ name : "should select the platform with highest version from plugins" ,
985
+ projectPodfileContent : `use_frameworks!
986
+ target "projectName" do
987
+
988
+ # Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
989
+
990
+ platform :ios, '9.0'
991
+ # End Podfile
992
+
993
+ # Begin Podfile - node_modules/mySecondPluginWithPlatform/Podfile
994
+
995
+ platform :ios, '10.0'
996
+ # End Podfile
997
+
998
+ # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
999
+ myPod ~> 0.3.4
1000
+ # End Podfile` ,
1001
+ expectedProjectPodfileContent : `use_frameworks!
1002
+ target "projectName" do
1003
+
1004
+ # Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
1005
+
1006
+
1007
+ # End Podfile
1008
+
1009
+ # Begin Podfile - node_modules/mySecondPluginWithPlatform/Podfile
1010
+
1011
+ platform :ios, '10.0'
1012
+ # End Podfile
1013
+
1014
+ # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
1015
+ myPod ~> 0.3.4
1016
+ # End Podfile`
1017
+ } ,
1018
+ {
1019
+ name : "should select the platform without version when no Podfile in App_Resources" ,
1020
+ projectPodfileContent : `use_frameworks!
1021
+ target "projectName" do
1022
+
1023
+ # Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
1024
+
1025
+ platform :ios
1026
+ # End Podfile
1027
+
1028
+ # Begin Podfile - node_modules/mySecondPluginWithPlatform/Podfile
1029
+
1030
+ platform :ios, '10.0'
1031
+ # End Podfile
1032
+
1033
+ # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
1034
+ myPod ~> 0.3.4
1035
+ # End Podfile` ,
1036
+ expectedProjectPodfileContent : `use_frameworks!
1037
+ target "projectName" do
1038
+
1039
+ # Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
1040
+
1041
+ platform :ios
1042
+ # End Podfile
1043
+
1044
+ # Begin Podfile - node_modules/mySecondPluginWithPlatform/Podfile
1045
+
1046
+
1047
+ # End Podfile
1048
+
1049
+ # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
1050
+ myPod ~> 0.3.4
1051
+ # End Podfile`
1052
+ }
1053
+ ] ;
1054
+
1055
+ beforeEach ( ( ) => {
1056
+ cocoapodsService . getProjectPodfilePath = ( ) => projectPodfilePath ;
1057
+ } ) ;
1058
+
1059
+ _ . each ( testCases , testCase => {
1060
+ it ( testCase . name , async ( ) => {
1061
+ let actualPodfileContent = "" ;
1062
+
1063
+ const fs = testInjector . resolve ( "fs" ) ;
1064
+ fs . exists = ( filePath : string ) => projectPodfilePath === filePath ;
1065
+ fs . readText = ( filePath : string ) => {
1066
+ if ( filePath === projectPodfilePath ) {
1067
+ return testCase . projectPodfileContent ;
1068
+ }
1069
+ } ;
1070
+ fs . writeFile = ( filePath : string , fileContent : string ) => {
1071
+ if ( filePath === projectPodfilePath ) {
1072
+ actualPodfileContent = fileContent ;
1073
+ }
1074
+ } ;
1075
+
1076
+ await cocoapodsService . removeDuplicatedPlatfomsFromProjectPodFile ( projectRoot ) ;
1077
+
1078
+ assert . deepEqual ( actualPodfileContent , testCase . expectedProjectPodfileContent ) ;
1079
+ } ) ;
1080
+ } ) ;
1081
+ } ) ;
908
1082
} ) ;
0 commit comments