I was trying to unit test the apple push notification library when I got a global leak error trying to open up an APN connection.
Is that a configuration error on my part or an error in node-apn or mocha?
I'm not sure I understand what checkGlobals is doing... is it just checking to see if any global variable are being set?
0) Feed "before all" hook:
Error: global leak detected: hasCert
at Runner.checkGlobals (/usr/lib/node_modules/mocha/lib/runner.js:96:21)
at Runner.<anonymous> (/usr/lib/node_modules/mocha/lib/runner.js:41:44)
at Runner.emit (events.js:64:17)
at /usr/lib/node_modules/mocha/lib/runner.js:159:12
at Hook.run (/usr/lib/node_modules/mocha/lib/runnable.js:114:5)
at next (/usr/lib/node_modules/mocha/lib/runner.js:157:10)
at Array.<anonymous> (/usr/lib/node_modules/mocha/lib/runner.js:165:5)
at EventEmitter._tickCallback (node.js:126:26)
Yes, Mocha features a global leak detection mechanism which alerts and fails if your code under test introduces global variables.
If
hasCert
is declared in a library and you have no control over its creation, you can tell Mocha to ignore it.On the command line,
To quote the documentation:
In a browser:
I came across this answer when I trying to figure out how to squelch JSONP leaks such as:
Squelch jQuery JSONP "leaks" via:
I ran into this problem as well, you probably forgot a
var
statement somewhere like I did, which in JS means that a global variable will be created.You may have to hunt it down yourself depending on how you structured your app, and hopefully it's not a 3rd-party bit of code that's causing this. :P
You should use JSLint or JSHint through your project, they should help uncover the source if it's anywhere in your code.
You can also disable global leak detection by passing:
In a browser:
I was encountering this error for many functions as follows:
So I passed a wildcard in the setup function and it solved my issue.
I added "mocha.globals(['browserSync']);" below to fix my problem. The rest of the code is from https://mochajs.org/ - section : RUNNING MOCHA IN THE BROWSER