Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

Error: global leaks detected: k, i, name, chars, char

My test looks exactly like the one explained in this thread: Mocha and 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.

like image 935
biberli Avatar asked May 11 '12 04:05

biberli


People also ask

Does Mocha run tests in parallel?

Mocha does not run individual tests in parallel. That means if you hand Mocha a single, lonely test file, it will spawn a single worker process, and that worker process will run the file. If you only have one test file, you'll be penalized for using parallel mode. Don't do that.

How do I stop mocha testing?

Find out how you can ignore some tests in Mocha You can use the skip() method (on describe() or it() ) to ignore some tests: In case of describe , it will ignore all tests in the describe block (which includes all nested describe and it functions); In case of it , it will ignore the individual test.


1 Answers

The leaks can come either from your own code or from node_modules that you use. Mocha should give some hints on where the leaks are, such as forgetting to declare local variable with 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. (It automatically initializes variables, using var) http://coffeescript.org/

There is a template that helps you get started here https://github.com/twilson63/express-coffee

like image 157
250R Avatar answered Sep 21 '22 16:09

250R