How to debug unit tests written in Typescript with Mocha from Visual Studio Code

updating this thread to the config that worked for us (note to self).

  • the --compilers option in https://stackoverflow.com/a/44999572/147530 is deprecated
  • ts:ts-node/register gives error
  • adding "${relativeFile}" also gives error Unexpected token / in JSON at position 6 as the "${relativeFile}" resolves to .vscode/launch.json .

updated config

{            
            "name": "mocha tests",
            "type": "node",
            "protocol": "inspector",
            "request": "launch",
            "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
            "stopOnEntry": false,
            "args": [ "-r", "ts-node/register", "${workspaceRoot}/test/**/*.spec.ts", "--no-timeouts"],
            "cwd": "${workspaceRoot}"
}

If anybody finds it useful, the following launch.json configuration snippet is working for me without any workaround:

    {
    "name": "mocha tests",
    "type": "node",
    "protocol" : "inspector",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
    "stopOnEntry": false,
    "args": [ "--compilers", "ts:ts-node/register", "--no-timeouts", "${relativeFile}"],
    "cwd": "${workspaceRoot}"
    }

Works fine for me with node v7.10.0, typescript 2.4.0 and Visual Studio Code 1.13.1 . Both mocha and typescript are installed locally under node_modules.