Skip to content

test: add tests for cocoapods override feature #5067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions test/cocoapods-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,4 +1194,169 @@ end`
});
});
});

describe("override pods", () => {

it("should override pods", async () => {
const projectDataMock = _.assign({}, mockProjectData, {nsConfig: {
overridePods: true
}});

const testCase = {
pluginPodContent: `pod 'MaterialComponents/Tabs', '< 84.4'`,
appResourcesPodContent: `pod 'MaterialComponents/Tabs', '~> 84.4'`,
projectPodfileContent: "",
expectedOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
#pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile
end`,
expectedFinalOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
#pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile

# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
pod 'MaterialComponents/Tabs', '~> 84.4'
# End Podfile
end`
};

mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.appResourcesPodContent);
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedOutput));
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedFinalOutput));
});

it("should override pods and undo if app resources podfile doesn't include the pod", async () => {
const testCase = {
pluginPodContent: `pod 'MaterialComponents/Tabs', '< 84.4'`,
appResourcesPodContent:
`pod 'MaterialComponents/Tabs', '~> 84.4'
pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
updatedAppResourcesPodContent:`pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
projectPodfileContent: "",
expectedOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
#pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile
end`,
expectedIntermidiatOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
#pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile

# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
pod 'MaterialComponents/Tabs', '~> 84.4'
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
# End Podfile
end`,
expectedFinalOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile

# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
# End Podfile
end`
};
const projectDataMock = _.assign({}, mockProjectData, {nsConfig: {
overridePods: true
}});

mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.appResourcesPodContent);
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedOutput));
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedIntermidiatOutput));

mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.updatedAppResourcesPodContent);
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedFinalOutput));
});

it("should not override if not in app resources podfile and the override when added", async () => {
const testCase = {
pluginPodContent: `pod 'MaterialComponents/Tabs', '< 84.4'`,
appResourcesPodContent: `pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
updatedAppResourcesPodContent:
`pod 'MaterialComponents/Tabs', '~> 84.4'
pod 'Mapbox-iOS-SDK', '~> 4.4.1'`,
projectPodfileContent: "",
expectedOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile
end`,
expectedIntermidiatOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile

# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
# End Podfile
end`,
expectedFinalOutput:
`use_frameworks!

target "projectName" do
# Begin Podfile - pluginPlatformsFolderPath/Podfile
#pod 'MaterialComponents/Tabs', '< 84.4'
# End Podfile

# Begin Podfile - my/full/path/to/app/App_Resources/iOS/Podfile
pod 'MaterialComponents/Tabs', '~> 84.4'
pod 'Mapbox-iOS-SDK', '~> 4.4.1'
# End Podfile
end`
};
const projectDataMock = _.assign({}, mockProjectData, {nsConfig: {
overridePods: true
}});

mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.appResourcesPodContent);
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedOutput));
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedIntermidiatOutput));

mockFileSystem(testInjector, testCase.pluginPodContent, testCase.projectPodfileContent, testCase.updatedAppResourcesPodContent);
await cocoapodsService.applyPodfileToProject(mockPluginData.name, cocoapodsService.getPluginPodfilePath(mockPluginData), projectDataMock, mockPlatformData);
await cocoapodsService.applyPodfileFromAppResources(projectDataMock, mockPlatformData);

assert.deepEqual(changeNewLineCharacter(newPodfileContent), changeNewLineCharacter(testCase.expectedFinalOutput));
});
});
});