Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

add flag to ignore global leaks #82

Quang Van2765c21d05b3
diff --git a/bin/mocha b/bin/mocha
index 0bca43fb..3273a5fb 100755
--- a/bin/mocha
+++ b/bin/mocha
@@ -46,6 +46,7 @@ program
.option('-C, --no-colors', 'force disabling of colors')
.option('-c, --colors', 'force enabling of colors')
.option('-G, --growl', 'enable growl notification support')
+ .option('-gl, --leaks', 'ignore Global Leaks')
.option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
.option('--interfaces', 'display available interfaces')
.option('--reporters', 'display available reporters')
@@ -175,6 +176,8 @@ function run(suite) {
var runner = new Runner(suite);
var reporter = new Reporter(runner);
runner.globals(program.globals);
+ if(program.leaks)
+ runner.check_global_leaks = false
if (program.grep) runner.grep(new RegExp(program.grep));
if (program.growl) growl(runner, reporter)
runner.run();
diff --git a/lib/runner.js b/lib/runner.js
index d5e705fd..fc085f3a 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -37,10 +37,13 @@ function Runner(suite) {
this._globals = [];
this.suite = suite;
this.total = suite.total();
- this.on('test end', function(test){ self.checkGlobals(test); });
- this.on('hook end', function(hook){ self.checkGlobals(hook); });
+ if(this.check_global_leaks){
+ this.on('test end', function(test){ self.checkGlobals(test); });
+ this.on('hook end', function(hook){ self.checkGlobals(hook); });
+ }
this.grep(/.*/);
this.globals(Object.keys(global).concat(['errno']));
+ this.check_global_leaks = true
}
/**