在调试模式下,当使用节点检查器时,mocha不会停止在规范文件中的调试器语句上 [英] In debug mode, mocha doesn't stop on debugger statements in a spec file when using node-inspector

查看:311
本文介绍了在调试模式下,当使用节点检查器时,mocha不会停止在规范文件中的调试器语句上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用-debug-brk运行mocha,并使用node-inspector打开chrome开发工具时,调试器将跳过我放在我的specfile中的任何调试器语句。

When I run mocha with --debug-brk and open chrome dev tools with node-inspector, the debugger skips over any debugger statements that I put in my specfile.

I 可以让调试器语句在模块文件中工作,只要我遵循

I can get debugger statements to work in module files provided I follow this trick of placing a breakpoint at the bottom of the mocha lib.

有没有人看到这个问题?

Has anybody else seen this problem?

推荐答案

似乎每个人都应该看到与node-inspector版本0.2.0beta4相同的问题。

It seems that everybody should be seeing the same problem with node-inspector version 0.2.0beta4.

问题是如何管理断点:


  • 前端记住浏览器本地存储中的断点,并恢复它们在相关文件加载之后。

  • 当您使用 - debug-brk 启动摩卡,并停止在第一行,您的spec文件没有加载,所以前端是n恢复您的断点。

  • 当您恢复摩卡执行时,前端无法在简短窗口中快速恢复断点,并在规则文件被解析并运行。事实上,在V8调试器更改之前,摩卡可能会退出,以通知前端关于要解析的新脚本!

  • The front-end remembers break-points in browser's local storage and restores them after the relevant file is loaded.
  • When you start mocha with --debug-brk and stop on the first line, your specfiles are not loaded yet, so the front-end does not restore your breakpoints.
  • When you resume mocha execution, front-end can't restore breakpoints quickly enough in the short window between a specfile is parsed and run. In fact mocha may exit before the V8 debugger has a change to notify front-end about new scripts being parsed!

另一个解决方法问题是在要触发断点的specfile中添加 debugger; 语句。

Another workaround for this issue is to add debugger; statement in the specfile where you want to trigger a breakpoint.

编辑

EDIT

请注意,如果您在中设置断点,则github上的节点检查器问题中提到的解决方案将会起作用。 $ c>回调(即spec实现),但它不会帮助您在构建规范描述的代码中设置断点(即,您的规范文件中的顶级代码和所有描述 callbacks)。

Note that the solution mentioned in node-inspector issue on github will work if you set breakpoint inside your it callback (i.e. spec implementation) but it won't help you with setting a breakpoint in the code which builds spec description (i.e. top-level code in your specfile and all describe callbacks).

示例:

var expect = require('chai').expect;
var calculator = require('./StringCalculator');

// CANNOT break on the line below
describe('add', function() {
  // CANNOT break on the line below
  it('returns 0 for empty string', function() {
    // CAN break on the line below
    expect(calculator.add('')).to.equal(0);
  });
});

EDIT2

问题在我的节点检查器的分支中修复了: https://github.com/strongloop/node -inpector 。您可以在浏览器中加载节点检查器UI后立即在您的spec文件中设置断点。

The problem is fixed in my fork of node-inspector: https://github.com/strongloop/node-inspector. You can set breakpoints anywhere in your specfiles immediately after the node-inspector UI is loaded in your browser.

这篇关于在调试模式下,当使用节点检查器时,mocha不会停止在规范文件中的调试器语句上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆