-
Notifications
You must be signed in to change notification settings - Fork 931
[doctor command] Add tests for androidHomeEnvVariable #728
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
Sep 22, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
206767b
Add tests for androidHomeEnvVariable
thib92 df1c103
Add System to envinfo
thib92 4b1da97
Restore envinfo in info command
thib92 e4e81bb
Remove System since it's not used
thib92 88b6f8e
Use any instead of Ora to avoid TS error
thib92 3c5ea62
Use NoopLoader
thib92 22e1c41
PR review @thymikee
thib92 e55569d
Return type for getEnvironmentInfo
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
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
46 changes: 46 additions & 0 deletions
46
packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.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,46 @@ | ||
| import androidHomeEnvVariables from '../androidHomeEnvVariable'; | ||
| import getEnvironmentInfo from '../../../../tools/envinfo'; | ||
| import {NoopLoader} from '../../../../tools/loader'; | ||
|
|
||
| import * as common from '../common'; | ||
|
|
||
| const logSpy = jest.spyOn(common, 'logManualInstallation'); | ||
|
|
||
| describe('androidHomeEnvVariables', () => { | ||
| const OLD_ENV = process.env; | ||
|
|
||
| afterEach(() => { | ||
| process.env = OLD_ENV; | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('returns a message if no ANDROID_HOME is defined', async () => { | ||
| delete process.env.ANDROID_HOME; | ||
|
|
||
| const environmentInfo = await getEnvironmentInfo(); | ||
| const diagnostics = await androidHomeEnvVariables.getDiagnostics( | ||
| environmentInfo, | ||
| ); | ||
| expect(typeof diagnostics.needsToBeFixed).toBe('string'); | ||
| }); | ||
|
|
||
| it('returns false if ANDROID_HOME is defined', async () => { | ||
| process.env.ANDROID_HOME = '/fake/path/to/android/home'; | ||
|
|
||
| const environmentInfo = await getEnvironmentInfo(); | ||
| const diagnostics = await androidHomeEnvVariables.getDiagnostics( | ||
| environmentInfo, | ||
| ); | ||
| expect(diagnostics.needsToBeFixed).toBe(false); | ||
| }); | ||
|
|
||
| it('logs manual installation steps to the screen', async () => { | ||
| const loader = new NoopLoader(); | ||
|
|
||
| const environmentInfo = await getEnvironmentInfo(); | ||
|
|
||
| androidHomeEnvVariables.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // @ts-ignore | ||
| import envinfo from 'envinfo'; | ||
| import {EnvironmentInfo} from '../commands/doctor/types'; | ||
|
|
||
| export default async function getEnvironmentInfo() { | ||
| return JSON.parse( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please cast to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks! |
||
| await envinfo.run( | ||
| { | ||
| Binaries: ['Node', 'Yarn', 'npm', 'Watchman'], | ||
| IDEs: ['Xcode', 'Android Studio'], | ||
| SDKs: ['iOS SDK', 'Android SDK'], | ||
| npmPackages: ['react', 'react-native', '@react-native-community/cli'], | ||
| npmGlobalPackages: ['*react-native*'], | ||
| }, | ||
| { | ||
| json: true, | ||
| showNotFound: true, | ||
| }, | ||
| ), | ||
| ) as EnvironmentInfo; | ||
| } | ||
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.