Typescript 使用npm和package.json脚本启动测试时,VSCode未在断点处停止

Typescript 使用npm和package.json脚本启动测试时,VSCode未在断点处停止,typescript,visual-studio-code,vscode-debugger,Typescript,Visual Studio Code,Vscode Debugger,从VSCode中,我想启动当前文件(例如my function.spec.ts)并进行交互式调试设置断点 为了运行测试,我需要设置一些环境变量,例如MONGO=mongodb://localhost:27017/。因此,我通过npm脚本启动测试,并使用launch.json中定义的配置的“envFile”属性传递环境变量 launch.json是 "configurations": [ { "name": "Current TS Tests File

VSCode中,我想启动当前文件(例如my function.spec.ts)并进行交互式调试设置断点

为了运行测试,我需要设置一些环境变量,例如
MONGO=mongodb://localhost:27017/
。因此,我通过npm脚本启动测试,并使用launch.json中定义的配置的
“envFile”
属性传递环境变量

launch.json

   "configurations": [
        {
            "name": "Current TS Tests File",
            "type": "node",
            "request": "launch",
            "runtimeExecutable": "npm",
            "args": ["${relativeFile}"],
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "envFile": "${workspaceFolder}/.env",
            "runtimeArgs": ["run-script", "test-one"]
        },
    ]
}
package.json脚本是

"scripts": {
   "test-one": "npm mocha -r ts-node/register",
}

通过这种配置,我能够启动测试。测试按预期执行,但代码不会在我设置的断点处停止执行。关于如何使断点工作有什么建议吗?

以下配置在我的机器上工作。源代码通过NPM运行启动配置,调试器点击
assert
上的断点

有关使用
节点ts
和VS-code进行调试的更多详细信息。如果您需要更多帮助将此设置映射到您的需求,请告诉我

package.json

{
  "scripts": {
    "test": "mocha -r ts-node/register --inspect --debug-brk index.test.ts"
  },
  "devDependencies": {
    "@types/mocha": "^5.2.7",
    "@types/node": "^12.0.12",
    "mocha": "^6.1.4",
    "ts-node": "^8.3.0",
    "typescript": "^3.5.2"
  }
}
launch.json

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch via NPM",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run-script", "test"],
      "port": 9229
    }
  ]
}
tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true
  }
}
index.test.ts

import assert from 'assert';

describe('index', function () {
    it('should pass', function () {
        assert.equal(true, true);
    });
});
太好了--inspect--debug brk'为我做了这件事。谢谢