Skip to content

Commit 18235ec

Browse files
committed
Fix resolve item children
1 parent 07c24d7 commit 18235ec

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/commonRunTestsHandler.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { SQL_FN_RUNTESTPROXY, UTIL_CLASSNAME } from './utils';
1010
export async function commonRunTestsHandler(controller: vscode.TestController, resolveItemChildren: (item: vscode.TestItem) => Promise<void>, request: vscode.TestRunRequest, cancellation: vscode.CancellationToken) {
1111
logger.debug(`commonRunTestsHandler invoked by controller id=${controller.id}`);
1212

13-
const isResolvedMap = new WeakMap<vscode.TestItem, boolean>();
14-
1513
// For each authority (i.e. server:namespace) accumulate a map of the class-level Test nodes in the tree.
1614
// We don't yet support running only some TestXXX methods in a testclass
1715
const mapAuthorities = new Map<string, Map<string, OurTestItem>>();
@@ -50,8 +48,8 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
5048
continue;
5149
}
5250

53-
// Resolve children if not already done
54-
if (test.canResolveChildren && !isResolvedMap.get(test)) {
51+
// Resolve children if not definitely already done
52+
if (test.canResolveChildren && test.children.size === 0) {
5553
await resolveItemChildren(test);
5654
}
5755

@@ -237,11 +235,6 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
237235
run.errored(classTest, new vscode.TestMessage(error instanceof Error ? error.message : String(error)));
238236
continue;
239237
}
240-
241-
// Unless the file copy failed, enqueue all the testitems that represent the TestXXX methods of the class
242-
classTest.children.forEach((methodTest) => {
243-
run.enqueued(methodTest);
244-
});
245238
}
246239
}
247240

src/localTests.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import { localTestController, OurTestItem, workspaceFolderTestClasses } from './
44
import logger from './logger';
55
import { resolveServerSpecAndNamespace, supportsCoverage } from './utils';
66

7-
const isResolvedMap = new WeakMap<vscode.TestItem, boolean>();
8-
97
async function resolveItemChildren(item: OurTestItem) {
108
if (item) {
11-
isResolvedMap.set(item, true);
129
const itemUri = item.ourUri;
1310
if (itemUri) {
1411
const folderIndex = item.id.split(':')[0]; //vscode.workspace.getWorkspaceFolder(itemUri)?.index || 0;
@@ -17,25 +14,41 @@ async function resolveItemChildren(item: OurTestItem) {
1714
const contents = await vscode.workspace.fs.readDirectory(itemUri);
1815
contents.filter((entry) => entry[1] === vscode.FileType.Directory).forEach((entry) => {
1916
const name = entry[0];
20-
const child: OurTestItem = localTestController.createTestItem(`${item.id}${name}.`, name);
17+
const childId = `${item.id}${name}.`;
18+
if (item.children.get(childId)) {
19+
return;
20+
}
21+
const child: OurTestItem = localTestController.createTestItem(childId, name);
2122
child.ourUri = itemUri.with({path: `${itemUri.path}/${name}`});
2223
child.canResolveChildren = true;
23-
child.supportsCoverage = item.supportsCoverage;
24+
child.supportsCoverage = item.supportsCoverage;
2425
item.children.add(child);
2526
});
2627
contents.filter((entry) => entry[1] === vscode.FileType.File).forEach((entry) => {
2728
const name = entry[0];
2829
if (name.endsWith('.cls')) {
29-
const child: OurTestItem = localTestController.createTestItem(`${item.id}${name.slice(0, name.length - 4)}`, name, itemUri.with({path: `${itemUri.path}/${name}`}));
30+
const childId = `${item.id}${name.slice(0, name.length - 4)}`;
31+
if (item.children.get(childId)) {
32+
return;
33+
}
34+
const child: OurTestItem = localTestController.createTestItem(childId, name, itemUri.with({path: `${itemUri.path}/${name}`}));
3035
child.ourUri = child.uri;
3136
child.canResolveChildren = true;
3237
child.supportsCoverage = item.supportsCoverage;
3338
item.children.add(child);
3439
const fullClassName = child.id.split(':')[3];
40+
if (!child.parent) {
41+
console.log(`*** BUG - child (id=${child.id}) has no parent after item.children.add(child) where item.id=${item.id}`);
42+
}
3543
//console.log(`workspaceFolderTestClasses.length=${workspaceFolderTestClasses.length}, index=${folderIndex}`);
3644
workspaceFolderTestClasses[folderIndex].set(fullClassName, child);
3745
}
3846
});
47+
if (item.children.size === 0) {
48+
// If no children, this is a class with no tests
49+
item.canResolveChildren = false;
50+
item.supportsCoverage = false;
51+
}
3952
} catch (error) {
4053
if (error.code !== vscode.FileSystemError.FileNotADirectory().code) {
4154
throw error;
@@ -58,7 +71,11 @@ async function resolveItemChildren(item: OurTestItem) {
5871
const match = lineText.match(/^Method Test(.+)\(/);
5972
if (match) {
6073
const testName = match[1];
61-
const child: OurTestItem = localTestController.createTestItem(`${item.id}:Test${testName}`, testName, itemUri);
74+
const childId = `${item.id}:Test${testName}`;
75+
if (item.children.get(childId)) {
76+
continue;
77+
}
78+
const child: OurTestItem = localTestController.createTestItem(childId, testName, itemUri);
6279
child.ourUri = child.uri;
6380
child.range = new vscode.Range(new vscode.Position(index, 0), new vscode.Position(index + 1, 0))
6481
child.canResolveChildren = false;

0 commit comments

Comments
 (0)