Friday, July 28, 2017

Debug for Mocha tests in Visual Studio Code

I was surprised  when I found how it's hard to set up such simple thing as "debug" in Visual Studio Code. It's unclear at all! For debug configuration we have just one json file and what exactly should be placed there - nobody knows. Additional problem were caused by using Babel ES2015 in code.

So, that exactly have to be done:

1. launch.json

Create file if it doesn't exists:
.vscode\launch.json

and place there:

{
    "version": "0.2.0",
    "configurations": [
        {
            "request": "launch",
            "name": "Debug Mocha Test",
            "type": "node",
            "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
            "stopOnEntry": true,
            "args": [
                "--compilers",
                "js:babel-core/register",               
                "--recursive"
            ],
            "cwd": "${workspaceRoot}/.",
            "runtimeExecutable": null,
            "env": {}
        }
    ]
}


2. Put breackpoint and run debug by pressing F5

And this is basically it - debug should work now: 




3. The end

As a result, it was very simple, but it took several  hours of time to understand what exactly has to be done :)

No comments:

Post a Comment