Permalink
Browse files

Fixes #166 - When grepping don't display the empty suites

Don't emit the 'suite' event if the suite doesn't contain tests matching
the grep expression.
  • Loading branch information...
1 parent ba6b06d commit cd186e07983d7c3c01e3a7832164ddfeb9354c76 @antoviaque antoviaque committed Apr 9, 2012
Showing with 36 additions and 7 deletions.
  1. +26 −7 lib/runner.js
  2. +10 −0 test/runner.js
View
@@ -62,17 +62,33 @@ Runner.prototype.__proto__ = EventEmitter.prototype;
*/
Runner.prototype.grep = function(re){
- var self = this;
debug('grep %s', re);
- self._grep = re;
+ this._grep = re;
+ this.total = this.grepTotal(this.suite);
+
+ return this;
+};
+
+/**
+ * Returns the number of tests matching the grep search for the
+ * given suite.
+ *
+ * @param {Suite} suite
+ * @return {Number}
+ * @api public
+ */
- self.suite.iterateTests(function(test){
- if (!self._grep.test(test.fullTitle())){
- self.total--;
+Runner.prototype.grepTotal = function(suite) {
+ var self = this;
+ var total = 0;
+
+ suite.iterateTests(function(test){
+ if (self._grep.test(test.fullTitle())){
+ total++;
};
});
- return self;
+ return total;
};
/**
@@ -355,7 +371,10 @@ Runner.prototype.runSuite = function(suite, fn){
, i = 0;
debug('run suite %s', suite.fullTitle());
- this.emit('suite', this.suite = suite);
+
+ if(self.grepTotal(suite)) {
+ this.emit('suite', this.suite = suite);
+ }
function next() {
var curr = suite.suites[i++];
View
@@ -23,6 +23,16 @@ describe('Runner', function(){
})
})
+ describe('.grepTotal()', function(){
+ it('should return the total number of matched tests', function(){
+ suite.addTest(new Test('im a test about lions'));
+ suite.addTest(new Test('im another test about lions'));
+ suite.addTest(new Test('im a test about bears'));
+ runner.grep(/lions/);
+ runner.grepTotal(suite).should.equal(2);
+ })
+ })
+
describe('.globals()', function(){
it('should default to the known globals', function(){
runner.globals().length.should.be.above(10);

0 comments on commit cd186e0

Please sign in to comment.