Skip to content

Commit

Permalink
refactor: allow debugExclude as a folder option
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 6, 2024
1 parent 548eb8d commit 9a62827
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
50 changes: 35 additions & 15 deletions src/debug/debugManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import * as vscode from 'vscode'
import getPort from 'get-port'
import { getConfig } from '../config'
import { log } from '../log'
import type { VitestFolderAPI } from '../api'

export class TestDebugManager extends vscode.Disposable {
private disposables: vscode.Disposable[] = []
private sessions = new Set<vscode.DebugSession>()
private port: number | undefined

private static DEBUG_DEFAULT_PORT = 9229

Expand All @@ -28,16 +30,29 @@ export class TestDebugManager extends vscode.Disposable {
)
}

public async start(defaultPort?: number) {
public async enable(api: VitestFolderAPI) {
await this.stop()

const config = getConfig()
// TODO: test only DEBUG_DEFAULT_PORT for now
const port = defaultPort || config.debuggerPort || TestDebugManager.DEBUG_DEFAULT_PORT || await getPort({ port: TestDebugManager.DEBUG_DEFAULT_PORT })
// TODO: remove "|| TestDebugManager.DEBUG_DEFAULT_PORT"
this.port ??= config.debuggerPort || TestDebugManager.DEBUG_DEFAULT_PORT || await getPort({ port: TestDebugManager.DEBUG_DEFAULT_PORT })
api.startInspect(this.port)
}

public async disable(api: VitestFolderAPI) {
await this.stop()
this.port = undefined
api.stopInspect()
}

public start(folder: vscode.WorkspaceFolder) {
const config = getConfig(folder)

const debugConfig = {
type: 'pwa-node',
request: 'attach',
name: 'Debug Tests',
port,
port: this.port,
autoAttachChildProcesses: true,
skipFiles: config.debugExclude,
smartStep: true,
Expand All @@ -48,17 +63,22 @@ export class TestDebugManager extends vscode.Disposable {
},
}

vscode.debug.startDebugging(undefined, debugConfig, {
suppressDebugView: true,
}).then((fulfilled) => {
if (fulfilled)
log.info('[DEBUG] Debugging started')
else
log.error('[DEBUG] Debugging failed')
}, (err) => {
log.error('[DEBUG] Start debugging failed')
log.error(err.toString())
})
vscode.debug.startDebugging(
folder,
debugConfig,
{ suppressDebugView: true },
).then(
(fulfilled) => {
if (fulfilled)
log.info('[DEBUG] Debugging started')
else
log.error('[DEBUG] Debugging failed')
},
(err) => {
log.error('[DEBUG] Start debugging failed')
log.error(err.toString())
},
)
}

public async stop() {
Expand Down
8 changes: 3 additions & 5 deletions src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ export class TestRunner extends vscode.Disposable {
}

public async debugTests(request: vscode.TestRunRequest, token: vscode.CancellationToken) {
await this.debug.stop()

this.api.startInspect(9229)
await this.debug.enable(this.api)

await this.runTests(request, token)

this.api.stopInspect()
await this.debug.disable(this.api)
}

private endRequestRuns(request: vscode.TestRunRequest) {
Expand Down Expand Up @@ -288,7 +286,7 @@ export class TestRunner extends vscode.Disposable {

if (request.profile?.kind === vscode.TestRunProfileKind.Debug) {
await this.debug.stop()
await this.debug.start()
this.debug.start(this.api.workspaceFolder)
}

const run = this.controller.createTestRun(request)
Expand Down

0 comments on commit 9a62827

Please sign in to comment.