Skip to content

Migrate CLI integration tests to Jest#1785

Merged
koesie10 merged 16 commits intojest-migration/integration-testsfrom
jest-migration/cli-integration
Nov 24, 2022
Merged

Migrate CLI integration tests to Jest#1785
koesie10 merged 16 commits intojest-migration/integration-testsfrom
jest-migration/cli-integration

Conversation

@koesie10
Copy link
Copy Markdown
Member

@koesie10 koesie10 commented Nov 23, 2022

This converts the CLI integration tests to Jest.

Most of the conversion has been done by npx jest-codemods, but all migration of Sinon has been done manually. There were also some other changes necessary, like ensuring that we call .skip properly when there is no CodeQL workspace.

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.

Base automatically changed from jest-migration/no-workspace to jest-migration/integration-tests November 24, 2022 09:21
This is a first pass on converting the cli-integration tests to Jest. It
uses a custom Jest runner (based on the jest-runner-vscode) to install
required extensions. It will also necessary to move some code for
installating the CLI to ensure it was possible to install the CLI from
outside VSCode.

Most of the conversion has been done by `npx jest-codemods`, but all
migration of Sinon has been done manually.
Instead of calling `fail`, we can just let the error be caught by Jest,
which will automatically fail the tests. For other instances where we're
calling `fail` in case an error was not thrown, we will instead use
`.rejects.toThrow`.
Jest does not support skipping tests when the test has already started
(which could also be in a before hook), so we need to manually return
from the tests when the CLI version does not support a tested feature.
Mocha supported `.to.have.length` for objects, but Jest only allows
`toHaveLength` on objects which have a length property (such as arrays).
For `to.contain`, `jest-codemods` seems to have converted these to be
`expect.arrayContaining`, even for strings. This will make the correct
change for strings.
@koesie10 koesie10 force-pushed the jest-migration/cli-integration branch from d9c4a1a to 558eb19 Compare November 24, 2022 09:25
There were some things that were breaking due to version checks. Since
we aren't testing on these CLI versions (2.7.2 and 2.7.4 or older)
anymore, we can remove these checks and simplify the tests.
This will ensure all mocks are restored after every test. This required
a significant amount of changes in the tests since `jest.spyOn` now
needs to be called in `beforeEach`, rather than in the `describe` block.
Apparently, we're not importing the same `config` file as is used by the
actual extension, so mocking methods in this file does not do anything.
However, we can mock the `vscode` module, so we can use this for
returning different values in the configuration.

We also need to mock the authentication session since we don't have one.
@koesie10 koesie10 marked this pull request as ready for review November 24, 2022 12:51
@koesie10 koesie10 requested review from a team as code owners November 24, 2022 12:51
Copy link
Copy Markdown
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.

I've not done a massively thorough review but generally LGTM! Thanks for doing this!

@koesie10 koesie10 merged commit 5841fbc into jest-migration/integration-tests Nov 24, 2022
@koesie10 koesie10 deleted the jest-migration/cli-integration branch November 24, 2022 16:15
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.

2 participants