@@ -22,20 +22,20 @@ import type { IRepositoryManager, ITestRepository } from '@vscode-wdio/types/tes
2222
2323const LOADING_TEST_ITEM_ID = '_resolving'
2424
25- export class RepositoryManager extends MetadataRepository implements IRepositoryManager {
25+ export class RepositoryManager implements IRepositoryManager {
2626 private readonly _repos = new Set < ITestRepository > ( )
2727 private _loadingTestItem : vscode . TestItem
2828 private _workspaceTestItems : vscode . TestItem [ ] = [ ]
2929 private _wdioConfigTestItems : vscode . TestItem [ ] = [ ]
3030 private _isInitialized = false
31- private isCreatedDefaultProfile = false
31+ private _isCreatedDefaultProfile = false
3232
3333 constructor (
3434 public readonly controller : vscode . TestController ,
3535 public readonly configManager : ExtensionConfigManager ,
36- private readonly workerManager : IWorkerManager
36+ private readonly _workerManager : IWorkerManager ,
37+ private readonly _metadata = new MetadataRepository ( )
3738 ) {
38- super ( )
3939 this . _loadingTestItem = this . controller . createTestItem ( LOADING_TEST_ITEM_ID , 'Resolving WebdriverIO Tests...' )
4040 this . _loadingTestItem . sortText = '.0' // show at first line
4141 this . _loadingTestItem . busy = true
@@ -56,17 +56,24 @@ export class RepositoryManager extends MetadataRepository implements IRepository
5656 . then ( async ( ) => await this . initialize ( ) )
5757 . then ( async ( ) => await Promise . all ( this . repos . map ( async ( repo ) => await repo . discoverAllTests ( ) ) ) )
5858 . then ( ( ) => this . registerToTestController ( ) )
59- . then ( ( ) => this . workerManager . reorganize ( configManager . getWdioConfigPaths ( ) ) )
59+ . then ( ( ) => this . _workerManager . reorganize ( configManager . getWdioConfigPaths ( ) ) )
6060 } )
6161 }
6262
6363 public get repos ( ) {
6464 return Array . from ( this . _repos )
6565 }
6666
67+ public getMetadata ( testItem : vscode . TestItem ) {
68+ return this . _metadata . getMetadata ( testItem )
69+ }
70+
71+ public getRepository ( testItem : vscode . TestItem ) : ITestRepository {
72+ return this . _metadata . getRepository ( testItem )
73+ }
74+
6775 public async initialize ( ) {
6876 const workspaces = this . configManager . workspaces
69-
7077 if ( workspaces . length < 1 ) {
7178 log . info ( 'No workspaces is detected.' )
7279 return
@@ -79,11 +86,11 @@ export class RepositoryManager extends MetadataRepository implements IRepository
7986
8087 this . _workspaceTestItems = await Promise . all (
8188 workspaces . map ( async ( workspace ) => {
82- const workspaceTestItem = this . createWorkspaceTestItem ( workspace . workspaceFolder )
89+ const workspaceTestItem = this . _createWorkspaceTestItem ( workspace . workspaceFolder )
8390 for ( const wdioConfigFile of workspace . wdioConfigFiles ) {
84- await this . createWdioConfigTestItem ( workspace . workspaceFolder , workspaceTestItem , wdioConfigFile )
91+ await this . _createWdioConfigTestItem ( workspace . workspaceFolder , workspaceTestItem , wdioConfigFile )
8592
86- this . isCreatedDefaultProfile = true
93+ this . _isCreatedDefaultProfile = true
8794 }
8895 return workspaceTestItem
8996 } )
@@ -97,13 +104,13 @@ export class RepositoryManager extends MetadataRepository implements IRepository
97104 return item . uri ?. fsPath === workspaceFolder . uri . fsPath
98105 } )
99106 for ( const workspaceTestItem of affectedWorkspaceItems ) {
100- const configTestItem = await this . createWdioConfigTestItem (
107+ const configTestItem = await this . _createWdioConfigTestItem (
101108 workspaceFolder ,
102109 workspaceTestItem ,
103110 wdioConfigPath
104111 )
105112
106- const repo = this . getRepository ( configTestItem )
113+ const repo = this . _metadata . getRepository ( configTestItem )
107114 await repo . discoverAllTests ( )
108115 if ( ! this . configManager . isMultiWorkspace ) {
109116 this . controller . items . add ( configTestItem )
@@ -118,12 +125,12 @@ export class RepositoryManager extends MetadataRepository implements IRepository
118125 log . debug ( `Remove the config file from ${ affectedWorkspaceItems . length } workspace(s)` )
119126 const configUri = convertPathToUri ( wdioConfigPath )
120127 for ( const workspaceItem of affectedWorkspaceItems ) {
121- const config = workspaceItem . children . get ( this . generateConfigTestItemId ( workspaceItem , configUri ) )
128+ const config = workspaceItem . children . get ( this . _generateConfigTestItemId ( workspaceItem , configUri ) )
122129 if ( ! config ) {
123130 continue
124131 }
125132 log . debug ( `Remove the TestItem: ${ config . id } ` )
126- const targetRepo = this . getRepository ( config )
133+ const targetRepo = this . _metadata . getRepository ( config )
127134 targetRepo . dispose ( )
128135 this . _repos . delete ( targetRepo )
129136
@@ -134,7 +141,7 @@ export class RepositoryManager extends MetadataRepository implements IRepository
134141 this . controller . items . delete ( workspaceItem . id )
135142 }
136143 } else {
137- const targetId = this . generateConfigTestItemId ( workspaceItem , configUri )
144+ const targetId = this . _generateConfigTestItemId ( workspaceItem , configUri )
138145 log . debug ( `Remove Configuration from the controller: ${ targetId } ` )
139146 this . controller . items . delete ( targetId )
140147 }
@@ -155,103 +162,80 @@ export class RepositoryManager extends MetadataRepository implements IRepository
155162 log . debug ( 'Successfully registered.' )
156163 }
157164
158- private createWorkspaceTestItem ( workspaceFolder : vscode . WorkspaceFolder ) {
165+ private _createWorkspaceTestItem ( workspaceFolder : vscode . WorkspaceFolder ) {
159166 const workspaceItem = this . controller . createTestItem (
160167 `workspace:${ workspaceFolder . uri . fsPath } ` ,
161168 workspaceFolder . name ,
162169 workspaceFolder . uri
163170 )
164- this . setMetadata ( workspaceItem , {
165- uri : workspaceFolder . uri ,
166- isWorkspace : true ,
167- isConfigFile : false ,
168- isSpecFile : false ,
169- isTestcase : false ,
170- } )
171+ this . _metadata . createWorkspaceMetadata ( workspaceItem , { uri : workspaceFolder . uri } )
171172 return workspaceItem
172173 }
173174
174- private async createWdioConfigTestItem (
175+ private async _createWdioConfigTestItem (
175176 workspaceFolder : vscode . WorkspaceFolder ,
176177 workspaceTestItem : vscode . TestItem ,
177178 wdioConfigPath : string
178179 ) {
179180 const uri = convertPathToUri ( wdioConfigPath )
180181 const configItem = this . controller . createTestItem (
181- this . generateConfigTestItemId ( workspaceTestItem , uri ) ,
182+ this . _generateConfigTestItemId ( workspaceTestItem , uri ) ,
182183 basename ( wdioConfigPath ) ,
183184 uri
184185 )
185186
186187 workspaceTestItem . children . add ( configItem )
187188 this . _wdioConfigTestItems . push ( configItem )
188189
189- const repo = new TestRepository (
190+ const repository = new TestRepository (
190191 this . configManager ,
191192 this . controller ,
192193 wdioConfigPath ,
193194 configItem ,
194- this . workerManager ,
195+ this . _workerManager ,
195196 workspaceFolder
196197 )
197- this . _repos . add ( repo )
198+ this . _repos . add ( repository )
198199
199200 configItem . description = relative ( workspaceTestItem . uri ! . fsPath , dirname ( wdioConfigPath ) )
200201
201- this . setMetadata ( configItem , {
202- uri,
203- isWorkspace : false ,
204- isConfigFile : true ,
205- isSpecFile : false ,
206- isTestcase : false ,
207- repository : repo ,
208- runProfiles : createRunProfile . call ( this , configItem , ! this . isCreatedDefaultProfile ) ,
209- } )
202+ const runProfiles = createRunProfile . call ( this , configItem , ! this . _isCreatedDefaultProfile )
203+
204+ this . _metadata . createWdioConfigFileMetadata ( configItem , { uri, repository, runProfiles } )
210205 return configItem
211206 }
212207
213- private generateConfigTestItemId ( workspaceTestItem : vscode . TestItem , configUri : vscode . Uri ) {
208+ private _generateConfigTestItemId ( workspaceTestItem : vscode . TestItem , configUri : vscode . Uri ) {
214209 return [ workspaceTestItem . id , `config:${ configUri . fsPath } ` ] . join ( TEST_ID_SEPARATOR )
215210 }
216211
217212 /**
218213 * Refresh WebdriverIO tests
219214 */
220215 public async refreshTests ( ) : Promise < void > {
221- return vscode . window . withProgress (
222- {
223- location : vscode . ProgressLocation . Notification ,
224- title : 'Reloading WebdriverIO tests...' ,
225- cancellable : false ,
226- } ,
227- async ( ) => {
228- try {
229- if ( ! this . _isInitialized ) {
230- await this . initialize ( )
231- }
232- for ( const repo of this . _repos ) {
233- // Clear existing tests
234- repo . clearTests ( )
235- // Discover tests again
236- await repo . discoverAllTests ( )
237- }
238-
239- vscode . window . showInformationMessage ( 'WebdriverIO tests reloaded successfully' )
240- } catch ( error ) {
241- const errorMessage = error instanceof Error ? error . message : String ( error )
242- log . error ( `Failed to reload tests: ${ errorMessage } ` )
243- vscode . window . showErrorMessage ( `Failed to reload WebdriverIO tests: ${ errorMessage } ` )
244- }
216+ this . controller . items . replace ( [ this . _loadingTestItem ] )
217+ try {
218+ if ( ! this . _isInitialized ) {
219+ await this . initialize ( )
245220 }
246- )
221+ await Promise . all (
222+ this . repos . map ( async ( repo ) => {
223+ return await repo . discoverAllTests ( )
224+ } )
225+ )
226+
227+ this . registerToTestController ( )
228+ await this . _workerManager . reorganize ( this . configManager . getWdioConfigPaths ( ) )
229+ } catch ( error ) {
230+ this . controller . items . replace ( [ ] )
231+ const errorMessage = error instanceof Error ? error . message : String ( error )
232+ log . error ( `Failed to reload tests: ${ errorMessage } ` )
233+ vscode . window . showErrorMessage ( `Failed to reload WebdriverIO tests: ${ errorMessage } ` )
234+ }
247235 }
248236
249237 public async dispose ( ) {
250- await Promise . all (
251- Array . from ( this . _repos ) . map ( async ( repo ) => {
252- await repo . dispose ( )
253- } )
254- )
238+ await Promise . all ( this . repos . map ( async ( repo ) => repo . dispose ( ) ) )
255239 this . _repos . clear ( )
256240 this . _workspaceTestItems = [ ]
257241 this . _wdioConfigTestItems = [ ]
0 commit comments