Skip to content

Commit

Permalink
fix: stop debugging if running other profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 2, 2024
1 parent 733d955 commit a0ab1d2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/debug/debugManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class TestDebugManager extends vscode.Disposable {
public async stopDebugging() {
await Promise.allSettled([...this.sessions].map(([, s]) => vscode.debug.stopDebugging(s)))
}

public get enabled() {
return this.port !== undefined
}
}

interface TestDebugConfiguration {
Expand Down
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ class VitestExtension {
)
}
runProfile.tag = api.tag
runProfile.runHandler = (request, token) => runner.runTests(request, token)
runProfile.runHandler = async (request, token) => {
await runner.stopDebugRun()
await runner.runTests(request, token)
}
this.runProfiles.set(`${api.id}:run`, runProfile)
let debugProfile = previousRunProfiles.get(`${api.id}:debug`)
if (!debugProfile) {
Expand Down Expand Up @@ -180,7 +183,10 @@ class VitestExtension {
)
}
coverageProfile.tag = api.tag
coverageProfile.runHandler = (request, token) => runner.runCoverage(request, token)
coverageProfile.runHandler = async (request, token) => {
await runner.stopDebugRun()
await runner.runCoverage(request, token)
}
coverageProfile.loadDetailedCoverage = coverageContext.loadDetailedCoverage
this.runProfiles.set(`${api.id}:coverage`, coverageProfile)
}
Expand Down
12 changes: 11 additions & 1 deletion src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class TestRunner extends vscode.Disposable {
// it's important to keep the same test items that were in the original request
// because they dictate how format testNamePattern
for (const [testFileData, testFileChildren] of testItems) {
if (token.isCancellationRequested)
if (token.isCancellationRequested || !this.debug.enabled)
break

const includedTests = testFileChildren.length
Expand Down Expand Up @@ -195,6 +195,16 @@ export class TestRunner extends vscode.Disposable {
}
}

public async stopDebugRun() {
// if debuggins session is active, users can still run tests
// there is no guarantee it will end correctly, so we nuke it
if (this.debug.enabled) {
await this.debug.disable(this.api)
this.simpleTestRunRequest = undefined
this.endTestRun()
}
}

public async runCoverage(request: vscode.TestRunRequest, token: vscode.CancellationToken) {
try {
await this.api.enableCoverage()
Expand Down

0 comments on commit a0ab1d2

Please sign in to comment.