Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

node.js - global leak errors in mocha

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)
question from:https://stackoverflow.com/questions/8360318/global-leak-errors-in-mocha

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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,

$ mocha --globals hasCert

To quote the documentation:

[This option] accepts a comma-delimited list of accepted global variable names. For example suppose your app deliberately exposes a global named app and YUI, you may want to add --globals app,YUI.

In a browser:

mocha.setup({globals: ['hasCert']});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...