☕️ Classic, reliable, trusted test framework for Node.js and the browser
Add support for a ?grep=pattern search variable in the browser to allow filtering of the tests run.
Harry Brundageca23fb25ba0f
diff --git a/mocha.js b/mocha.jsindex b5236a71..4a61e6b6 100644--- a/mocha.js+++ b/mocha.js@@ -2270,7 +2270,7 @@ exports.escape = function(html) {/*** Node shims.- *+ ** These are meant only to allow* mocha.js to run untouched, not* to allow running node code in@@ -2287,10 +2287,22 @@ global = this;mocha = require('mocha');// boot-;(function(){var suite = new mocha.Suite;var Reporter = mocha.reporters.HTML;+ function parse(qs) {+ return qs+ .replace('?', '')+ .split('&')+ .reduce(function(obj, pair){+ var i = pair.indexOf('=')+ , key = pair.slice(0, i)+ , val = pair.slice(++i);++ obj[key] = decodeURIComponent(val);+ return obj;+ }, {});+ }mocha.setup = function(ui){ui = mocha.interfaces[ui];@@ -2303,6 +2315,8 @@ mocha = require('mocha');suite.emit('run');var runner = new mocha.Runner(suite);var reporter = new Reporter(runner);+ var params = parse(window.location.search || "");+ if (pattern = params['grep']) runner.grep(new RegExp(pattern));runner.run();};-})();\ No newline at end of file+})();diff --git a/support/tail.js b/support/tail.jsindex 97513745..bf8be547 100644--- a/support/tail.js+++ b/support/tail.js@@ -1,7 +1,7 @@/*** Node shims.- *+ ** These are meant only to allow* mocha.js to run untouched, not* to allow running node code in@@ -18,10 +18,22 @@ global = this;mocha = require('mocha');// boot-;(function(){var suite = new mocha.Suite;var Reporter = mocha.reporters.HTML;+ function parse(qs) {+ return qs+ .replace('?', '')+ .split('&')+ .reduce(function(obj, pair){+ var i = pair.indexOf('=')+ , key = pair.slice(0, i)+ , val = pair.slice(++i);++ obj[key] = decodeURIComponent(val);+ return obj;+ }, {});+ }mocha.setup = function(ui){ui = mocha.interfaces[ui];@@ -34,6 +46,8 @@ mocha = require('mocha');suite.emit('run');var runner = new mocha.Runner(suite);var reporter = new Reporter(runner);+ var params = parse(window.location.search || "");+ if (pattern = params['grep']) runner.grep(new RegExp(pattern));runner.run();};-})();\ No newline at end of file+})();