Skip to content

Conversation

@koesie10
Copy link
Member

This adds some really simple tests for the gh-api-client file to ensure that we can use msw mocks in pure tests.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

This adds some really simple tests for the `gh-api-client` file to
ensure that we can use msw mocks in pure tests.
@koesie10 koesie10 requested a review from charisk October 27, 2022 08:30
@koesie10 koesie10 requested a review from a team as a code owner October 27, 2022 08:30
it('returns the variant analysis', async () => {
await loadScenario('problem-query-success');

const result = await getVariantAnalysis(mockCredentials, 557804416, 146);
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about getting these ids from the scenario data instead of hard-coding in a test as well? I'm not sure if that would be super ugly so happy to be told no :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've implemented it and I don't think it's ugly, but I did have to change how the tsconfig.json for tests was loaded.

This splits the mock GitHub API server class into two parts: one for the
interactive, VSCode parts and one for the non-VSCode parts. This allows
us to use the non-VSCode part in tests.
@koesie10 koesie10 requested a review from a team as a code owner October 28, 2022 13:00
Copy link
Contributor

@charisk charisk left a comment

Choose a reason for hiding this comment

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

LGTM, just a suggestion left around test data usage. Happy to leave that for another day too.

This will change the pure tests Mocha setup to actually use the
`tsconfig.json` located in the `test` directory. Before, it was using
the root-level `tsconfig.json`. To ensure we are still using mostly the
same settings, this will extend the `test/tsconfig.json` from the
root-level `tsconfig.json`.
This will check that the data returned matches the data in the JSON
files, rather than checking against constants/magic values.
@koesie10 koesie10 merged commit bc10a7a into main Oct 28, 2022
@koesie10 koesie10 deleted the koesie10/gh-api-client-msw-test branch October 28, 2022 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants