Mocha breakpoints using Visual Studio Code

后端 未结 20 1316
星月不相逢
星月不相逢 2020-12-12 11:52

Is it possible to add breakpoints to ones Mocha tests using Visual Studio Code?

Normally when debugging code one need to configure the launch.json, setting the prog

20条回答
  •  Happy的楠姐
    2020-12-12 12:24

    1) Go to

    .vscode

    then

    launch.json

    file

    2) Add the following configuration in launch.json -

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Mocha Test",
                "cwd": "${workspaceRoot}",
                "runtimeExecutable": "${workspaceRoot}/*folder_path_containing_test*/node_modules/.bin/mocha",
                "windows": {
                    "runtimeExecutable": "${workspaceRoot}/*folder_path_containing_test*/node_modules/.bin/mocha.cmd"
                },
                "runtimeArgs": [
                    "--colors",
                    "--recursive",
                    "${workspaceRoot}/*folder_path_till_test*/tests"
                ],
                "internalConsoleOptions": "openOnSessionStart"
            },
            {
                "type": "node",
                "request": "launch",
                "name": "Launch Program",
                "program": "${workspaceRoot}/*folder_path_to_test*/app.js"
            }
        ]
    }
    

    3) Set breakpoints in test file and then press F5

提交回复
热议问题