Migrate CLI integration tests to Jest#1785
Merged
koesie10 merged 16 commits intojest-migration/integration-testsfrom Nov 24, 2022
Merged
Migrate CLI integration tests to Jest#1785koesie10 merged 16 commits intojest-migration/integration-testsfrom
koesie10 merged 16 commits intojest-migration/integration-testsfrom
Conversation
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.
d9c4a1a to
558eb19
Compare
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.
3 tasks
…' into jest-migration/cli-integration
charisk
approved these changes
Nov 24, 2022
Contributor
charisk
left a comment
There was a problem hiding this comment.
I've not done a massively thorough review but generally LGTM! Thanks for doing this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.skipproperly when there is no CodeQL workspace.Checklist
ready-for-doc-reviewlabel there.