Skip to content

Commit 76b1580

Browse files
author
Fatme
authored
Merge pull request #4395 from NativeScript/fatme/fix-pods-remove
fix: add new line at the end of the platform's section in order to remove it correctly
2 parents 90ba02c + 7583fa9 commit 76b1580

File tree

2 files changed

+124
-29
lines changed

2 files changed

+124
-29
lines changed

lib/services/cocoapods-platform-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager {
118118
result += ` ${podfilePlatformData.version}`;
119119
}
120120

121-
result += `${EOL}${podfilePlatformData.content}${EOL}${this.getPlatformSectionFooter()}`;
121+
result += `${EOL}${podfilePlatformData.content}${EOL}${this.getPlatformSectionFooter()}${EOL}`;
122122
return result;
123123
}
124124

test/cocoapods-service.ts

+123-28
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,128 @@ end`
913913
describe("remove duplicated platfoms from project podfile", () => {
914914
const projectRoot = "my/project/platforms/ios";
915915
const projectPodfilePath = path.join(projectRoot, "testProjectPodfilePath");
916+
let projectPodfileContent = "";
917+
918+
beforeEach(() => {
919+
cocoapodsService.getProjectPodfilePath = () => projectPodfilePath;
920+
projectPodfileContent = "";
921+
});
922+
923+
function setupMocks(pods: any[]): { projectData: IProjectData } {
924+
const podsPaths = pods.map(p => p.path);
925+
const projectData = testInjector.resolve("projectData");
926+
projectData.getAppResourcesDirectoryPath = () => "my/full/path/to/app/App_Resources";
927+
projectData.projectName = "projectName";
928+
929+
const fs = testInjector.resolve("fs");
930+
fs.exists = (filePath: string) => projectPodfilePath === filePath || _.includes(podsPaths, filePath);
931+
fs.readText = (filePath: string) => {
932+
if (filePath === projectPodfilePath) {
933+
return projectPodfileContent;
934+
}
935+
936+
const pod = _.find(pods, p => p.path === filePath);
937+
if (pod) {
938+
return pod.content;
939+
}
940+
};
941+
fs.writeFile = (filePath: string, fileContent: string) => {
942+
if (filePath === projectPodfilePath) {
943+
projectPodfileContent = fileContent;
944+
}
945+
};
946+
fs.deleteFile = () => ({});
947+
948+
return { projectData };
949+
}
950+
951+
const testCasesWithApplyAndRemove = [
952+
{
953+
name: "should select the podfile with highest platform after Podfile from App_Resources has been deleted",
954+
pods: [{
955+
name: "mySecondPluginWithPlatform",
956+
path: "node_modules/ mypath with spaces/mySecondPluginWithPlatform/Podfile",
957+
content: `platform :ios, '10.0'`
958+
}, {
959+
name: "myPluginWithoutPlatform",
960+
path: "node_modules/myPluginWithoutPlatform/Podfile",
961+
content: `pod 'myPod' ~> 0.3.4`
962+
}, {
963+
name: "myFirstPluginWithPlatform",
964+
path: "node_modules/myFirstPluginWithPlatform/Podfile",
965+
content: `platform :ios, '11.0'`
966+
}, {
967+
name: "App_Resources",
968+
path: "my/full/path/to/app/App_Resources/iOS/Podfile",
969+
content: `platform :ios, '8.0'`
970+
}],
971+
podsToRemove: [{
972+
name: "NSPodfileBase",
973+
path: "my/full/path/to/app/App_Resources/iOS/Podfile"
974+
}],
975+
expectedProjectPodfileContentAfterApply: `use_frameworks!
976+
977+
target "projectName" do
978+
# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
979+
# platform :ios, '8.0'
980+
# End Podfile
981+
982+
# Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
983+
# platform :ios, '11.0'
984+
# End Podfile
985+
986+
# Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
987+
pod 'myPod' ~> 0.3.4
988+
# End Podfile
989+
990+
# Begin Podfile - node_modules/ mypath with spaces/mySecondPluginWithPlatform/Podfile
991+
# platform :ios, '10.0'
992+
# End Podfile
993+
994+
# NativeScriptPlatformSection my/full/path/to/app/App_Resources/iOS/Podfile with 8.0
995+
platform :ios, '8.0'
996+
# End NativeScriptPlatformSection
997+
end`,
998+
expectedProjectPodfileContentAfterRemove: `use_frameworks!
999+
1000+
target "projectName" do
1001+
1002+
# Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
1003+
# platform :ios, '11.0'
1004+
# End Podfile
1005+
1006+
# Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
1007+
pod 'myPod' ~> 0.3.4
1008+
# End Podfile
1009+
1010+
# Begin Podfile - node_modules/ mypath with spaces/mySecondPluginWithPlatform/Podfile
1011+
# platform :ios, '10.0'
1012+
# End Podfile
1013+
# NativeScriptPlatformSection node_modules/myFirstPluginWithPlatform/Podfile with 11.0
1014+
platform :ios, '11.0'
1015+
# End NativeScriptPlatformSection
1016+
end`
1017+
}
1018+
];
1019+
1020+
_.each(testCasesWithApplyAndRemove, testCase => {
1021+
it(testCase.name, async () => {
1022+
const { projectData } = setupMocks(testCase.pods);
1023+
1024+
for (const pod of testCase.pods) {
1025+
await cocoapodsService.applyPodfileToProject(pod.name, pod.path, projectData, projectPodfilePath);
1026+
}
1027+
1028+
assert.deepEqual(projectPodfileContent, testCase.expectedProjectPodfileContentAfterApply);
1029+
1030+
for (const pod of testCase.podsToRemove) {
1031+
await cocoapodsService.removePodfileFromProject(pod.name, pod.path, projectData, projectPodfilePath);
1032+
}
1033+
1034+
assert.deepEqual(projectPodfileContent, testCase.expectedProjectPodfileContentAfterRemove);
1035+
});
1036+
});
1037+
9161038
const testCases = [
9171039
{
9181040
name: "should not change the Podfile when no platform",
@@ -1130,36 +1252,9 @@ end`
11301252
}
11311253
];
11321254

1133-
beforeEach(() => {
1134-
cocoapodsService.getProjectPodfilePath = () => projectPodfilePath;
1135-
});
1136-
11371255
_.each(testCases, testCase => {
11381256
it(testCase.name, async () => {
1139-
const podsPaths = testCase.pods.map(p => p.path);
1140-
let projectPodfileContent = "";
1141-
1142-
const projectData = testInjector.resolve("projectData");
1143-
projectData.getAppResourcesDirectoryPath = () => "my/full/path/to/app/App_Resources";
1144-
projectData.projectName = "projectName";
1145-
1146-
const fs = testInjector.resolve("fs");
1147-
fs.exists = (filePath: string) => projectPodfilePath === filePath || _.includes(podsPaths, filePath);
1148-
fs.readText = (filePath: string) => {
1149-
if (filePath === projectPodfilePath) {
1150-
return projectPodfileContent;
1151-
}
1152-
1153-
const pod = _.find(testCase.pods, p => p.path === filePath);
1154-
if (pod) {
1155-
return pod.content;
1156-
}
1157-
};
1158-
fs.writeFile = (filePath: string, fileContent: string) => {
1159-
if (filePath === projectPodfilePath) {
1160-
projectPodfileContent = fileContent;
1161-
}
1162-
};
1257+
const { projectData } = setupMocks(testCase.pods);
11631258
cocoapodsService.removePodfileFromProject = () => ({});
11641259

11651260
for (const pod of testCase.pods) {

0 commit comments

Comments
 (0)