mocha --inspect-brk <fileName> 似乎已停止工作 - 附加调试器时测试文件没有 运行
mocha --inspect-brk <fileName> seems to have stopped working - test file does not run when debugger attached
我已经创建了一个 public 存储库来证明这在一个基本模块中不起作用,该模块只包含一个 mocha 测试文件和一个脚本 运行 通过带有调试器的 mocha 所述文件:
https://github.com/corey-cosman/mocha-test-debug
重现:
git clone git@github.com:corey-cosman/mocha-test-debug.git
npm install
npm run test:debug
预计:
此测试文件 运行s 并在断点处停止
实际:
调试器附加并侦听端口 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
});
});
如前所述,这已经工作了一段时间,最近才停止,昨天注意到了。任何帮助是极大的赞赏。谢谢!
发生这种情况是因为 --inspect-brk
在脚本到达您的测试脚本之前中断了脚本执行,而您的测试脚本本来就是这样做的。参见 https://nodejs.org/en/docs/guides/debugging-getting-started/
--inspect-brk Break before user code starts
您需要打开 chrome 上的开发工具,然后单击绿色的 nodejs 图标以查看您的应用程序调试器。然后单击恢复执行(蓝色播放按钮),使其移动到您的 debugger
断点
您的 test:debug
脚本也有错误,文件名有错字。
这应该是您在 package.json
上的 test:debug
命令
"test:debug": "mocha -- --inspect-brk ./test/mocha-debug-test.js"
我已经创建了一个 public 存储库来证明这在一个基本模块中不起作用,该模块只包含一个 mocha 测试文件和一个脚本 运行 通过带有调试器的 mocha 所述文件:
https://github.com/corey-cosman/mocha-test-debug
重现:
git clone git@github.com:corey-cosman/mocha-test-debug.git
npm install
npm run test:debug
预计:
此测试文件 运行s 并在断点处停止
实际:
调试器附加并侦听端口 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
});
});
如前所述,这已经工作了一段时间,最近才停止,昨天注意到了。任何帮助是极大的赞赏。谢谢!
发生这种情况是因为 --inspect-brk
在脚本到达您的测试脚本之前中断了脚本执行,而您的测试脚本本来就是这样做的。参见 https://nodejs.org/en/docs/guides/debugging-getting-started/
--inspect-brk Break before user code starts
您需要打开 chrome 上的开发工具,然后单击绿色的 nodejs 图标以查看您的应用程序调试器。然后单击恢复执行(蓝色播放按钮),使其移动到您的 debugger
断点
您的 test:debug
脚本也有错误,文件名有错字。
这应该是您在 package.json
上的test:debug
命令
"test:debug": "mocha -- --inspect-brk ./test/mocha-debug-test.js"