☕️ Classic, reliable, trusted test framework for Node.js and the browser
docs: improve 'grep()' and clarify docs (#4714)
Juerg B757b85dd2300
diff --git a/docs/index.md b/docs/index.mdindex 1c26cea1..b0c22608 100644--- a/docs/index.md+++ b/docs/index.md@@ -1138,9 +1138,12 @@ Cause Mocha to only run tests matching the given `regexp`, which is internally cSuppose, for example, you have "api" related tests, as well as "app" related tests, as shown in the following snippet; One could use `--grep api` or `--grep app` to run one or the other. The same goes for any other part of a suite or test-case title, `--grep users` would be valid as well, or even `--grep GET`.+And another option with double quotes: `--grep "groupA|groupB"`.<br>+And for more complex criterias: `--grep "/get/i"`. Some shells as e.g. Git-Bash-for-Windows may require: `--grep "'/get/i'"`. Using flags other than the `ignoreCase /i` (especially `/g` and `/y`) may lead to unpredictable results.+```jsdescribe('api', function() {- describe('GET /api/users', function() {+ describe('GET /api/users groupA', function() {it('respond with an array of users', function() {// ...});@@ -1148,7 +1151,7 @@ describe('api', function() {});describe('app', function() {- describe('GET /users', function() {+ describe('GET /users groupB', function() {it('respond with an array of users', function() {// ...});diff --git a/example/config/.mocharc.js b/example/config/.mocharc.jsindex e80004a9..402ec035 100644--- a/example/config/.mocharc.js+++ b/example/config/.mocharc.js@@ -1,7 +1,8 @@'use strict';// This is a JavaScript-based config file containing every Mocha option plus others.-// If you need conditional logic, you might want to use this type of config.+// If you need conditional logic, you might want to use this type of config,+// e.g. set options via environment variables 'process.env'.// Otherwise, JSON or YAML is recommended.module.exports = {diff --git a/lib/mocha.js b/lib/mocha.jsindex 62a414a9..b36210d6 100644--- a/lib/mocha.js+++ b/lib/mocha.js@@ -581,7 +581,7 @@ Mocha.prototype.fgrep = function(str) {Mocha.prototype.grep = function(re) {if (utils.isString(re)) {// extract args if it's regex-like, i.e: [string, pattern, flag]- var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);+ var arg = re.match(/^\/(.*)\/([gimy]{0,4})$|.*/);this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);} else {this.options.grep = re;