-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debugger in vs-code does not stop at breakpoint but elsewhere #5380
Comments
Can you test if This issue has come up before - it's not really Vitest related. I would guess that your breakpoints don't work even when debugging in browser during development. Related discussions: |
This is most often related to bad or missing sourcemaps |
No, it has the same bug.
Breakpoints work well in browser. Breakpoints work well starting vite dev server in "Javascript debug terminal". So it's pretty much narrowed down to vitest I'd say.
^ This is not related to breakpoints
^ this is describing exactly the same problem. Source maps are turned on as you can see in my minimalistic example: https://github.com/bonham/vitest-debug-issue-js/blob/main/vite.config.js |
Breakpoints seem to work fine when using Chrome Dev tools: vitest-5380.mov |
Hi @AriPerkkio, yes you are right. I tried the same and also for me breakpoint works well. This is a good workaround. Summary:
Idk, but seems not a vitest issue but maybe a vs-code issue ( vue plugin or whatever .... ) |
Not sure if this is helpful or not, but I can reproduce this issue (in the VS Code debugger) without vue at all, just a plain node app. Disabling coverage when a debugger is attached is a workaround but unfortunate. |
with vitest or even without vitest? |
@bonham Oh sorry, yes with vitest. |
I just tested debugging in VS Code with a node app instrumented with istanbul and esbuild and it works fine with breakpoints being where they should be. So I think there's something in vitest specifically that is causing the problem, I don't think that VS Code is the root problem (although maybe a contributing factor). |
@CreativeTechGuy how can I reproduce this issue? Is it with |
@AriPerkkio Sorry for the delay, this is gnarly. I couldn't reproduce it starting from an empty repo, but I started deconstructing my massive repo and I was able to get it down to a few dozen lines total across all files. I've put a ton of information and very detailed steps in the repo README. Let me know if you are able to reproduce. I've been able to reproduce it across two computers (Windows 10 & 11) so far so hopefully you can too. https://github.com/CreativeTechGuy/vitest-coverage-debugger-issue-repro |
We are experiencing this same problem at the moment and for us the workaround going through the Chrome Devtools is also working, but a lot less convenient to use. |
We have this issue at our work across multiple VueJS and Nuxt projects. Various developers have spent collective weeks trying to solve to no success. |
There's some more discussion about VS Code not respecting inline source maps here: #5605. Check the solution at the end and see if it works for you. |
Not sure if the solution at the end is quite our problem - they seem to be trying to debug node_modules, where we are failing on our application code. Trying their fix of |
To me this sounds like source mapping issue. As soon as I remove Debugging in vs code without style tags works:vitest-vscode-vue-debug.mp4But when looking at the source maps they look just fine:
So to summarize:
We have quite many issues that are related to VS Code not being able to handle source maps. Does Vue debugging work in VS Code in general, without Vitest? |
By default, Vitest strips all CSS styles. Does debugger work if |
Having the same issue with an angular application. Breakpoints are all messed up when debugging tests. Works perfectly when debugging application ran with ng serve. |
Same issue on my side with Angular+analogjs+Vitest: debugger moves badly on breakpoints, see gif. I created a repo to reproduce this issue: https://github.com/valneras/jest-vs-vitest We blocked the migration on Vitest because of that :( |
@valneras there's an open issue on Analog that's related to the plugin's sourcemap issues: analogjs/analog#1211
So are you able to use some other testing framework with When looking at the source maps of your project, it's clearly visible that they are completely off when And when I remove |
@AriPerkkio any tips would be welcomed on this one. The sourcemaps work correctly in the browser, so I'm trying to figure out why they are off with Vitest. We disable |
Example of a produced sourcemap with the plugin I did grab the generated source from using the https://github.com/brandonroberts/analog-vitest-sourcemaps |
@brandonroberts you can see the broken source maps in https://github.com/valneras/jest-vs-vitest. But its Vite config is not similar as in your reproduction. It's using
I tested the So @valneras, update your project to match https://github.com/brandonroberts/analog-vitest-sourcemaps and debugger should work just fine. |
I did find that I needed to explicitly disable /// <reference types="vitest" />
import angular from '@analogjs/vite-plugin-angular';
import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
esbuild: false, // completely disable esbuild
plugins: [
angular(),
],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
reporters: ['default'],
},
define: {
'import.meta.vitest': mode !== 'production',
},
};
}); We are disabling esbuild inside the analog vite plugin, but its not getting applied early enough for Vitest to pick it up, as the VitestPlugin is enforced using |
@AriPerkkio and @brandonroberts I tried both approaches. With the @analogjs/platform the gutter icons seem to go to the right place, but breakpoints still jump around and debugger stops at the wrong line. When disabling esbuild, as @brandonroberts suggests, Gutter icons are all wrong as well as breakpoints. |
Ok. I see that also. If I use Sample sourcemap from app.component.spec.ts Oddly enough, if I remove the first line in the file, they line up correctly. Let's continue the discussion here |
Just to provide an update on the Analog side, I landed a fix in Analog |
Describe the bug
In vanilla project with vue3 + vitest + @testing-library/vue + node 18.18.2 or 20.11.1, setting and debugging breakpoints in vs-code on windows 11 does not work as expected. Debugger stops at wrong location. I am using vue single file components ( aka .vue files )
Seems to be transpiling and/or sourcemap issue.
The issue disappears when removing <style>...</style> section in .vue file
Reproduction
Result: Debugger stops at wrong line
Expected: Debugger should stop at correct line
Issue goes away when removing <style>...</style> section in .vue file
Example file
SimpleComponent.vue
Example
simple.spec.js
Full example vanilla project to clone and reproduce: https://github.com/bonham/vitest-debug-issue-js
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: