You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tests: remove Window.vscode() and related logic (#3182)
## Problem
Writing wrappers for the sole purpose of making an implementation easier to test is not a sustainable approach.
## Solution
* Remove `Window.vscode()` and `FakeWindow`
* Extend `TestWindow` to cover the same scenarios that `FakeWindow` was used for
### Important Notes
This PR uses Proxy heavily in order to make "testable" versions of native vscode objects. Some things like `showInformationMessage` and `withProgress` do not have an API that can be manipulated programmatically. For these methods, we have to create in-mem representations that can be tested. These currently live in `src/test/shared/vscode/message.ts`.
Copy file name to clipboardExpand all lines: docs/TESTPLAN.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,3 +73,38 @@ modifications/workarounds in `src/test/testRunner.ts`.
73
73
- Testing AWS SDK client functionality is cumbersome, verbose, and low-yield.
74
74
- Test code uses multiple “mocking” frameworks, which is confusing, error-prone, hard to onboard, and hard to use.
75
75
- Coverage not counted for integ tests (because of unresolved tooling issue).
76
+
77
+
## Window
78
+
79
+
Certain VS Code API calls are not easily controlled programtically. `vscode.window` is a major source of these functions as it is closely related to the UI. To facilitate some semblance of UI testing, all unit tests have access to a proxied `vscode.window` object via `getTestWindow()`.
80
+
81
+
### Inspecting State
82
+
83
+
The test window will capture relevant UI state that can be inspected at test time. For example, you can check to see if any messages were shown by looking at `getTestWindow().shownMessages` which is an array of message objects.
84
+
85
+
Some VS Code API operations do not expose "native" UI elements that can be inspected. In these cases, in-memory test versions have been created. In every other case the native VS Code API is used directly and extended to make them more testable.
86
+
87
+
### Event-Driven Interactions
88
+
89
+
Checking the state works well if user interactions are not required by the code being tested. But many times the code will be waiting for the user's response.
90
+
91
+
To handle this, test code can register event handler that listen for when a certain type of UI element is shown. For example, if we wanted to always accept the first item of a quick pick we can do this:
Exceptions thrown within one of these handlers will cause the current test to fail. This allows you to make assertions within the callback without worrying about causing the test to hang.
0 commit comments