Skip to content

Conversation

@Alanoll
Copy link
Contributor

@Alanoll Alanoll commented Jan 17, 2026

This fixes #712 when debugging via the browser and setting breakpoints within VSCode when using project style configurations.

Using the loaded Vitest configurations (thanks @sheremet-va for the point in the right direction), it will set the webRoot on the browser DebugConfiguration to the root defined in the configuration for the tests attempting to be debugged.

The logic gathers all roots for all tests requested for execution, but if multiple different roots are found, it will log a DEBUG message to the console instead throwing an error like the other Browser scenarios. Debugging still works when set in the test file itself, but may not catch when set in source files.

@Alanoll
Copy link
Contributor Author

Alanoll commented Jan 17, 2026

@sheremet-va Let me know if you'd like to try and support the multiple roots, and I can try and reimplement using sourceMapPathOverrides instead

I have two concerns with doing that:

  • Setting the value overrides the defaults provided by VSCode. They likely wouldn't apply when served via Vite though (link to default paths), so they're possibly safe to override.
  • It could lead to collisions with user codebases, and it'd be trickier to diagnose. If two projects have similarly named files (e.g. if worker and worker-legacy were web project roots, they both have a index.ts with code), VSCode would only break successfully the first one matched to the patterns (/worker/* , /worker-legacy/*). Troubleshooting reported issues would require project layout information.

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some small suggestions

browser?: {
provider: string
name: string
webRoot?: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be optional, root is always defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made these to optional because of the worker-legacy project.
I wasn't sure if legacy in this sense was a "don't touch unless absolutely neededtype of thing, as making this required causes an error in that project when it's getting thebrowser` objects.

My latest commit make it required and updates the worker-legacy project to resolve the error. Let me know if I should roll that back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacy just means "not vitest 4", the extension should till work there (unfortunately)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well the change is there now as well :)

browser?: {
provider: string
name: string
webRoot?: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be optional, root is always defined

@Alanoll Alanoll requested a review from sheremet-va January 19, 2026 16:35
@sheremet-va sheremet-va merged commit 0e17e72 into vitest-dev:main Jan 19, 2026
1 of 4 checks passed
@sheremet-va
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser Debugging - Unable to stop at source code breakpoint with projects

2 participants