visual studio code debuggin mocha is ignoring breakpoints

后端 未结 2 735
死守一世寂寞
死守一世寂寞 2020-12-21 11:39

I am trying to debug mocha unit test in visual studio code. I followed this question and got this run configuration:

    {
        \"name\": \"Run mocha\",
          


        
相关标签:
2条回答
  • 2020-12-21 12:00

    This works for me, you need to point to _mocha. Using just mocha does not allow attaching breakpoints.

        {
            "name": "Debug mocha",
            "type": "node",
            "request": "launch",
            "runtimeArgs": ["C:\\Users\\CS\\AppData\\Roaming\\npm\\node_modules\\mocha\\bin\\_mocha"],
            "program": "${workspaceRoot}\\test.js",
            "stopOnEntry": false,
            "args": [
            ],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": null,
            "env": {
                "NODE_ENV": "development"
            }
        }
    
    0 讨论(0)
  • 2020-12-21 12:21

    If you include the port and the "--debug-brk" argument, you should be able to debug mocha unit tests. I have the following setup in my launch.json file. I included the "--recursive" argument as well so mocha would run all tests in subfolders as well. With this configuration file, I just set my VS Code debugger to use the "Debug Mocha Test" configuration and I'm able to hit breakpoints in any of my test files.

    {
        // Use IntelliSense to learn about possible Node.js debug attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "program": "${workspaceRoot}/server.js",
                "cwd": "${workspaceRoot}"
            },
            {
                "type": "node",
                "request": "attach",
                "name": "Attach to Process",
                "port": 5858
            },
            {
                "type": "node",
                "request": "launch",
                "name": "Debug Mocha Test",
                "port": 5858,
                "runtimeArgs": ["${workspaceRoot}/node_modules/mocha/bin/mocha"],
                "cwd": "${workspaceRoot}",
                "args": ["--recursive", "--debug-brk"]
            }
        ]
    }
    

    You can verify the port mocha will use for debugging by running mocha --debug-brk

    0 讨论(0)
提交回复
热议问题