mocha --inspect-brk <fileName> 似乎停止工作了 -- 当调试器连接时,测试文件没有运行。

问题描述 投票:1回答:1

我创建了一个公共资源库来演示在一个基本模块中不能工作的情况,该模块只包含一个mocha测试文件和一个通过mocha运行该文件并附带调试器的脚本。

https:/github.comcorey-cosmanmocha-test-debug。

以供复制。

git clone [email protected]:corey-cosman/mocha-test-debug.git

npm install

npm run test:debug

预期:

这个测试文件在断点处运行和停止。

实际。

调试器连接并监听127.0.0.1:9229端口,但mocha文件没有运行。

package.json:

{
  "name": "mocha-test-debug",
  "version": "1.0.0",
  "description": "",
  "main": "test/mocha-test-debug.js",
  "scripts": {
    "test:debug": "mocha -- --inspect-brk  ./test/mocha-test-debug.js"
  },
  "devDependencies": {
    "mocha": "^7.2.0"
  }
}

test/mocha-test-debug.js:

describe('mocha test debug', function () {
  it('should run test and hit breakpoint', async function () {
    debugger
  });
});

* 如前所述,这已经工作了一段时间,最近才停止,昨天才注意到。任何帮助都非常感激。谢谢!我已经创建了一个公共资源库,以证明在基本模块中无法工作,只需包含一个摩卡。

javascript debugging mocha inspect
1个回答
1
投票

出现这种情况是因为 --inspect-brk 是在到达你的测试脚本之前就中断了脚本的执行,它的目的就是这样。请看 https:/nodejs.orgendocsguidesdebugging-getting-started。

--inspect-brk 在用户代码开始前中断。

你需要在chrome上打开devtools,然后点击绿色的nodejs图标来查看你的应用程序调试器。然后点击恢复执行(蓝色的播放按钮),使其移动到你的 debugger 断点

另外,你的 test:debug 脚本,文件名上有一个错别字。

这应该是你的 test:debug 吩咐 软件包.json

"test:debug": "mocha -- --inspect-brk ./test/mocha-debug-test.js"

© www.soinside.com 2019 - 2024. All rights reserved.