diff --git a/docs/index.md b/docs/index.md index 1c26cea1d0..b0c22608c6 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 c Suppose, 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"`.
+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. + ```js describe('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.js index e80004a9dc..402ec03565 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.js index 62a414a9fa..b36210d60e 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;