Skip to content

Commit e65efeb

Browse files
Merge pull request #5067 from NativeScript/kddimitrov/pods-override-tests
test: add tests for cocoapods override feature
2 parents 65d524e + 986d8f6 commit e65efeb

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

test/cocoapods-service.ts

+165
Original file line numberDiff line numberDiff line change
@@ -1194,4 +1194,169 @@ end`
11941194
});
11951195
});
11961196
});
1197+
1198+
describe("override pods", () => {
1199+
1200+
it("should override pods", async () => {
1201+
const projectDataMock = _.assign({}, mockProjectData, {nsConfig: {
1202+
overridePods: true
1203+
}});
1204+
1205+
const testCase = {
1206+
pluginPodContent: `pod 'MaterialComponents/Tabs', '< 84.4'`,
1207+
appResourcesPodContent: `pod 'MaterialComponents/Tabs', '~> 84.4'`,
1208+
projectPodfileContent: "",
1209+
expectedOutput:
1210+
`use_frameworks!
1211+
1212+
target "projectName" do
1213+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1214+
#pod 'MaterialComponents/Tabs', '< 84.4'
1215+
# End Podfile
1216+
end`,
1217+
expectedFinalOutput:
1218+
`use_frameworks!
1219+
1220+
target "projectName" do
1221+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1222+
#pod 'MaterialComponents/Tabs', '< 84.4'
1223+
# End Podfile
1224+
1225+
# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
1226+
pod 'MaterialComponents/Tabs', '~> 84.4'
1227+
# End Podfile
1228+
end`
1229+
};
1230+
1231+
mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.appResourcesPodContent);
1232+
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
1233+
1234+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedOutput));
1235+
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);
1236+
1237+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedFinalOutput));
1238+
});
1239+
1240+
it("should override pods and undo if app resources podfile doesn't include the pod", async () => {
1241+
const testCase = {
1242+
pluginPodContent: `pod 'MaterialComponents/Tabs', '< 84.4'`,
1243+
appResourcesPodContent:
1244+
`pod 'MaterialComponents/Tabs', '~> 84.4'
1245+
pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
1246+
updatedAppResourcesPodContent:`pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
1247+
projectPodfileContent: "",
1248+
expectedOutput:
1249+
`use_frameworks!
1250+
1251+
target "projectName" do
1252+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1253+
#pod 'MaterialComponents/Tabs', '< 84.4'
1254+
# End Podfile
1255+
end`,
1256+
expectedIntermidiatOutput:
1257+
`use_frameworks!
1258+
1259+
target "projectName" do
1260+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1261+
#pod 'MaterialComponents/Tabs', '< 84.4'
1262+
# End Podfile
1263+
1264+
# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
1265+
pod 'MaterialComponents/Tabs', '~> 84.4'
1266+
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
1267+
# End Podfile
1268+
end`,
1269+
expectedFinalOutput:
1270+
`use_frameworks!
1271+
1272+
target "projectName" do
1273+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1274+
pod 'MaterialComponents/Tabs', '< 84.4'
1275+
# End Podfile
1276+
1277+
# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
1278+
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
1279+
# End Podfile
1280+
end`
1281+
};
1282+
const projectDataMock = _.assign({}, mockProjectData, {nsConfig: {
1283+
overridePods: true
1284+
}});
1285+
1286+
mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.appResourcesPodContent);
1287+
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
1288+
1289+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedOutput));
1290+
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);
1291+
1292+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedIntermidiatOutput));
1293+
1294+
mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.updatedAppResourcesPodContent);
1295+
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
1296+
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);
1297+
1298+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedFinalOutput));
1299+
});
1300+
1301+
it("should not override if not in app resources podfile and the override when added", async () => {
1302+
const testCase = {
1303+
pluginPodContent: `pod 'MaterialComponents/Tabs', '< 84.4'`,
1304+
appResourcesPodContent: `pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
1305+
updatedAppResourcesPodContent:
1306+
`pod 'MaterialComponents/Tabs', '~> 84.4'
1307+
pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
1308+
projectPodfileContent: "",
1309+
expectedOutput:
1310+
`use_frameworks!
1311+
1312+
target "projectName" do
1313+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1314+
pod 'MaterialComponents/Tabs', '< 84.4'
1315+
# End Podfile
1316+
end`,
1317+
expectedIntermidiatOutput:
1318+
`use_frameworks!
1319+
1320+
target "projectName" do
1321+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1322+
pod 'MaterialComponents/Tabs', '< 84.4'
1323+
# End Podfile
1324+
1325+
# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
1326+
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
1327+
# End Podfile
1328+
end`,
1329+
expectedFinalOutput:
1330+
`use_frameworks!
1331+
1332+
target "projectName" do
1333+
# Begin Podfile - pluginPlatformsFolderPath/Podfile
1334+
#pod 'MaterialComponents/Tabs', '< 84.4'
1335+
# End Podfile
1336+
1337+
# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
1338+
pod 'MaterialComponents/Tabs', '~> 84.4'
1339+
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
1340+
# End Podfile
1341+
end`
1342+
};
1343+
const projectDataMock = _.assign({}, mockProjectData, {nsConfig: {
1344+
overridePods: true
1345+
}});
1346+
1347+
mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.appResourcesPodContent);
1348+
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
1349+
1350+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedOutput));
1351+
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);
1352+
1353+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedIntermidiatOutput));
1354+
1355+
mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.updatedAppResourcesPodContent);
1356+
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
1357+
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);
1358+
1359+
assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedFinalOutput));
1360+
});
1361+
});
11971362
});

0 commit comments

Comments
 (0)