☕️ Classic, reliable, trusted test framework for Node.js and the browser
Added -g, --grep <pattern> support
Tj Holowaychuk0693f775362e
diff --git a/bin/mocha b/bin/mochaindex 922018a2..52b8c26f 100755--- a/bin/mocha+++ b/bin/mocha@@ -31,7 +31,8 @@ program.option('-r, --require <name>', 'require the given module').option('-R, --reporter <name>', 'specify the reporter to use', 'dot').option('-u, --ui <name>', 'specify user-interface (bdd|tdd|exports)', 'bdd')- .option('-g, --growl', 'enable growl support')+ .option('-g, --grep <pattern>', 'only run tests matching <pattern>')+ .option('-G, --growl', 'enable growl support')// report help@@ -97,6 +98,7 @@ function run(suite) {suite.emit('run');var runner = new Runner(suite);var reporter = new Reporter(runner);+ 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.jsindex 09609775..74a8b844 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -35,6 +35,7 @@ function Runner(suite) {this.total = suite.total();this.globals = Object.keys(global);this.on('test end', this.checkGlobals.bind(this));+ this.grep(/.*/);}/**@@ -43,6 +44,19 @@ function Runner(suite) {Runner.prototype.__proto__ = EventEmitter.prototype;+/**+ * Run tests with full titles matching `re`.+ *+ * @param {RegExp} re+ * @return {Runner} for chaining+ * @api public+ */++Runner.prototype.grep = function(re){+ this._grep = re;+ return this;+};+/*** Check for global variable leaks.*@@ -182,6 +196,9 @@ Runner.prototype.runTests = function(suite, fn){// all doneif (!test) return fn();+ // grep+ if (!self._grep.test(test.fullTitle())) return next();+// execute test and hook(s)self.emit('test', self.test = test);self.hook('beforeEach', function(err){diff --git a/lib/suite.js b/lib/suite.jsindex 78f7d5dd..56391cfd 100644--- a/lib/suite.js+++ b/lib/suite.js@@ -45,7 +45,8 @@ Suite.prototype.__proto__ = EventEmitter.prototype;Suite.prototype.beforeAll = function(fn){this.beforeAllCallbacks.push(fn);return this;-}+};+/*** Run `fn(test[, done])` after running tests.*@@ -57,7 +58,7 @@ Suite.prototype.beforeAll = function(fn){Suite.prototype.afterAll = function(fn){this.afterAllCallbacks.push(fn);return this;-}+};/*** Run `fn(test[, done])` before each test case.@@ -70,7 +71,8 @@ Suite.prototype.afterAll = function(fn){Suite.prototype.beforeEach = function(fn){this.beforeEachCallbacks.push(fn);return this;-}+};+/*** Run `fn(test[, done])` after each test case.*@@ -82,7 +84,7 @@ Suite.prototype.beforeEach = function(fn){Suite.prototype.afterEach = function(fn){this.afterEachCallbacks.push(fn);return this;-}+};/*** Add a test `suite`.