Skip to content

Commit d437641

Browse files
committed
fix: fix dispose omission in RunProfile
fix: comment out about debug run
1 parent 165ff7c commit d437641

6 files changed

Lines changed: 44 additions & 25 deletions

File tree

src/test/manager.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class RepositoryManager implements vscode.Disposable {
2727
private _loadingTestItem: vscode.TestItem
2828
private _workspaceTestItems: WorkspaceTestItem[] = []
2929
private _wdioConfigTestItems: WdioConfigTestItem[] = []
30+
private isCreatedDefaultProfile = false
3031

3132
constructor(
3233
public readonly controller: vscode.TestController,
@@ -63,13 +64,10 @@ export class RepositoryManager implements vscode.Disposable {
6364
this._workspaceTestItems = await Promise.all(
6465
workspaces.map(async (workspace) => {
6566
const workspaceTestItem = this.createWorkspaceTestItem(workspace.workspaceFolder)
66-
let isCreatedDefaultProfile = false
6767
for (const wdioConfigFile of workspace.wdioConfigFiles) {
6868
await this.createWdioConfigTestItem(workspaceTestItem, wdioConfigFile)
6969

70-
// Create run profile
71-
createRunProfile(this, wdioConfigFile, !isCreatedDefaultProfile)
72-
isCreatedDefaultProfile = true
70+
this.isCreatedDefaultProfile = true
7371
}
7472
return workspaceTestItem
7573
})
@@ -84,9 +82,6 @@ export class RepositoryManager implements vscode.Disposable {
8482
for (const workspaceTestItem of affectedWorkspaceItems) {
8583
const configTestItem = await this.createWdioConfigTestItem(workspaceTestItem, wdioConfigPath)
8684

87-
// Create run profile
88-
createRunProfile(this, wdioConfigPath, false)
89-
9085
await configTestItem.metadata.repository.discoverAllTests()
9186
if (!this.configManager.isMultiWorkspace) {
9287
this.controller.items.add(configTestItem)
@@ -169,13 +164,14 @@ export class RepositoryManager implements vscode.Disposable {
169164
const repo = new TestRepository(this.controller, worker, wdioConfigPath, configItem)
170165
this._repos.add(repo)
171166

167+
configItem.description = relative(workspaceTestItem.uri!.fsPath, dirname(wdioConfigPath))
172168
configItem['metadata'] = {
173169
isWorkspace: false,
174170
isConfigFile: true,
175171
isSpecFile: false,
176172
repository: repo,
173+
runProfile: createRunProfile.call(this, configItem, !this.isCreatedDefaultProfile),
177174
}
178-
configItem.description = relative(workspaceTestItem.uri!.fsPath, dirname(wdioConfigPath))
179175
return configItem
180176
}
181177

src/test/repository.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export class TestRepository implements vscode.Disposable {
9090
!filePaths || filePaths.length === 0 ? allConfigSpecs : filterSpecsByPaths(allConfigSpecs, filePaths)
9191

9292
if (specsToReload.length === 0) {
93-
// TODO: If there is information in the Repository but it cannot be retrieved from the actual configuration file, there may be a discrepancy in the configuration.
93+
// TODO: If there is information in the Repository but it cannot be retrieved from the actual configuration file,
94+
// there may be a discrepancy in the configuration.
9495
// In this case, consider using a reload of the entire file.
9596
log.debug('No matching spec files found for reload')
9697
return
@@ -161,7 +162,7 @@ export class TestRepository implements vscode.Disposable {
161162
try {
162163
// Create TestItem testFile by testFile
163164
const fileId = this.getTestFileId(this._wdioConfigTestItem, test.spec)
164-
// const fileContent = await this.readSpecFile(spec)
165+
165166
const testCases = await convertTestData(test)
166167

167168
const fileTestItem = this.resisterSpecFile(fileId, convertPathToUri(test.spec))
@@ -390,6 +391,7 @@ export class TestRepository implements vscode.Disposable {
390391
* Dispose of resources
391392
*/
392393
public dispose() {
394+
this._wdioConfigTestItem.metadata.runProfile.dispose()
393395
this._suiteMap.clear()
394396
this._fileMap.clear()
395397
}

src/test/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface WdioConfigTestItem extends WdioTestItem {
8181
isConfigFile: true
8282
isSpecFile: false
8383
repository: TestRepository
84+
runProfile: vscode.TestRunProfile
8485
}
8586
}
8687

src/test/utils.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,24 @@ export const isTestcase = (testItem: vscode.TestItem): testItem is TestcaseTestI
6060
!testItem.metadata.isSpecFile
6161

6262
export function createRunProfile(
63-
repositoryManager: RepositoryManager,
64-
wdioConfigFile: string,
63+
this: RepositoryManager,
64+
wdioConfigFileTestItem: WdioConfigTestItem,
6565
isDefaultProfile: boolean
6666
) {
67-
repositoryManager.controller.createRunProfile(
68-
path.basename(wdioConfigFile),
69-
vscode.TestRunProfileKind.Run,
70-
createHandler(repositoryManager.configManager, repositoryManager),
71-
isDefaultProfile
72-
)
67+
const description = wdioConfigFileTestItem.description ? ` (${wdioConfigFileTestItem.description})` : ''
68+
return [
69+
this.controller.createRunProfile(
70+
`${path.basename(wdioConfigFileTestItem.uri!.fsPath)}${description}`,
71+
vscode.TestRunProfileKind.Run,
72+
createHandler(this.configManager, this),
73+
isDefaultProfile
74+
),
75+
//TODO: support debug
76+
// this.controller.createRunProfile(
77+
// `${path.basename(wdioConfigFileTestItem.uri!.fsPath)}${description}`,
78+
// vscode.TestRunProfileKind.Debug,
79+
// createHandler(this.configManager, this),
80+
// isDefaultProfile
81+
// ),
82+
]
7383
}

tests/test/repository.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('TestRepository', () => {
2929
let mockWorker: WdioExtensionWorkerInterface
3030
let readFile: sinon.SinonStub
3131
let readSpecsStub: sinon.SinonStub
32+
let runProfileDisposeStub: sinon.SinonStub
3233

3334
beforeEach(() => {
3435
sandbox = sinon.createSandbox()
@@ -48,11 +49,16 @@ describe('TestRepository', () => {
4849
mockWdioConfigUri.fsPath,
4950
mockWdioConfigUri
5051
) as WdioConfigTestItem
52+
runProfileDisposeStub = sandbox.stub()
53+
5154
wdioConfigTestItem.metadata = {
5255
isWorkspace: false,
5356
isConfigFile: true,
5457
isSpecFile: false,
5558
repository: {} as any,
59+
runProfile: {
60+
dispose: runProfileDisposeStub,
61+
} as unknown as vscode.TestRunProfile,
5662
}
5763

5864
// Setup worker mock
@@ -102,8 +108,9 @@ describe('TestRepository', () => {
102108

103109
// Execute
104110
testRepository.dispose()
105-
111+
runProfileDisposeStub
106112
// Verify
113+
expect(runProfileDisposeStub).to.have.been.called
107114
expect(spyOnSuiteMapClear).to.have.been.called
108115
expect(spyOnFileMapClear).to.have.been.called
109116
})

tests/test/utils.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import * as path from 'node:path'
2-
31
import { describe, expect, it, vi, beforeEach } from 'vitest'
42

53
import * as utils from '../../src/test/utils.js'
64

75
import type * as vscode from 'vscode'
86
import type { RepositoryManager } from '../../src/test/manager.js'
9-
import type { WdioTestItem } from '../../src/test/types.js'
7+
import type { WdioConfigTestItem, WdioTestItem } from '../../src/test/types.js'
108

119
vi.mock('vscode', async () => {
1210
return {
@@ -239,13 +237,18 @@ describe('Test Utils', () => {
239237
})
240238

241239
it('should create a run profile with correct parameters', () => {
242-
const wdioConfigFile = '/path/to/wdio.conf.js'
240+
const wdioConfigFile = {
241+
uri: {
242+
fsPath: 'file:///path/to/wdio.conf.js',
243+
},
244+
description: 'path/to',
245+
} as unknown as WdioConfigTestItem
243246
const isDefaultProfile = true
244247

245-
utils.createRunProfile(repositoryManager, wdioConfigFile, isDefaultProfile)
248+
utils.createRunProfile.call(repositoryManager, wdioConfigFile, isDefaultProfile)
246249

247250
expect(mockController.createRunProfile).toHaveBeenCalledWith(
248-
path.basename(wdioConfigFile),
251+
'wdio.conf.js (path/to)',
249252
expect.any(Number),
250253
expect.any(Function),
251254
isDefaultProfile

0 commit comments

Comments
 (0)