Skip to content

Commit 9aa9680

Browse files
authored
Show progress while discovering tests (#3519)
1 parent 0e50e07 commit 9aa9680

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,4 +1102,12 @@ suite("TestController", () => {
11021102
testItem.tags.find((tag) => tag.id.startsWith("framework:minitest")),
11031103
);
11041104
}).timeout(10000);
1105+
1106+
test("trying to populate test files twice doesn't do duplicate work", async () => {
1107+
const spy = sandbox.spy(vscode.workspace, "findFiles");
1108+
await controller.testController.resolveHandler!(undefined);
1109+
await controller.testController.resolveHandler!(undefined);
1110+
1111+
assert.ok(spy.calledOnce);
1112+
});
11051113
});

vscode/src/testController.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,15 @@ export class TestController {
466466
async findTestItem(id: string, uri: vscode.Uri, line?: number) {
467467
if (this.testController.items.size === 0) {
468468
// Discover and test items immediately if the test explorer hasn't been expanded
469-
await this.resolveHandler(undefined);
469+
await vscode.window.withProgress(
470+
{
471+
title: "Discovering tests",
472+
location: vscode.ProgressLocation.Notification,
473+
},
474+
async (progress) => {
475+
await this.resolveHandler(undefined, progress);
476+
},
477+
);
470478
}
471479

472480
const parentItem = await this.getParentTestItem(uri);
@@ -1022,12 +1030,18 @@ export class TestController {
10221030

10231031
private async resolveHandler(
10241032
item: vscode.TestItem | undefined,
1033+
progress?: vscode.Progress<{ message?: string; increment?: number }>,
10251034
): Promise<void> {
10261035
const workspaceFolders = vscode.workspace.workspaceFolders;
10271036
if (!workspaceFolders) {
10281037
return;
10291038
}
10301039

1040+
// If we receive another initial resolve request, but the explorer is already populated, skip
1041+
if (item === undefined && this.testController.items.size > 0) {
1042+
return;
1043+
}
1044+
10311045
if (item) {
10321046
const workspaceFolder = vscode.workspace.getWorkspaceFolder(item.uri!)!;
10331047

@@ -1063,7 +1077,7 @@ export class TestController {
10631077
} else if (workspaceFolders.length === 1) {
10641078
// If there's only one workspace, there's no point in nesting the tests under the workspace name
10651079
await vscode.commands.executeCommand("testing.clearTestResults");
1066-
await this.gatherWorkspaceTests(workspaceFolders[0], undefined);
1080+
await this.gatherWorkspaceTests(workspaceFolders[0], undefined, progress);
10671081
} else {
10681082
// If there's more than one workspace, we use them as the top level items
10691083
await vscode.commands.executeCommand("testing.clearTestResults");
@@ -1091,11 +1105,21 @@ export class TestController {
10911105
private async gatherWorkspaceTests(
10921106
workspaceFolder: vscode.WorkspaceFolder,
10931107
item: vscode.TestItem | undefined,
1108+
progress?: vscode.Progress<{ message?: string; increment?: number }>,
10941109
) {
10951110
const initialCollection = item ? item.children : this.testController.items;
10961111
const pattern = this.testPattern(workspaceFolder);
1112+
const filePaths = await vscode.workspace.findFiles(pattern);
1113+
const increment = Math.floor(filePaths.length / 100);
1114+
1115+
for (const uri of filePaths) {
1116+
if (progress) {
1117+
progress.report({
1118+
message: `Processing ${path.basename(uri.fsPath)}`,
1119+
increment,
1120+
});
1121+
}
10971122

1098-
for (const uri of await vscode.workspace.findFiles(pattern)) {
10991123
await this.addTestItemsForFile(uri, workspaceFolder, initialCollection);
11001124
}
11011125
}

0 commit comments

Comments
 (0)