@@ -4,11 +4,8 @@ import { localTestController, OurTestItem, workspaceFolderTestClasses } from './
44import logger from './logger' ;
55import { resolveServerSpecAndNamespace , supportsCoverage } from './utils' ;
66
7- const isResolvedMap = new WeakMap < vscode . TestItem , boolean > ( ) ;
8-
97async 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 ( / ^ M e t h o d T e s t ( .+ ) \( / ) ;
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