如何将简单的 Node cli/repl 调试器与 Jest 一起使用?
Jest documentation使用 node-inspector ,但从 Node 6.3 开始它已过时/弃用。我还是在 Node 7.7.4 上尝试了推荐的命令:
node --debug-brk ./node_modules/.bin/jest --runInBand --no-cache [your_test_file]
但这只是卡在下面(假设等待 Node 检查器):
(node:13452) DeprecationWarning: Node --debug 已弃用。请改用 node --inspect 。监听 127.0.0.1:5858 的调试器
我按照警告的规定添加了 --inspect
,但即便如此,执行也不会在 Chrome DevTools 中的 debugger
语句上停止。
对于一个非常简单的用例来说,这似乎过于复杂。
最佳答案
我发现以下命令有效:
Node 调试 ./node_modules/.bin/jest --runInBand --no-cache [你的测试文件]
...但有一些古怪的行为。当调试器第一次停止时,您将看到:
break in node_modules/jest/bin/jest.js:10
8 */
9
>10 'use strict';
11
12 require('jest-cli/bin/jest');
debug>
显然,Jest 总是会注入(inject)此断点,以便您有时间打开 Chrome DevTools(在我们的案例中无关紧要,因为我们只打算使用 cli/repl)。
使用 c
继续越过这个断点,在很短的时间之后(当然没有任何迹象表明事情正在进展)你应该看到你的断点:
break in webpack/assets/react/components/presentation/Feed/Comments/Comment/commentSpec.jsx:12
10 var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_comment2.default, { loading: true }));
11
>12 debugger;
13 expect(wrapper.find(_button2.default)).to.have.length(1);
14 });
debug>
最后一件奇怪的事情是您需要键入 repl 来检查对象,如 Node Debugger 中所述。和 Inspecting variables using node's built-in debugger?
在阅读文档时,所有这些步骤的组合对我来说并不是很明显,所以我希望这个答案可以帮助人们更快地克服障碍。
关于node.js - 如何将 Node 调试 cli 与 Jest 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42981238/