Debugger stops at at end of file when "stepping into"
Describe the bug
I'm trying to debug tests in Visual Studio Code. I followed this guide: https://vitest.dev/guide/debugging.html to set up the vscode debugger and everything works fine, until I "step into" a function or method. The debugger does not stop on the correct line, but at the end of the file. I created a minimal repo to reproduce the issue: https://github.com/oliverschwendener/vitest-vscode-debugging-issue. Does anyone have an idea what could cause this issue? Did I misconfigure something?
Reproduction
https://github.com/oliverschwendener/vitest-vscode-debugging-issue
Output
[INFO 15:58:09] [v0.8.4] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 15:58:09] [API] Running Vitest: v1.5.0 (vite.config.mts)
[INFO 15:58:09] [API] Starting Vitest process with Node.js: /Users/oliverschwendener/.nvm/versions/node/v20.12.2/bin/node
[INFO 15:58:10] [API] Vitest process 94273 created
[INFO 15:58:11] [API] Collecting tests: src/Calculator.test.ts
[INFO 15:58:11] [API] Collecting tests: src/Calculator.test.ts
[INFO 15:58:33] [DEBUG] Starting debugging on localhost:53856
[INFO 15:58:33] Running 1 file(s) with name pattern: ^\s?add should add two numbers$
[Worker] Debugger listening on ws://127.0.0.1:53856/691b403d-7e0e-4ddc-8605-5c4ff72dd9f6
For help, see: https://nodejs.org/en/docs/inspector
[Worker] Debugger attached.
[INFO 15:58:33] [DEBUG] Debugging started
Version
v0.8.4
Validations
- [X] Check that you are using the latest version of the extension
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Thanks for the reproduction.
It looks like this is due to how Vite SSR transforms imports/exports internally. Vite replaces each named export with a getter of magic variable __vite_ssr..., so probably this getter call is making an weird jump. When I tested it, it goes to add body after "step into" 3 times, so that coincides with my assumption.
I'm not sure if there's a solution to this, but probably this issue is reproducible on plain Vite SSR, so actions need to be taken there.
Btw, you are using vscode debugger directly with own launch.json, so technically this is not vscode extension issue, which is what this repo is about (EDIT: now the issue is moved to main vitest repo). But, the same issue can reproduce either way.
This is very likely related to how Vite SSR transform modifies the variables: https://github.com/ariperkkio/vite-ssr-transform-sourcemaps-issue/
Upstream issue open https://github.com/vitejs/vite/issues/18325
Thanks for following up!