-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
309 lines (249 loc) · 9.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import * as vscode from 'vscode';
import { TestAdapter as LegacyTestAdapter } from './legacy';
/**
* The ID of the Test Explorer extension. Use it to get the `TestHub` API like this:
* ```
const testHub = vscode.extensions.getExtension<TestHub>(testExplorerExtensionId).exports; ```
* Don't forget to add an `extensionDependencies` entry to your `package.json`:
* ```
"extensionDependencies": [ "hbenl.vscode-test-explorer" ] ```
*/
export const testExplorerExtensionId = 'hbenl.vscode-test-explorer';
/**
* This is the interface offered by the Test Explorer extension for registering
* and unregistering Test Adapters and Test Controllers.
*/
export interface TestHub {
registerTestAdapter(adapter: TestAdapter): void;
unregisterTestAdapter(adapter: TestAdapter): void;
registerTestController(controller: TestController): void;
unregisterTestController(controller: TestController): void;
/**
* @deprecated this is for adapters using the pre-1.0 API
*/
registerAdapter(adapter: LegacyTestAdapter): void;
/**
* @deprecated this is for adapters using the pre-1.0 API
*/
unregisterAdapter(adapter: LegacyTestAdapter): void;
}
/**
* This is the interface that must be implemented by Test Adapters.
*/
export interface TestAdapter {
/**
* The workspace folder that this test adapter is associated with (if any).
* There is usually one test adapter per workspace folder and testing framework.
*/
workspaceFolder?: vscode.WorkspaceFolder;
/**
* Start loading the definitions of tests and test suites.
* Note that the Test Adapter should also watch source files and the configuration for changes and
* automatically reload the test definitions if necessary (without waiting for a call to this method).
* @returns A promise that is resolved when the adapter finished loading the test definitions.
*/
load(): Promise<void>;
/**
* Run the specified tests.
* @param tests An array of test or suite IDs. For every suite ID, all tests in that suite are run.
* @returns A promise that is resolved when the test run is completed.
*/
run(tests: string[]): Promise<void>;
/**
* Run the specified tests in the debugger.
* @param tests An array of test or suite IDs. For every suite ID, all tests in that suite are run.
* @returns A promise that is resolved when the test run is completed.
*/
debug?(tests: string[]): Promise<void>;
/**
* Stop the current test run.
*/
cancel(): void;
/**
* This event is used by the adapter to inform the Test Explorer (and other Test Controllers)
* that it started or finished loading the test definitions.
*/
readonly tests: vscode.Event<TestLoadStartedEvent | TestLoadFinishedEvent>;
/**
* This event is used by the adapter during a test run to inform the Test Explorer
* (and other Test Controllers) about a test run and tests and suites being started or completed.
* For example, if there is one test suite with ID `suite1` containing one test with ID `test1`,
* a successful test run would emit the following events:
* ```
* { type: 'started', tests: ['suite1'] }
* { type: 'suite', suite: 'suite1', state: 'running' }
* { type: 'test', test: 'test1', state: 'running' }
* { type: 'test', test: 'test1', state: 'passed' }
* { type: 'suite', suite: 'suite1', state: 'completed' }
* { type: 'finished' } ```
*/
readonly testStates: vscode.Event<TestRunStartedEvent | TestRunFinishedEvent | TestSuiteEvent | TestEvent>;
/**
* This event can be used by the adapter to trigger a test run for all tests that have
* been set to "autorun" in the Test Explorer.
* Note that the Test Explorer will automatically trigger such a test run when it receives a
* `TestLoadFinishedEvent`. In other words, you should *not* send this event after reloading
* the tests as this would result in 2 identical test runs being triggered.
*/
readonly autorun?: vscode.Event<void>;
}
/**
* This is the interface that must be implemented by Test Controllers
*/
export interface TestController {
/**
* Register the given Test Adapter. The Test Controller should subscribe to the `adapter.tests`
* event source immediately in order to receive the test definitions.
*/
registerTestAdapter(adapter: TestAdapter): void;
unregisterTestAdapter(adapter: TestAdapter): void;
}
/**
* This event is sent by a Test Adapter when it starts loading the test definitions.
*/
export interface TestLoadStartedEvent {
type: 'started';
}
/**
* This event is sent by a Test Adapter when it finished loading the test definitions.
*/
export interface TestLoadFinishedEvent {
type: 'finished';
/** The test definitions that have just been loaded */
suite?: TestSuiteInfo;
/** If loading the tests failed, this should contain the reason for the failure */
errorMessage?: string;
}
/**
* This event is sent by a Test Adapter when it starts a test run.
*/
export interface TestRunStartedEvent {
type: 'started';
/**
* The test(s) that will be run, this should be the same as the `tests` argument from the call
* to `run(tests)` or `debug(tests)` that started the test run.
*/
tests: string[];
}
/**
* This event is sent by a Test Adapter when it finished a test run.
*/
export interface TestRunFinishedEvent {
type: 'finished';
}
/**
* Information about a test suite.
*/
export interface TestSuiteInfo {
type: 'suite';
id: string;
/** The label to be displayed by the Test Explorer for this suite. */
label: string;
/** The description to be displayed next to the label. */
description?: string;
/** The tooltip text to be displayed by the Test Explorer when you hover over this suite. */
tooltip?: string;
/**
* The file containing this suite (if known).
* This can either be an absolute path (if it is a local file) or a URI.
* Note that this should never contain a `file://` URI.
*/
file?: string;
/** The line within the specified file where the suite definition starts (if known). */
line?: number;
children: (TestSuiteInfo | TestInfo)[];
}
/**
* Information about a test.
*/
export interface TestInfo {
type: 'test';
id: string;
/** The label to be displayed by the Test Explorer for this test. */
label: string;
/** The description to be displayed next to the label. */
description?: string;
/** The tooltip text to be displayed by the Test Explorer when you hover over this test. */
tooltip?: string;
/**
* The file containing this test (if known).
* This can either be an absolute path (if it is a local file) or a URI.
* Note that this should never contain a `file://` URI.
*/
file?: string;
/** The line within the specified file where the test definition starts (if known). */
line?: number;
/** Indicates whether this test will be skipped during test runs */
skipped?: boolean;
}
/**
* Information about a suite being started or completed during a test run.
*/
export interface TestSuiteEvent {
type: 'suite';
/**
* The suite that is being started or completed. This field usually contains the ID of the
* suite, but it may also contain the full information about a suite that is started if that
* suite had not been sent to the Test Explorer yet.
*/
suite: string | TestSuiteInfo;
state: 'running' | 'completed';
/**
* This property allows you to update the description of the suite in the Test Explorer.
* When the test states are reset, the description will change back to the one from `TestSuiteInfo`.
*/
description?: string;
/**
* This property allows you to update the tooltip of the suite in the Test Explorer.
* When the test states are reset, the tooltip will change back to the one from `TestSuiteInfo`.
*/
tooltip?: string;
}
/**
* Information about a test being started, completed or skipped during a test run.
*/
export interface TestEvent {
type: 'test';
/**
* The test that is being started, completed or skipped. This field usually contains
* the ID of the test, but it may also contain the full information about a test that is
* started if that test had not been sent to the Test Explorer yet.
*/
test: string | TestInfo;
state: 'running' | 'passed' | 'failed' | 'skipped' | 'errored';
/**
* This message will be displayed by the Test Explorer when the user selects the test.
* It is usually used for information about why a test has failed.
*/
message?: string;
/**
* These messages will be shown as decorations for the given lines in the editor.
* They are usually used to show information about a test failure at the location of that failure.
*/
decorations?: TestDecoration[];
/**
* This property allows you to update the description of the test in the Test Explorer.
* When the test states are reset, the description will change back to the one from `TestInfo`.
*/
description?: string;
/**
* This property allows you to update the tooltip of the test in the Test Explorer.
* When the test states are reset, the tooltip will change back to the one from `TestInfo`.
*/
tooltip?: string;
}
export interface TestDecoration {
/**
* The line for which the decoration should be shown
*/
line: number;
/**
* The message to show in the decoration. This must be a single line of text.
*/
message: string;
/**
* This text is shown when the user hovers over the decoration's message.
* If this isn't defined then the hover will show the test's log.
*/
hover?: string;
}