Skip to content
Merged
Show file tree
Hide file tree
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
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);
});
});
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down