[英]Node.js - why do I get leaks when testing with mocha and zombie?
I've tried to make zombie work with mocha, but unless I use the mocha --ignore-leaks command options, my test always fails with the error: 我试图使僵尸程序与mocha一起使用,但是除非我使用mocha --ignore-leaks命令选项,否则我的测试将始终失败,并显示以下错误:
Error: global leaks detected: k, i, name, chars, char
My test looks exactly like the one explained in this thread: Mocha and ZombieJS 我的测试与该线程中解释的测试完全相同: Mocha和ZombieJS
I wish I could have posted my question there, but as a newbie, I cannot comment on the thread, only ask a new question. 我希望我可以在这里发布我的问题,但是作为一个新手,我不能在主题上发表评论,而只能提出一个新问题。
Do you have any idea why I get these leaks? 您知道我为什么会泄漏这些吗? I'm using mocha 1.0.3 and zombie 1.0.0. 我正在使用摩卡咖啡1.0.3和僵尸1.0.0。
The leaks can come either from your own code or from node_modules that you use. 泄漏可能来自您自己的代码,也可能来自您使用的node_modules。 Mocha should give some hints on where the leaks are, such as forgetting to declare local variable with var . Mocha应该对泄漏的位置给出一些提示,例如忘记使用var声明局部变量。
// global leaks
a = 1;
// no leaks
var a = 1;
You might also be interested writing Node.js app in coffeescript since it helps you avoid mistakes like that. 您可能也有兴趣在coffeescript中编写Node.js应用程序,因为它可以帮助您避免此类错误。 ( It automatically initializes variables, using var ) http://coffeescript.org/ ( 它使用var自动初始化变量 ) http://coffeescript.org/
There is a template that helps you get started here https://github.com/twilson63/express-coffee 这里有一个模板可以帮助您入门https://github.com/twilson63/express-coffee
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.