Mocha breakpoints using Visual Studio Code

后端 未结 20 1281
星月不相逢
星月不相逢 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条回答
  • 2020-12-12 12:28

    in the launch.json, add 1 more configuration below

    {
          "type": "node",
          "request": "launch",
          "name": "Mocha Tests",
          "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
          "args": [
            "--timeout",
            "10000",
            "${workspaceRoot}/services/*.spec.js",
            "${workspaceRoot}/*.spec.js"
          ],
          "internalConsoleOptions": "openOnSessionStart"
        },
    

    if you need to configure node version, simply add runtimeExecutable field like this

    {
          "type": "node",
          "request": "launch",
          "name": "Mocha Tests",
          "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
          "args": [
            "--timeout",
            "10000",
            "${workspaceRoot}/services/*.spec.js",
            "${workspaceRoot}/*.spec.js"
          ],
          "internalConsoleOptions": "openOnSessionStart",
          "runtimeExecutable": "${env:HOME}/.nvm/versions/node/v8.2.1/bin/node"
        },
    
    0 讨论(0)
  • 2020-12-12 12:28

    Simplest solution

    Add the following code to the launch.json inside the .vscode folder :

    {
                "name": "Unit tests",
                "type": "node",
                "request": "launch",
                "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
                "args": [
                ],
            }
    

    You might want however to add a timeout argument as well:

     {
                "name": "Unit tests",
                "type": "node",
                "request": "launch",
                "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
                "args": [
                    "--timeout",
                    "999999"
                ],
            }
    
    0 讨论(0)
提交回复
热议问题