Skip to content

Conversation

@thib92
Copy link
Contributor

@thib92 thib92 commented Sep 18, 2019

Summary:

Started writing tests for the doctor healthchecks, starting with androidHomeEnvVariable.

Since I needed the envinfo output in the test, and I will need it in all the upcomming tests, I moved it to the tools folder. Maybe it's not the best place, I'm not sure.

I only wrote one test to have feedback about the way of writing them, feel free to comment.

IMHO since these are unit tests we should mock all the imports and just make sure we call them when expected.
I didn't test the hard-coded SO links because it seems like a detail that wasn't worth testing.

Related to #694

Test Plan:

This is a test so... CI is green? ✅

@thib92
Copy link
Contributor Author

thib92 commented Sep 18, 2019

Looks like E2E tests failing because of Azure.

@thib92
Copy link
Contributor Author

thib92 commented Sep 18, 2019

@lucasbento please take a look if you have time 😄

Copy link
Member

@lucasbento lucasbento left a comment

Choose a reason for hiding this comment

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

Looks very good, thanks for this!

Just left a few comments.

});

it('logs manual installation steps to the screen', async () => {
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I'm forcing loader to be of type Ora, but I only put the info property, not the rest.

Though I changed it to any to avoid the // @ts-ignore.

Copy link
Member

Choose a reason for hiding this comment

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

You can use NoopLoader (grep for it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to watch it though, so I need to use jest.fn(). Though using NoopLoader, I could use jest.spyOn(). What do you reckon is the best?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Or use jest.spyOn, maybe that's even better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually my mistake, I don't need to watch it, so I used the NoopLoader. Thanks @thymikee!

Copy link
Member

@lucasbento lucasbento left a comment

Choose a reason for hiding this comment

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

Good work 😄

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Almost there! Thanks for sending tests <3

{json: true, showNotFound: true},
),
);
const environmentInfo = JSON.parse(await getEnvironmentInfo());
Copy link
Member

Choose a reason for hiding this comment

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

Please move JSON.parse to getEnvironmentInfo

printCategory({
...issueCategory,
key,
});
Copy link
Member

Choose a reason for hiding this comment

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

Can we revert this change? I like it being a one-liner :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sorry, my VSCode formatter settings changed for some reason. Reverted :)

import {EnvironmentInfo} from '../../types';
import {NoopLoader} from '../../../../tools/loader';

jest.mock('../common');
Copy link
Member

Choose a reason for hiding this comment

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

Are you mocking common just to spy on logManualInstallation? This likely unnecessarily lowers the coverage. Please use:

import * as common from '../common';
const logSpy = jest.spyOn(common, 'logManualInstallation');

expect(logManualInstallation).toHaveBeenCalledTimes(1);
});

afterEach(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Please move afterEach to the top of describe, this way it's easier to spot the side effects that tests rely on

@thib92
Copy link
Contributor Author

thib92 commented Sep 21, 2019

All fixed @thymikee, thanks for the review and the good tips on Jest best practices 😄

const environmentInfo: EnvironmentInfo = JSON.parse(
await getEnvironmentInfo(),
);
const environmentInfo: EnvironmentInfo = await getEnvironmentInfo();
Copy link
Member

Choose a reason for hiding this comment

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

you likely don't need to cast the type now :)

json: true,
showNotFound: true,
},
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!

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

👍

@thymikee thymikee merged commit 246a34d into react-native-community:master Sep 22, 2019
@thib92 thib92 deleted the tests-healthcheck branch September 22, 2019 23:10
@lucasbento lucasbento mentioned this pull request Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants