Description
State of the World
Testing support in VS Code has been a feature request for a long time. The VS Code community has build excellent extensions around testing, for example:
- The Test Explorer UI from @hbenl
- Wallaby.js from the Wallaby team
- Jest from @orta
- ...and many more
Each implementation of testing presents a different set of features, UI, and idiomaticity. Because there is no sanctioned approach to tests in VS Code, extension developers tend to make bespoke implementations, as we've seen in the Python and Java language extensions. Ideally, like in debugging, a VS Code user would have just about the same experience as they work between projects and languages.
VS Code's Approach
Investigate how VS Code can improve the testing support. Several extensions are already providing testing support, explore what APIs/UIs could be added to improve these testing extensions and the test running experience. -- 2020 Roadmap
The Test Explorer UI presents the best point of inspiration for us, as there are many existing extensions built on its API: it's capable and proven. Regardless of the direction we take in VS Code, we should have a way for its Test Adapters to be upgraded to the new world.
Wallaby is an excellent extension, but it's tailored and purpose-built to JavaScript, and includes functionality which is not readily portable to other languages. While it is a good source for inspiration, we're not aiming to encompass Wallaby's feature set in the extension points we provide, at least not yet.
We're prototyping an API in the extension host, but there are a number of approaches we can take:
Extension Host ('traditional' VS Code API) | 'Test Protocol' (like DAP/LSP) | Extension (like existing test explorer) |
---|---|---|
+ Simple to adopt for extension authors + Easier to manage state + Clear way to build 'official' test extensions |
+ Encourages keeping expensive work in child processes + Could be theoretically shared with VS and other editors |
+ Keep VS Code core slim + Unclear whether there's significant functionality we'd want that's not already possible in exthost api |
- The 'obvious path' is doing heavy lifting in the extension host process, which is undesirable |
- Additional implementation and maintainence complexity for VS Code - Less friendly, additional complexity than TS APIs for extension authors |
- Additional extension and set of libraries to maintain+version for types and implementation - Less clear there's an official pathway for test extensions |
API Design
The following is a working draft of an API design. It should not be considered final, or anything close to final. This post will be edited as it evolves.
Changes versus the Test Adapter API
As mentioned, the test adapter API and this one provide a similar end user experience. Here are the notable changes we made:
-
The test adapter API does not distinguish between watching a workspace and watching a file. In some cases, there is an existing process that reads workspace tests (such as a language server in Java) or it's not much more expensive to get workspace tests than file tests (such as mocha, perhaps). However, some cases, like Go, providing tests for a single file can be done very cheaply and efficiently without needing to involve the workspace.
In this API we expect the
TestProvider
to, after activation, always provide tests for the visible text editors, and we only request tests for the entire workspace when required (i.e. when the UI needs to enumerate them). -
We have modeled the test state more closely after the existing
DiagnosticCollection
, where the Test Adapter API uses only events to enumerate tests and does not have a central collection. -
The Test Adapter API makes the distinction between suites and tests, we do not. They have almost identical capabilities, and in at least one scenario the 'suites' are more like tests and the leaf 'tests' cannot be run individually.
-
We use object identity rather than ID for referencing tests. This is in line with other items in the VS Code API, including Diagnostics.
Ideas and Open Questions
See the testing
label for current work, questions, and problems.
API
See the current working proposal in https://github.com/microsoft/vscode/blob/master/src/vs/vscode.proposed.d.ts (ctrl+f for 107467)