2

I am trying to debug a Mocha test with Visual Studio Code that runs in a Docker container. Due to the Docker container I must launch the tests from inside the container and attach to it which disqualifies answers like this one. I am getting the debugger to connect and it even breaks with the --debug-brk flag enabled. But every breakpoint I set gets marked as "Unverified breakpoint" by VS Code, regardless of whether I set it:

  • in the tested Typescript files
  • in Javascript files required directly or indirectly by the Typescript files
  • in the Typescript compiler output

Here is what I do:

  1. Run npm test inside the container which translates to NODE_ENV=test API_PORT=8081 DBDATABASE=tests mocha --timeout 50000 -r source-map-support/register -r ts-node/register --preserve-symlinks --exit --debug-brk --inspect=0.0.0.0:9229 "./src/**/*.spec.ts"
  2. Launch the debugger.
  3. Set the breakpoint. It immediately greys out and says "Unverified breakpoint" on hover.

The relevant part of launch.json:

{
    "type": "node",
    "request": "attach",
    "name": "Debug Backend",
    "port": 9229,
    "restart": true,
    "protocol": "inspector",
    "localRoot": "${workspaceFolder}/api/backend/",
    "remoteRoot": "/api/backend/",
    "outFiles": ["${workspaceFolder}/api/backend/dist/**/*.js"],
    "skipFiles": ["<node_internals>/**/*.js"]
},

In case it might be relevant, here is the tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": ["es5", "dom", "scripthost", "es2017", "es6", "es7"],
    "allowJs": true,
    "outDir": "./dist/",
    "preserveSymlinks": true,
    "strict": true,
    "noImplicitThis": false,
    "moduleResolution": "node",
    "baseUrl": "./",
    "paths": {
      "sequelize-test-helpers": ["typings/sequelize-test-helpers"]
    },
    "typeRoots": ["node_modules/@types", "typings"],
    "types": ["node", "core-js"]
  },
  "include": ["src/**/*.ts", "typings"]
}
303
  • 888
  • 1
  • 11
  • 31

0 Answers0