Mocha breakpoints using Visual Studio Code

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

    I've figured out a way to do this which I classify as a workaround. I expect the Visual Studio Code team to provide a more definitive solution for this but meanwhile this what I've done:

    1. I've created a ./settings/mocha.js file which runs mocha programatically passing arguments as a list of files to be run. You can see the full file here;
    2. I've created a launch config which will run the ./settings/mocha.js as the program and passes the files/file patterns we need to test as arguments:

      {
          "name": "Unit tests",
          "type": "node",
          "program": ".settings/mocha.js",
          "stopOnEntry": true,
          "args": ["test/unit/*.js", "test/unit/**/*.js"],
          "cwd": ".",
          "runtimeExecutable": null,
          "env": { }
      }
      

      Full launch.json example

    So this is the equivalent of doing mocha test/unit/*.js test/unit/**/*.js and now we can use breakpoints in our mocha tests.

提交回复
热议问题