DEV Community

udiko
udiko

Posted on • Updated on

Debug mocha tests with vscode

To debug mocha.js in vscode select run & debug

Image description

If you dont have launch.json file press create a launch.json file for creating it.

Press add configuration
Image description

Select Mocha Tests

Image description

The json should looks like:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "args": [
                "-u",
                "tdd",
                "--timeout",
                "999999",
                "--colors",
                "${workspaceFolder}/test"
            ],
            "internalConsoleOptions": "openOnSessionStart",
            "name": "Mocha Tests",
            "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "request": "launch",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "pwa-node"
        },

        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Add to "args":

"--file",
"${workspaceFolder}/test-folder/setup.js",
"${workspaceFolder}/test-folder/**/*.spec.js",

and run
Image description

If you get Process exited with code 1 remove the

    "--require",
    "esm",
Enter fullscreen mode Exit fullscreen mode

Top comments (0)