使用 node-inspector 调试 jasmine-node 测试

发布于 2024-11-10 09:47:53 字数 69 浏览 0 评论 0原文

有谁知道这是否可能?节点检查器的大部分示例似乎都是为了调试调用的网页。不过,我希望能够调试 jasmine-node 测试。

Does anyone have any idea if this is possible? Most of the sample for node-inspector seemed geared toward debugging an invoked webpage. I'd like to be able to debug jasmine-node tests though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅气尐潴 2024-11-17 09:47:53

简而言之,只需调试 jasmine-node:

node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js spec/my_spec.js

如果您查看 jasmine-node 脚本的源代码,它只是调用 cli.js,我发现我可以调试它脚本就好了。

我想使用节点检查器来调试 CoffeeScript 测试。只需添加 --coffee 开关就可以很好地工作,例如

node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js --coffee spec/my_spec.coffee

In short, just debug jasmine-node:

node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js spec/my_spec.js

If you look at the source of the jasmine-node script, it just invokes cli.js, and I found I could debug that script just fine.

I wanted to use node-inspector to debug a CoffeeScript test. Just adding the --coffee switch worked nicely, e.g.

node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js --coffee spec/my_spec.coffee
小嗷兮 2024-11-17 09:47:53

我最终编写了一个名为“toggle”的小实用程序:

require('tty').setRawMode(true);
var stdin = process.openStdin();

exports.toggle = function(fireThis)
{
    if (process.argv.indexOf("debug")!=-1)
    {
        console.log("debug flag found, press any key to start or rerun. Press 'ctrl-c' to cancel out!");
        stdin.on('keypress', function (chunk, key) {
            if (key.name == 'c' && key.ctrl == true)
            {
                process.exit();
            }
            fireThis();
        });
    }
    else
    {
        console.log("Running, press any key to rerun or ctrl-c to exit.");
        fireThis();
        stdin.on('keypress', function (chunk, key) {
            if (key.name == 'c' && key.ctrl == true)
            {
                process.exit();
            }
            fireThis();
        });



    }
}

您可以将其放入单元测试中,例如:

var toggle = require('./toggle');

toggle.toggle(function(){

    var vows = require('vows'),
    assert = require('assert');

    vows.describe('Redis Mass Data Storage').addBatch({

....

然后运行测试,例如:node --debug myfile.js debug。如果你运行调试开关,它将等待你除了 ctrl-c 之外的任何操作。 Ctrl-c 退出。您也可以重新运行,这很好。

w0000t。

I ended up writing a little util called toggle:

require('tty').setRawMode(true);
var stdin = process.openStdin();

exports.toggle = function(fireThis)
{
    if (process.argv.indexOf("debug")!=-1)
    {
        console.log("debug flag found, press any key to start or rerun. Press 'ctrl-c' to cancel out!");
        stdin.on('keypress', function (chunk, key) {
            if (key.name == 'c' && key.ctrl == true)
            {
                process.exit();
            }
            fireThis();
        });
    }
    else
    {
        console.log("Running, press any key to rerun or ctrl-c to exit.");
        fireThis();
        stdin.on('keypress', function (chunk, key) {
            if (key.name == 'c' && key.ctrl == true)
            {
                process.exit();
            }
            fireThis();
        });



    }
}

You can drop it into your unit tests like:

var toggle = require('./toggle');

toggle.toggle(function(){

    var vows = require('vows'),
    assert = require('assert');

    vows.describe('Redis Mass Data Storage').addBatch({

....

And then run your tests like: node --debug myfile.js debug. If you run debug toggle will wait until you anything but ctrl-c. Ctrl-c exits. You can also rerun, which is nice.

w0000t.

夏雨凉 2024-11-17 09:47:53

我未经教育的猜测是,您需要修补 jasmine,我相信它在运行测试时会生成一个新的节点进程或其他进程,并且这些新进程需要启用调试。

我有类似的愿望并设法使用 Eclipse 作为调试器让expressso工作:
http://groups.google.com/group/nodejs/browse_thread/thread/af35b025eb801f43

…但我意识到:如果我需要单步执行代码来理解它,我可能需要重构代码(可能是更可测试),或者将我的测试分解为更小的单元。

您的测试就是您的调试器。

My uneducated guess is that you'd need to patch jasmine, I believe it spawns a new node process or something when running tests, and these new processes would need to be debug-enabled.

I had a similar desire and managed to get expressso working using Eclipse as a debugger:
http://groups.google.com/group/nodejs/browse_thread/thread/af35b025eb801f43

…but I realised: if I needed to step through my code to understand it, I probably need to refactor the code (probably to be more testable), or break my tests up into smaller units.

Your tests is your debugger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文