Unbound breakpoint while debugging Karma tests in VS Code

Viewed 135

I'm trying to debug Karma tests using VS Code. I managed to run tests and attach VS Code to the headless Chrome. The problem is that breakpoints don't work after attaching VS Code. But the "debugger" keyword works well and after stopping on it, I can set new breakpoints, and it works, but old breakpoints remain unbound.

enter image description here

Here are my configs:

launch.json

"version": "0.2.0",
"configurations": [
    {
        "type": "chrome",
        "request": "attach",
        "name": "Debug Karma",
        "address": "localhost",
        "port": 9333,
        "preLaunchTask": "Start Karma",
        "trace": true,
        "pathMapping": {
            "/": "${workspaceRoot}/",
            "/base/": "${workspaceRoot}/"
        }
    }
]

tasks.json

"version": "2.0.0",
"tasks": [
    {
        "label": "Start Karma",
        "type": "npm",
        "isBackground": true,
        "script": "test-by-karma-dev",
        "problemMatcher": [
            {
                "pattern": [
                    {
                        "regexp": ".",
                        "file": 1,
                        "location": 2,
                        "message": 3
                    }
                ],
                "background": {
                    "activeOnStart": true,
                    "beginsPattern": "karma start",
                    "endsPattern": "Connected on socket"
                }
            }
        ]
    }
]
1 Answers

I'm experiencing the exact same behaviour. Did you manage to solve this in the meanwhile?

I found some kind of other workaround, but it isn't any better then placing a debugger statement. But if you press the debug button on the karma html page it opens up a new tab to /debug.html. After this attach vscode to chrome. Then the breakpoint remains bound. But the problem is that the tests have already run by then. So you have to refresh the browser tab to rerun the tests, but at that moment the breakpoint becomes unbouded again. So what you need to do is refresh the browser tab by restarting the debug session in vscode and immediately after restarting pause it.

screenshot restarting and pause/resume debugger session

Then remove the unbound breakpoint and place it back again. After this the breakpoint is bound. Then resume the debug session and the breakpoint gets hit. Quite some steps and not any better than using the debugger statement, but maybe this sheds some light on the issue...

Related