-
Notifications
You must be signed in to change notification settings - Fork 931
[doctor command] Add tests for androidSDK and androidNDK #742
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
thymikee
merged 8 commits into
react-native-community:master
from
thib92:tests-healthcheck
Oct 14, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8f8355d
Add tests for androidSDK and androidNDK
thib92 9a0eb35
Add mocks to execa for Windows tests
thib92 8192e52
Finish mock of execa for androidSDK test
thib92 2919be5
PR comments @lucasbento
thib92 bff633c
Merge branch 'master' into tests-healthcheck
thib92 1a956a8
Change to true value instead of message
thib92 0371d6b
Add comments about ts-ignore
thib92 671906f
Change mock logic
thib92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/cli/src/commands/doctor/healthchecks/__tests__/androidNDK.test.ts
This file contains hidden or 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,69 @@ | ||
| import androidNDK from '../androidNDK'; | ||
| import getEnvironmentInfo from '../../../../tools/envinfo'; | ||
| import {EnvironmentInfo} from '../../types'; | ||
| import {NoopLoader} from '../../../../tools/loader'; | ||
|
|
||
| import * as common from '../common'; | ||
|
|
||
| const logSpy = jest.spyOn(common, 'logManualInstallation'); | ||
|
|
||
| describe('androidNDK', () => { | ||
| let initialEnvironmentInfo: EnvironmentInfo; | ||
| let environmentInfo: EnvironmentInfo; | ||
|
|
||
| beforeAll(async () => { | ||
| initialEnvironmentInfo = await getEnvironmentInfo(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| environmentInfo = initialEnvironmentInfo; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('returns a message if the Android SDK is not installed', async () => { | ||
| environmentInfo.SDKs['Android SDK'] = 'Not Found'; | ||
| const diagnostics = await androidNDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(true); | ||
| }); | ||
|
|
||
| it('returns a message if the Android NDK is not installed', async () => { | ||
| // To avoid having to provide fake versions for all the Android SDK tools | ||
| // @ts-ignore | ||
| environmentInfo.SDKs['Android SDK'] = { | ||
| 'Android NDK': 'Not Found', | ||
| }; | ||
| const diagnostics = await androidNDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(true); | ||
| }); | ||
|
|
||
| it('returns a message if the NDK version is not in range', async () => { | ||
| // To avoid having to provide fake versions for all the Android SDK tools | ||
| // @ts-ignore | ||
| environmentInfo.SDKs['Android SDK'] = { | ||
| 'Android NDK': '18', | ||
| }; | ||
| const diagnostics = await androidNDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false if the NDK version is in range', async () => { | ||
| // To avoid having to provide fake versions for all the Android SDK tools | ||
| // @ts-ignore | ||
| environmentInfo.SDKs['Android SDK'] = { | ||
| 'Android NDK': '19', | ||
| }; | ||
| const diagnostics = await androidNDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(false); | ||
| }); | ||
|
|
||
| it('logs manual installation steps to the screen', () => { | ||
| const loader = new NoopLoader(); | ||
|
|
||
| androidNDK.runAutomaticFix({loader, environmentInfo}); | ||
|
|
||
| expect(logSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
67 changes: 67 additions & 0 deletions
67
packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts
This file contains hidden or 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,67 @@ | ||
| import execa from 'execa'; | ||
| import androidSDK from '../androidSDK'; | ||
| import getEnvironmentInfo from '../../../../tools/envinfo'; | ||
| import {EnvironmentInfo} from '../../types'; | ||
| import {NoopLoader} from '../../../../tools/loader'; | ||
|
|
||
| import * as common from '../common'; | ||
|
|
||
| const logSpy = jest.spyOn(common, 'logManualInstallation'); | ||
|
|
||
| jest.mock('execa', () => jest.fn()); | ||
|
|
||
| describe('androidSDK', () => { | ||
| let initialEnvironmentInfo: EnvironmentInfo; | ||
| let environmentInfo: EnvironmentInfo; | ||
|
|
||
| beforeAll(async () => { | ||
| initialEnvironmentInfo = await getEnvironmentInfo(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| environmentInfo = initialEnvironmentInfo; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('returns a message if the Android SDK is not installed', async () => { | ||
| environmentInfo.SDKs['Android SDK'] = 'Not Found'; | ||
| ((execa as unknown) as jest.Mock).mockResolvedValue({stdout: ''}); | ||
| const diagnostics = await androidSDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(true); | ||
| }); | ||
|
|
||
| it('returns a message if the SDK version is not in range', async () => { | ||
| // To avoid having to provide fake versions for all the Android SDK tools | ||
| // @ts-ignore | ||
| environmentInfo.SDKs['Android SDK'] = { | ||
| 'Build Tools': [25], | ||
| }; | ||
| ((execa as unknown) as jest.Mock).mockResolvedValue({ | ||
| stdout: 'build-tools;25.0', | ||
| }); | ||
| const diagnostics = await androidSDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false if the SDK version is in range', async () => { | ||
| // To avoid having to provide fake versions for all the Android SDK tools | ||
| // @ts-ignore | ||
| environmentInfo.SDKs['Android SDK'] = { | ||
| 'Build Tools': ['26.0'], | ||
| }; | ||
| ((execa as unknown) as jest.Mock).mockResolvedValue({ | ||
| stdout: 'build-tools;26.0', | ||
| }); | ||
| const diagnostics = await androidSDK.getDiagnostics(environmentInfo); | ||
| expect(diagnostics.needsToBeFixed).toBe(false); | ||
| }); | ||
|
|
||
| it('logs manual installation steps to the screen', () => { | ||
| const loader = new NoopLoader(); | ||
| androidSDK.runAutomaticFix({loader, environmentInfo}); | ||
| expect(logSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.