11import type { RunnerTaskResultPack , UserConsoleLog } from 'vitest'
2- import type { VitestWorkerRPC , WorkerInitMetadata } from 'vitest-vscode-shared'
2+ import type { VitestWorkerRPC , WorkerInitMetadata , WorkerRunnerOptions } from 'vitest-vscode-shared'
33import type {
44 BrowserCommand ,
55 Reporter ,
@@ -15,20 +15,25 @@ import { ExtensionWorker } from './worker'
1515
1616interface VSCodeReporterOptions {
1717 setupFilePaths : WorkerInitMetadata [ 'setupFilePaths' ]
18+ debug : WorkerRunnerOptions [ 'debug' ]
1819}
1920
2021export class VSCodeReporter implements Reporter {
2122 public rpc ! : VitestWorkerRPC
2223 private vitest ! : VitestCore
2324
2425 private setupFilePaths : WorkerInitMetadata [ 'setupFilePaths' ]
26+ private debug : WorkerRunnerOptions [ 'debug' ]
2527
2628 constructor ( options : VSCodeReporterOptions ) {
2729 this . setupFilePaths = options . setupFilePaths
30+ this . debug = options . debug
2831 }
2932
3033 onInit ( vitest : VitestCore ) {
3134 this . vitest = vitest
35+ this . configureBrowserDebugging ( vitest )
36+
3237 vitest . projects . forEach ( ( project ) => {
3338 this . ensureSetupFileIsAllowed ( project . vite . config )
3439 } )
@@ -142,6 +147,19 @@ export class VSCodeReporter implements Reporter {
142147 } )
143148 }
144149
150+ configureBrowserDebugging ( vitest : VitestCore ) {
151+ //
152+ // Note: This is too late to enable the inspector itself, but we can still add setup files
153+ //
154+ const isBrowserEnabled = vitest . projects . some ( project => project . config . browser ?. enabled )
155+
156+ if ( isBrowserEnabled && this . debug !== undefined && typeof this . debug === 'object' ) {
157+ vitest . projects . forEach ( ( project ) => {
158+ project . config . setupFiles . push ( this . setupFilePaths . browserDebug )
159+ } )
160+ }
161+ }
162+
145163 toJSON ( ) {
146164 return { }
147165 }
0 commit comments