-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move pods installation from
init
to ios-specific commands (…
…#2077) * remove pod installation from init process * create dependency hashes and store it in cache * move installPods from doctor to platform-ios * install pods on run-ios and build-ios * add --force-pods flag to run-ios * add tests * add tests for pods installation * use crypto and rename releaseCacheManager to cacheManager * move run sudo to cli-tools * use findPodfilePath * resolve only native dependencies for pod check * update pod installation tests * add version property to dependency config & use it to hash dependencies * cr updates * add pod installation prompt to init * better error handling when package.json not found * add --install-pods flag to init * update tests * fix config tests * set hash in cache when initializing new project * try/catch require package.json * update type for installCocoaPods
- Loading branch information
1 parent
520c90f
commit d011058
Showing
30 changed files
with
399 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import {writeFiles, getTempDirectory, cleanup} from '../../../../jest/helpers'; | ||
import installPods from '../tools/installPods'; | ||
import resolvePods, {compareMd5Hashes, getIosDependencies} from '../tools/pods'; | ||
|
||
const mockGet = jest.fn(); | ||
const mockSet = jest.fn(); | ||
jest.mock('@react-native-community/cli-tools', () => ({ | ||
...Object.assign(jest.requireActual('@react-native-community/cli-tools')), | ||
cacheManager: { | ||
get: mockGet, | ||
set: mockSet, | ||
}, | ||
})); | ||
jest.mock('../tools/installPods', () => jest.fn()); | ||
const dependencyHash = 'd41d8cd98f00b204e9800998ecf8427e'; | ||
|
||
const packageJson = { | ||
name: 'test-package', | ||
dependencies: {dep1: '1.0.0'}, | ||
devDependencies: {dep2: '1.0.0'}, | ||
}; | ||
|
||
const commonDepConfig = { | ||
root: '', | ||
platforms: { | ||
ios: { | ||
podspecPath: '', | ||
version: '1.0.0', | ||
scriptPhases: [], | ||
configurations: [], | ||
}, | ||
}, | ||
}; | ||
|
||
const dependenciesConfig = { | ||
dep1: { | ||
name: 'dep1', | ||
...commonDepConfig, | ||
}, | ||
dep2: { | ||
name: 'dep2', | ||
...commonDepConfig, | ||
}, | ||
}; | ||
|
||
const DIR = getTempDirectory('root_test'); | ||
|
||
const createTempFiles = (rest?: Record<string, string>) => { | ||
writeFiles(DIR, { | ||
'package.json': JSON.stringify(packageJson), | ||
...rest, | ||
}); | ||
}; | ||
|
||
beforeEach(async () => { | ||
await cleanup(DIR); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('compareMd5Hashes', () => { | ||
it('should return false if hashes are different', () => { | ||
const result = compareMd5Hashes('hash1', 'hash2'); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return true if hashes are the same', () => { | ||
const result = compareMd5Hashes('hash', 'hash'); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('getIosDependencies', () => { | ||
it('should return only dependencies with native code', () => { | ||
const result = getIosDependencies(dependenciesConfig); | ||
expect(result).toEqual(['[email protected]', '[email protected]']); | ||
}); | ||
}); | ||
|
||
describe('resolvePods', () => { | ||
it('should install pods if they are not installed', async () => { | ||
createTempFiles({'ios/Podfile/Manifest.lock': ''}); | ||
|
||
await resolvePods(DIR, {}); | ||
|
||
expect(installPods).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should install pods when force option is set to true', async () => { | ||
createTempFiles(); | ||
|
||
await resolvePods(DIR, {}, {forceInstall: true}); | ||
|
||
expect(installPods).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should install pods when there is no cached hash of dependencies', async () => { | ||
createTempFiles(); | ||
|
||
await resolvePods(DIR, {}); | ||
|
||
expect(mockSet).toHaveBeenCalledWith( | ||
packageJson.name, | ||
'dependencies', | ||
dependencyHash, | ||
); | ||
}); | ||
|
||
it('should skip pods installation if the cached hash and current hash are the same', async () => { | ||
createTempFiles({'ios/Pods/Manifest.lock': ''}); | ||
|
||
mockGet.mockImplementation(() => dependencyHash); | ||
|
||
await resolvePods(DIR, {}); | ||
|
||
expect(installPods).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should install pods if the cached hash and current hash are different', async () => { | ||
createTempFiles({'ios/Pods/Manifest.lock': ''}); | ||
|
||
mockGet.mockImplementation(() => dependencyHash); | ||
|
||
await resolvePods(DIR, { | ||
dep1: { | ||
name: 'dep1', | ||
...commonDepConfig, | ||
}, | ||
}); | ||
|
||
expect(installPods).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.