Mocha breakpoints using Visual Studio Code

后端 未结 20 1297
星月不相逢
星月不相逢 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:01

    I've made this work on VSCode on OS X 10.10. Just replace your ./settings/launch.json file with this.

    {
        "version": "0.1.0",
        "configurations": [
            {
                "name": "Run app.js",
                "type": "node",
                "program": "app.js", // Assuming this is your main app file.
                "stopOnEntry": false,
                "args": [],
                "cwd": ".",
                "runtimeExecutable": null,
                "env": { "NODE_ENV": "production"}
            },
            {
                "name": "Run mocha",
                "type": "node",
                "program": "/Users/myname/myfolder/node_modules/mocha/bin/_mocha",
                "stopOnEntry": false,
                "args": ["test/unit.js"],
                "cwd": ".",
                "runtimeExecutable": null,
                "env": { "NODE_ENV": "production"}
            }
        ]
    }
    

    It is also available as a gist here.

    The key values you need to change are program, which should be set to the _mocha executable, and args, which should be an array of your test files.

提交回复
热议问题