diff --git a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidNDK.test.ts b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidNDK.test.ts new file mode 100644 index 000000000..3aa9cf9bc --- /dev/null +++ b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidNDK.test.ts @@ -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); + }); +}); diff --git a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts new file mode 100644 index 000000000..f1db5249e --- /dev/null +++ b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts @@ -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); + }); +}); diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts index a53b56487..e4d8fcec6 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts @@ -20,7 +20,6 @@ export default { // See the PR: https://github.com/tabrindle/envinfo/pull/119 if (sdks === 'Not Found' && process.platform !== 'darwin') { try { - // $FlowFixMe bad execa types const {stdout} = await execa( process.env.ANDROID_HOME ? `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`