Visual Studio Code Breakpoints Don't Hit When Debugging Mocha Tests

I use Mocha (and Chai) for my unit tests for the NodeJS module and want to debug it in Visual Studio code. I have a TypeScript file in a subfolder testwith some tests. VScode generates .js and .map files in an external directory (using the tsc view mode task). My tsconfig.json file contains the following settings:

{
    "compilerOptions": {
        "compileOnSave": true,
        "module": "commonjs",
        "target": "es6",
        "outDir": "out",
        "removeComments": true,
        "noImplicitAny": true,
        "sourceMap": true,
        "inlineSources": true,
        "isolatedModules": false,
        "allowSyntheticDefaultImports": true,
        "experimentalDecorators": true
    },
    "include": [
        "src/**/*", "parser/**/*", "test/**/*"
    ],
    "exclude": [
        "node_modules",
        ".vscode-test"
    ]
}

and the external directory contains 3 subdirs for 3 inclusions. So far so good.

I can run my tests with this command:

mocha --compilers ts:ts-node/register,tsx:ts-node/register

outside of vscode. Then I ran this code using the switch --debug-brkand connected the vscode to it. This works, but the breakpoint does not hit. Configuration in launch.json for this:

    {
        "name": "Attach",
        "type": "node",
        "request": "attach",
        "port": 5858,
        "address": "localhost",
        "restart": false,
        "sourceMaps": true,
        "outDir": null,
        "localRoot": "${workspaceRoot}",
        "remoteRoot": null
    }

, , mocha. :

    {
        "name": "Mocha",
        "type": "node",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "preLaunchTask": "tsc",
        "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
        "args": [ "--no-timeouts", "--colors", "${workspaceRoot}/out/test/**/*.js" ],
        "stopOnEntry": true,
        "runtimeExecutable": null,
        "env": {
           "NODE_ENV": "testing"
        }
        "sourceMaps": true
    }

, , .

?

: , , debugger; - debugger;. , . .

+4
1

"protocol": "inspector", , , , . . , , . : outfiles , vscode TS. :

        "outFiles": [
            "${workspaceRoot}/out/**/*.js"
        ],

. , vscode , - .

+1

Source: https://habr.com/ru/post/1665348/


All Articles