Truffle – How to Debug a Truffle JS Unit Test in VSCode

mochatestingtrufflevisual-studio-code

I am using visual studio code and truffle and would like to easily debug my JavaScript tests.

A similar question has been asked here: how can I run a truffle test in a debugger?. This has been wrongly marked as a duplicated and not been released.

Best Answer

Add the following to your configurations in launch.json:

"configurations": [
        {
            "name": "run tests",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/node_modules/truffle/build/cli.bundled.js",
            "args": ["test"],
            "cwd": "${workspaceRoot}",
            "outFiles": [
                "${workspaceRoot}/test/**/*"
            ],
          }
    ]

You will need to adjust the program property to match the path of your installed truffle if you have installed truffle globally.