15

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.

Sebastian Kropp
  • 411
  • 3
  • 8
  • This similar answer, using truffle-core, worked for me: https://ethereum.stackexchange.com/a/41096/3708 – Svante Apr 24 '18 at 11:24

2 Answers2

16

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.

Sebastian Kropp
  • 411
  • 3
  • 8
  • That doesn't seem to run the tests for me. – Daniel Ryan Aug 15 '18 at 22:01
  • 3
    It worked for me after I installed truffle as a local package – ulu Jan 20 '19 at 10:21
  • You may want to add the network (configured in truffle-config.js) to the arguments, like, assuming you called your network develop: "args": ["test", "--network", "develop"],

    Also, you can just use the truffle executable instead of cli.bundled.js in the "program" section; I have found it running which truffle from shell.

    – Fanta Jul 17 '21 at 10:33
3

Clearly, if you have installed truffle globally (npm install -g truffle), you will need to provide the full path of that directory e.g.: "program": "/usr/local/lib/node_modules/truffle/build/cli.bundled.js"

Gogogol
  • 31
  • 1