DEV Community

loading...

VSCode debugger config with Mocha and Babel 7

boobo94 profile image Bogdan Alexandru Militaru Originally published at boobo94.xyz on ・2 min read

The post VSCode debugger config with Mocha and Babel 7 appeared first on boobo94. So if you want to read more articles like this please subscribe to my newsletter or follow me here

VSCode debugger is a very nice tool that you can use in every project. I personally prefer VSCode for most programming languages that I write code. The minimalism and extendability make it very powerful.

If you wanna know more about my VSCode configurations and extensions that I use check VSCode setup for web development: settings and extensions.

These days I tried to configure the VSCode debugger for a Node.js project that I’m working on in testing mode. I use Babel 7 and Mocha framework for tests. Apparently everything looks very simple and intuitive because the VSCode offers support to create a new config for different tasks, so I choose the default one for Mocha.

I encountered a few issues trying to run the VSCode debugger with Mocha and Babel 7, but the configuration is not very hard and can be shown below:

{
      "type": "node",
      "request": "launch",
      "name": "Mocha Tests",
      "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
      "runtimeArgs": [],
      "args": [
        "${workspaceFolder}/test/**/*.js",
        "--require",
        "@babel/register",
        "-u",
        "bdd",
        "--timeout",
        "999999",
        "--colors"
      ],
      "env": {
        "NODE_ENV": "test",
      },
      "internalConsoleOptions": "openOnSessionStart"
    }
Enter fullscreen mode Exit fullscreen mode

Firstly I had to change the type from tdd to bdd , because Mocha runs as bdd. Secondly is very important to pass the needed plugins in order for Node to interpret the code correctly. Please observe –require @babel/core.

If you like the article and consider it helpful please take the tiger out of the cage and inform others about it. Please share it with your people and subscribe to my newsletter. Don’t forget to leave me a comment about your opinion related to this article and ask me some questions.

The post VSCode debugger config with Mocha and Babel 7 appeared first on boobo94. So if you want to read more articles like this please subscribe to my newsletter or follow me here

Discussion (0)

pic
Editor guide