Skip to content

Commit bde729b

Browse files
committed
Add refresh support to the test explorer
1 parent d615deb commit bde729b

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

vscode/src/test/suite/testController.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,4 +898,22 @@ suite("TestController", () => {
898898
assert.ok(runStub.passed.calledWith(testItem));
899899
assert.ok(runStub.end.calledWithExactly());
900900
}).timeout(10000);
901+
902+
test("refresh handler clears all items and starts from scratch", async () => {
903+
await controller.testController.resolveHandler!(undefined);
904+
assert.ok(controller.testController.items.size > 0);
905+
906+
const replaceSpy = sandbox.spy(controller.testController.items, "replace");
907+
const resolveHandlerStub = sandbox.stub().resolves(true);
908+
controller.testController.resolveHandler = resolveHandlerStub;
909+
910+
const source = new vscode.CancellationTokenSource();
911+
await controller.testController.refreshHandler!(source.token);
912+
913+
assert.ok(replaceSpy.calledOnce);
914+
assert.ok(replaceSpy.calledWith([]));
915+
assert.ok(resolveHandlerStub.calledOnce);
916+
917+
source.dispose();
918+
});
901919
});

vscode/src/testController.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class TestController {
8686

8787
if (this.fullDiscovery) {
8888
this.testController.resolveHandler = this.resolveHandler.bind(this);
89+
this.testController.refreshHandler = this.refreshHandler.bind(this);
8990
}
9091

9192
this.testCommands = new WeakMap<vscode.TestItem, string>();
@@ -510,6 +511,12 @@ export class TestController {
510511
return this.runner.tcpPort;
511512
}
512513

514+
private async refreshHandler(_token: vscode.CancellationToken) {
515+
this.testController.items.replace([]);
516+
this.testController.invalidateTestResults();
517+
await this.testController.resolveHandler!(undefined);
518+
}
519+
513520
private async handleTests(
514521
request: vscode.TestRunRequest,
515522
token: vscode.CancellationToken,

0 commit comments

Comments
 (0)