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
21 changes: 5 additions & 16 deletions packages/cli/src/commands/doctor/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import chalk from 'chalk';
// @ts-ignore
import envinfo from 'envinfo';
import {logger} from '@react-native-community/cli-tools';
import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks';
import {getLoader} from '../../tools/loader';
Expand All @@ -12,6 +10,7 @@ import {
HealthCheckCategoryResult,
HealthCheckResult,
} from './types';
import getEnvironmentInfo from '../../tools/envinfo';

const printCategory = ({label, key}: {label: string; key: number}) => {
if (key > 0) {
Expand Down Expand Up @@ -58,18 +57,7 @@ export default (async (_, __, options) => {

loader.start('Running diagnostics...');

const environmentInfo = JSON.parse(
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},
),
);
const environmentInfo = await getEnvironmentInfo();

const iterateOverHealthChecks = async ({
label,
Expand Down Expand Up @@ -106,8 +94,9 @@ export default (async (_, __, options) => {
)).filter(healthcheck => healthcheck !== undefined) as HealthCheckResult[],
});

// Remove all the categories that don't have any healthcheck with `needsToBeFixed`
// so they don't show when the user taps to fix encountered issues
// Remove all the categories that don't have any healthcheck with
// `needsToBeFixed` so they don't show when the user taps to fix encountered
// issues
const removeFixedCategories = (categories: HealthCheckCategoryResult[]) =>
categories.filter(category =>
category.healthchecks.some(healthcheck => healthcheck.needsToBeFixed),
Expand Down
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);
});
});
21 changes: 21 additions & 0 deletions packages/cli/src/tools/envinfo.ts
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cast to EnvironmentInfo

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}