Skip to content

Migrate integration tests to Jest#1798

Merged
koesie10 merged 50 commits intomainfrom
jest-migration/integration-tests
Nov 30, 2022
Merged

Migrate integration tests to Jest#1798
koesie10 merged 50 commits intomainfrom
jest-migration/integration-tests

Conversation

@koesie10
Copy link
Copy Markdown
Member

This is a bundled PR of all work that has been done to migrate the integration tests to Jest. All individual commits should already have been reviewed.

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.

koesie10 and others added 30 commits November 23, 2022 11:23
This migrates all no-workspace VSCode integration tests to Jest by
running `npx jest-codemods`, followed by manual fixes (mostly for Sinon
and Proxyquire).
This results in parallel downloads of VSCode, which is not supported.
The timeouts need to be set either on a per-file basis, or per test by
using the parameter in `it`. Since we have both Mocha and Jest types, we
need to declare in the test file which one we're using.
Instead of calling `fail` and catching an error, this will use the
`rejects.toThrow` assertion to check that a Promise rejects with a
specific error.
Migrate no-workspace integration tests to Jest
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.
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.
This removes the Mocha, Sinon and Chai-related packages and removes
unused code from the test suite.
koesie10 and others added 12 commits November 25, 2022 10:11
This will apply the same change as the PR on `jest-runner-vscode` in
the local `node_modules` on every install, ensuring that we have
Windows support.
Since we are launching a completely different process for the extension
tests than the process that is launched by VSCode, we need to add some
special handling for the debugging.

This will let the extension host/VSCode expose a debugging port, which
VSCode will then connect to. This is "less desirable than letting the
bootloader do its thing", but a packaged VSCode application does not
allow using the bootloader (`NODE_OPTIONS`=`--require=...`). Therefore,
we have to fallback to this option.

See: https://github.com/microsoft/vscode-js-debug/blob/47c60558ec31902f42c255abb9b460078df02f9d/src/configuration.ts#L405-L411
Add debugging support for Jest integration tests
Instead of running the integration tests from the `out` directory, this
will run the integration tests from the `src` directory using `ts-jest`.

Unfortunately, we are not able to use TypeScript files for the
`jest-runner-vscode` configuration since `cosmiconfig` (the package that
handles the configuration loading for `jest-runner-vscode`) doesn't
support loading TypeScript files by default.
Use ts-jest for running integration tests
This adds debugging support to jest-runner for the integration tests
when they are run from the `out` directory. Unfortunately, this removes
the ability to debug the non-integration tests, such as the pure tests.
Use `patch-package` to add Windows support
@koesie10 koesie10 requested review from a team as code owners November 25, 2022 12:41
Add documentation for running a single test
@koesie10 koesie10 enabled auto-merge November 25, 2022 15:01
@koesie10 koesie10 disabled auto-merge November 25, 2022 17:37
koesie10 and others added 4 commits November 28, 2022 11:32
This will patch `jest-runner-vscode` to retry tests. This is a temporary
test to see if this will help with the flakiness of the CLI integration
tests.

The biggest problem with this is that it will launch multiple VSCode
instances on every retry:
- First try (not a retry): 1 instance
- Second try: 2 instances
- Third try: 3 instances
- etc.

I'm not sure why this is happening and can't really narrow it down to a
specific cause. Even if I change the `runVSCode` call for the retry by
a simple `cp.spawn` call, it still launches multiple instances.
Multiple VSCode instances were being launched when a second instance of
VSCode was being spawned with the same user data directory. This is
probably because VSCode restores the windows from the previous session,
even when `-n`/`--new-window` is passed.

This fixes it by patching `jest-runner-vscode` to always create a new
temporary user data directory, rather than re-using the same one for
all test suites.
This will update the `jest-runner-vscode` patch to retry tests that fail
due to no test result being returned from the test runner.

This will also add some retries to the `minimal-workspace` and
`no-workspace` tests to help with flakiness.
@koesie10 koesie10 enabled auto-merge November 30, 2022 07:50
@koesie10 koesie10 disabled auto-merge November 30, 2022 08:05
@koesie10 koesie10 merged commit 2895e84 into main Nov 30, 2022
@koesie10 koesie10 deleted the jest-migration/integration-tests branch November 30, 2022 08:54
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