我正在尝试使用在Docker容器中运行的Visual Studio Code调试Mocha测试。由于使用Docker容器,我必须从容器内部启动测试并将其附加到该容器上,这将使诸如this one之类的答案不合格。我正在连接调试器,并且在启用--debug-brk
标志的情况下它甚至中断了。但是我设置的每个断点都会被VS Code标记为“未验证的断点”,无论我是否设置了它:
这是我的工作:
npm test
,将其转换为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"
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"]
},
如果可能与之相关,请参见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"]
}