Skip to content

Commit d6a54d2

Browse files
committed
Automatically discover children for test files that weren't expanded (#3336)
### Motivation I noticed that executing entire test directories through the explorer wasn't working. This is due to #3335 and the aspect that we were not automatically discovering the children of test files if they were never expanded. That meant that, we had no knowledge of their children existing, but when running the tests we are reporting results for those children we know nothing about. We need to automatically resolve children for test files that haven't been expanded otherwise the items we need to update don't exist. ### Implementation It's just a matter of invoking our resolve handler if there are no children in the test file item. ### Automated Tests Added a test.
1 parent 940063a commit d6a54d2

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

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

+83
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,89 @@ suite("TestController", () => {
872872
});
873873
});
874874

875+
test("finding an item inside a test file that was never expanded automatically discovers children", async () => {
876+
const commonStub = sinon.stub(common, "featureEnabled").returns(true);
877+
const controller = new TestController(
878+
context,
879+
FAKE_TELEMETRY,
880+
() => undefined,
881+
() => Promise.resolve(workspace),
882+
);
883+
commonStub.restore();
884+
885+
const workspacesStub = sinon
886+
.stub(vscode.workspace, "workspaceFolders")
887+
.get(() => [workspaceFolder]);
888+
889+
const relativePathStub = sinon
890+
.stub(vscode.workspace, "asRelativePath")
891+
.callsFake((uri) =>
892+
path.relative(workspacePath, (uri as vscode.Uri).fsPath),
893+
);
894+
895+
await controller.testController.resolveHandler!(undefined);
896+
const collection = controller.testController.items;
897+
const testDirUri = vscode.Uri.joinPath(workspaceUri, "test");
898+
const testDir = collection.get(testDirUri.toString());
899+
assert.ok(testDir);
900+
901+
const serverTestUri = vscode.Uri.joinPath(
902+
workspaceUri,
903+
"test",
904+
"server_test.rb",
905+
);
906+
const serverTest = testDir.children.get(serverTestUri.toString());
907+
assert.ok(serverTest);
908+
909+
const fakeClient = {
910+
discoverTests: sinon.stub().resolves([
911+
{
912+
id: "ServerTest",
913+
uri: serverTestUri.toString(),
914+
label: "ServerTest",
915+
range: {
916+
start: { line: 0, character: 0 },
917+
end: { line: 12, character: 10 },
918+
},
919+
tags: ["minitest"],
920+
children: [
921+
{
922+
id: "ServerTest::NestedTest",
923+
uri: serverTestUri.toString(),
924+
label: "NestedTest",
925+
range: {
926+
start: { line: 2, character: 0 },
927+
end: { line: 10, character: 10 },
928+
},
929+
tags: ["minitest"],
930+
children: [
931+
{
932+
id: "ServerTest::NestedTest#test_something",
933+
uri: serverTestUri.toString(),
934+
label: "test_something",
935+
range: {
936+
start: { line: 2, character: 0 },
937+
end: { line: 10, character: 10 },
938+
},
939+
tags: ["minitest"],
940+
children: [],
941+
},
942+
],
943+
},
944+
],
945+
},
946+
]),
947+
waitForIndexing: sinon.stub().resolves(),
948+
};
949+
workspace.lspClient = fakeClient as any;
950+
951+
await controller.findTestItem("ServerTest", serverTestUri);
952+
assert.strictEqual(fakeClient.discoverTests.callCount, 1);
953+
954+
workspacesStub.restore();
955+
relativePathStub.restore();
956+
});
957+
875958
test("running a test", async () => {
876959
await withController(async (controller) => {
877960
const uri = vscode.Uri.joinPath(workspaceUri, "test", "server_test.rb");

vscode/src/testController.ts

+6
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ export class TestController {
387387
return testFileItem;
388388
}
389389

390+
// If we're trying to find a test item inside a file that has never been expanded, then we never discovered its
391+
// children and need to do so before trying to access them
392+
if (testFileItem.children.size === 0) {
393+
await this.resolveHandler(testFileItem);
394+
}
395+
390396
// If we find an exact match for this ID, then return it right away
391397
const groupOrItem = testFileItem.children.get(id);
392398
if (groupOrItem) {

0 commit comments

Comments
 (0)