[英]Debugging jasmine-node tests with node-inspector
有誰知道這是否可能? 節點檢查器的大多數示例似乎都適合調試調用的網頁。 不過,我希望能夠調試 jasmine-node 測試。
簡而言之,只需調試 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
最后我寫了一個叫做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 退出。 您也可以重新運行,這很好。
w0000噸。
我沒有受過教育的猜測是你需要修補 jasmine,我相信它會在運行測試時產生一個新的節點進程或其他東西,並且這些新進程需要啟用調試。
我有類似的願望,並設法使用 Eclipse 作為調試器讓 expressso 工作: http://groups.google.com/group/nodejs/browse_thread/thread/af35b025eb801f43
……但我意識到:如果我需要單步調試代碼來理解它,我可能需要重構代碼(可能更易於測試),或者將我的測試分解成更小的單元。
你的測試就是你的調試器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.