-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 still not working while test in browser mode #5090
Comments
It's possible if you run Vitest in watch-mode and open browser's dev-tools. |
@AriPerkkio thanks, how to enable watch-mode and open dev-tools, i can't find infomation in document |
To run in watch mode, remove the "scripts": {
- "test": "vitest run"
+ "test": "vitest"
}, |
If it's possible to debug with VS Code while running Vitest in headless mode, that would be great. |
I am trying to run my vitest browser mode tests in debug mode through IntelliJ Idea, but it looks like my test code is run in a different thread (browser?) and hence none of the breakpoints trigger. It works out of the box when using the default, non-browser mode. Is this the same issue described here, or should I open a new ticket? |
not working~ |
@gezilinll The problem is not the browser mode, but the headless mode. Try to configure test.browser.headless = false in your vite.config.mjs. |
I also use IntelliJ IDEA, and breakpoints and |
Debugger in VS code works fine with breakpoints with these settings: // vitest.config.ts
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
browser: {
enabled: true,
name: "chromium",
provider: "playwright",
headless: true, // Both modes work fine
providerOptions: {
launch: {
args: ["--remote-debugging-port=9222"],
},
},
},
},
}); // .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "Attach to browser",
"port": 9222
}
]
}
vitest-browser-mode-vscode-debug.webm |
For Idea support, I went ahead and opened a YouTrack ticket. I hope there is some kind of workaround, but I assume it requires some work in our vitest integration. Nevertheless, I'd appreciate it if you could upvote the youtrack ticket, so that we can gauge interest more accurately. Thanks! |
I don't have access to IntelliJ, but you should be able to get it working with these instructions: https://www.jetbrains.com/help/idea/configuring-javascript-debugger.html It's just about connecting to Chrome Devtools Protocol, not really Vitest related. E: Installed IntelliJ trial and did some testing. It is possible to attach debugger into Vitest's browser mode. It's really hacky atm so https://youtrack.jetbrains.com/issue/WEB-68768/Vitest-Browser-Mode-Debugging-Doesnt-Work is needed. intellij-demo.webm |
Thanks @AriPerkkio for providing a workaround for the IDEA platform, I documented it in YouTrack https://youtrack.jetbrains.com/issue/WEB-68768/Vitest-Browser-Mode-Debugging-Doesnt-Work#focus=Change-27-10353350.0-0 |
For VS Code you can also create a single configuration file. This will run Vitest and attach to the browser. {
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run Vitest",
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"console": "integratedTerminal"
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to browser",
"port": 9229
}
],
"compounds": [
{
"name": "Debug Vitest Browser",
"configurations": ["Attach to browser", "Run Vitest"],
"stopAll": true
}
]
} But from Vitest's side we could still improve the developer experience to match the current We could make the Similar steps are done on Node's side for vitest/packages/vitest/src/runtime/inspector.ts Lines 30 to 43 in 2c926bf
|
Describe the bug
I commit issue yesterday: #5085 , but @sheremet-va closed it and mark it to duplicate to #4497 .
I have tried ways of #4497 metioned, but still not working, and I don't think they are same problem, please try my demo in Reproduction, it still can not debugger in browser mode, THANKS~
Reproduction
https://github.com/gezilinll/vitest-browser-debugger
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: