@@ -2185,33 +2185,6 @@ declare module 'vscode' {
2185
2185
* in {@link onDidChangeTest} when a test is added or removed.
2186
2186
*/
2187
2187
readonly root : T ;
2188
-
2189
- /**
2190
- * An event that fires when an existing test `root` changes. This can be
2191
- * a result of a property update, or an update to its children. Changes
2192
- * made to tests will not be visible to {@link TestObserver} instances
2193
- * until this event is fired.
2194
- *
2195
- * When a change is signalled, VS Code will check for any new or removed
2196
- * direct children of the changed ite, For example, firing the event with
2197
- * the {@link testRoot} will detect any new children in `root.children`.
2198
- */
2199
- readonly onDidChangeTest : Event < T > ;
2200
-
2201
- /**
2202
- * Promise that should be resolved when all tests that are initially
2203
- * defined have been discovered. The provider should continue to watch for
2204
- * changes and fire `onDidChangeTest` until the hierarchy is disposed.
2205
- */
2206
- readonly discoveredInitialTests ?: Thenable < unknown > ;
2207
-
2208
- /**
2209
- * An event that fires when a test becomes outdated, as a result of
2210
- * file changes, for example. In "auto run" mode, tests that are outdated
2211
- * will be automatically re-run after a short delay. Firing a test
2212
- * with children will mark the entire subtree as outdated.
2213
- */
2214
- readonly onDidInvalidateTest ?: Event < T > ;
2215
2188
}
2216
2189
2217
2190
/**
@@ -2233,8 +2206,9 @@ declare module 'vscode' {
2233
2206
*
2234
2207
* @param workspace The workspace in which to observe tests
2235
2208
* @param cancellationToken Token that signals the used asked to abort the test run.
2209
+ * @returns the root test item for the workspace
2236
2210
*/
2237
- provideWorkspaceTestHierarchy ( workspace : WorkspaceFolder , token : CancellationToken ) : ProviderResult < TestHierarchy < T > > ;
2211
+ provideWorkspaceTestRoot ( workspace : WorkspaceFolder , token : CancellationToken ) : ProviderResult < T > ;
2238
2212
2239
2213
/**
2240
2214
* Requests that tests be provided for the given document. This will be
@@ -2246,18 +2220,21 @@ declare module 'vscode' {
2246
2220
* saved, if possible.
2247
2221
*
2248
2222
* If the test system is not able to provide or estimate for tests on a
2249
- * per-file basis, this method may not be implemented. In that case, VS
2250
- * Code will request and use the information from the workspace hierarchy .
2223
+ * per-file basis, this method may not be implemented. In that case, the
2224
+ * editor will request and use the information from the workspace tree .
2251
2225
*
2252
2226
* @param document The document in which to observe tests
2253
2227
* @param cancellationToken Token that signals the used asked to abort the test run.
2228
+ * @returns the root test item for the workspace
2254
2229
*/
2255
- provideDocumentTestHierarchy ?( document : TextDocument , token : CancellationToken ) : ProviderResult < TestHierarchy < T > > ;
2230
+ provideDocumentTestRoot ?( document : TextDocument , token : CancellationToken ) : ProviderResult < T > ;
2256
2231
2257
2232
/**
2233
+ * @todo this will move out of the provider soon
2234
+ * @todo this will eventually need to be able to return a summary report, coverage for example.
2235
+ *
2258
2236
* Starts a test run. This should cause {@link onDidChangeTest} to
2259
2237
* fire with update test states during the run.
2260
- * @todo this will eventually need to be able to return a summary report, coverage for example.
2261
2238
* @param options Options for this test run
2262
2239
* @param cancellationToken Token that signals the used asked to abort the test run.
2263
2240
*/
@@ -2305,18 +2282,55 @@ declare module 'vscode' {
2305
2282
setState ( test : T , state : TestState ) : void ;
2306
2283
}
2307
2284
2285
+ export interface TestChildrenCollection < T > extends Iterable < T > {
2286
+ /**
2287
+ * Gets the number of children in the collection.
2288
+ */
2289
+ readonly size : number ;
2290
+
2291
+ /**
2292
+ * Gets an existing TestItem by its ID, if it exists.
2293
+ * @param id ID of the test.
2294
+ * @returns the TestItem instance if it exists.
2295
+ */
2296
+ get ( id : string ) : T | undefined ;
2297
+
2298
+ /**
2299
+ * Adds a new child test item. No-ops if the test was already a child.
2300
+ * @param child The test item to add.
2301
+ */
2302
+ add ( child : T ) : void ;
2303
+
2304
+ /**
2305
+ * Removes the child test item by reference or ID from the collection.
2306
+ * @param child Child ID or instance to remove.
2307
+ */
2308
+ delete ( child : T | string ) : void ;
2309
+
2310
+ /**
2311
+ * Removes all children from the collection.
2312
+ */
2313
+ clear ( ) : void ;
2314
+ }
2315
+
2308
2316
/**
2309
2317
* A test item is an item shown in the "test explorer" view. It encompasses
2310
2318
* both a suite and a test, since they have almost or identical capabilities.
2311
2319
*/
2312
- export class TestItem {
2320
+ export class TestItem < TChildren = any > {
2313
2321
/**
2314
2322
* Unique identifier for the TestItem. This is used to correlate
2315
2323
* test results and tests in the document with those in the workspace
2316
2324
* (test explorer). This must not change for the lifetime of the TestItem.
2317
2325
*/
2318
2326
readonly id : string ;
2319
2327
2328
+ /**
2329
+ * A set of children this item has. You can add new children to it, which
2330
+ * will propagate to the editor UI.
2331
+ */
2332
+ readonly children : TestChildrenCollection < TChildren > ;
2333
+
2320
2334
/**
2321
2335
* Display name describing the test case.
2322
2336
*/
@@ -2327,6 +2341,12 @@ declare module 'vscode' {
2327
2341
*/
2328
2342
description ?: string ;
2329
2343
2344
+ /**
2345
+ * Location of the test in the workspace. This is used to show line
2346
+ * decorations and code lenses for the test.
2347
+ */
2348
+ location ?: Location ;
2349
+
2330
2350
/**
2331
2351
* Whether this test item can be run individually, defaults to `true`.
2332
2352
*
@@ -2344,22 +2364,53 @@ declare module 'vscode' {
2344
2364
debuggable : boolean ;
2345
2365
2346
2366
/**
2347
- * Location of the test in the workspace. This is used to show line
2348
- * decorations and code lenses for the test.
2349
- */
2350
- location ?: Location ;
2351
-
2352
- /**
2353
- * Optional list of nested tests for this item.
2367
+ * Whether this test item can be expanded in the tree view, implying it
2368
+ * has (or may have) children. If this is given, the item may be
2369
+ * passed to the {@link TestHierarchy.getChildren} method.
2354
2370
*/
2355
- children : TestItem [ ] ;
2371
+ expandable : boolean ;
2356
2372
2357
2373
/**
2358
2374
* Creates a new TestItem instance.
2359
2375
* @param id Value of the "id" property
2360
2376
* @param label Value of the "label" property.
2377
+ * @param parent Parent of this item. This should only be defined for the
2378
+ * test root.
2379
+ */
2380
+ constructor ( id : string , label : string , expandable : boolean ) ;
2381
+
2382
+ /**
2383
+ * Marks the test as outdated. This can happen as a result of file changes,
2384
+ * for example. In "auto run" mode, tests that are outdated will be
2385
+ * automatically re-run after a short delay. Invoking this on a
2386
+ * test with children will mark the entire subtree as outdated.
2387
+ *
2388
+ * Extensions should generally not override this method.
2389
+ */
2390
+ invalidate ( ) : void ;
2391
+
2392
+ /**
2393
+ * Requests the children of the test item. Extensions should override this
2394
+ * method for any test that can discover children.
2395
+ *
2396
+ * When called, the item should discover tests and update its's `children`.
2397
+ * The provider will be marked as 'busy' when this method is called, and
2398
+ * the provider should report `{ busy: false }` to {@link Progress.report}
2399
+ * once discovery is complete.
2400
+ *
2401
+ * The item should continue watching for changes to the children and
2402
+ * firing updates until the token is cancelled. The process of watching
2403
+ * the tests may involve creating a file watcher, for example.
2404
+ *
2405
+ * The editor will only call this method when it's interested in refreshing
2406
+ * the children of the item, and will not call it again while there's an
2407
+ * existing, uncancelled discovery for an item.
2408
+ *
2409
+ * @param token Cancellation for the request. Cancellation will be
2410
+ * requested if the test changes before the previous call completes.
2411
+ * @returns a provider result of child test items
2361
2412
*/
2362
- constructor ( id : string , label : string ) ;
2413
+ discoverChildren ( progress : Progress < { busy : boolean } > , token : CancellationToken ) : void ;
2363
2414
}
2364
2415
2365
2416
/**
@@ -2483,23 +2534,46 @@ declare module 'vscode' {
2483
2534
* List of test results. The items in this array are the items that
2484
2535
* were passed in the {@link test.runTests} method.
2485
2536
*/
2486
- results : ReadonlyArray < Readonly < TestItemWithResults > > ;
2537
+ results : ReadonlyArray < Readonly < TestResultSnapshot > > ;
2487
2538
}
2488
2539
2489
2540
/**
2490
- * A {@link TestItem} with an associated result, which appear or can be
2491
- * provided in {@link TestResult} interfaces.
2541
+ * A {@link TestItem}-like interface with an associated result, which appear
2542
+ * or can be provided in {@link TestResult} interfaces.
2492
2543
*/
2493
- export interface TestItemWithResults extends TestItem {
2544
+ export interface TestResultSnapshot {
2545
+ /**
2546
+ * Unique identifier that matches that of the associated TestItem.
2547
+ * This is used to correlate test results and tests in the document with
2548
+ * those in the workspace (test explorer).
2549
+ */
2550
+ readonly id : string ;
2551
+
2552
+ /**
2553
+ * Display name describing the test case.
2554
+ */
2555
+ readonly label : string ;
2556
+
2557
+ /**
2558
+ * Optional description that appears next to the label.
2559
+ */
2560
+ readonly description ?: string ;
2561
+
2562
+ /**
2563
+ * Location of the test in the workspace. This is used to show line
2564
+ * decorations and code lenses for the test.
2565
+ */
2566
+ readonly location ?: Location ;
2567
+
2494
2568
/**
2495
2569
* Current result of the test.
2496
2570
*/
2497
- result : TestState ;
2571
+ readonly result : TestState ;
2498
2572
2499
2573
/**
2500
2574
* Optional list of nested tests for this item.
2501
2575
*/
2502
- children : Readonly < TestItemWithResults > [ ] ;
2576
+ readonly children : Readonly < TestResultSnapshot > [ ] ;
2503
2577
}
2504
2578
2505
2579
//#endregion
0 commit comments