Skip to content

Commit 757b85d

Browse files
authoredAug 14, 2021
docs: improve 'grep()' and clarify docs (#4714)
1 parent f19d3ca commit 757b85d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
 

‎docs/index.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1138,17 +1138,20 @@ Cause Mocha to only run tests matching the given `regexp`, which is internally c
11381138

11391139
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`.
11401140

1141+
And another option with double quotes: `--grep "groupA|groupB"`.<br>
1142+
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.
1143+
11411144
```js
11421145
describe('api', function() {
1143-
describe('GET /api/users', function() {
1146+
describe('GET /api/users groupA', function() {
11441147
it('respond with an array of users', function() {
11451148
// ...
11461149
});
11471150
});
11481151
});
11491152

11501153
describe('app', function() {
1151-
describe('GET /users', function() {
1154+
describe('GET /users groupB', function() {
11521155
it('respond with an array of users', function() {
11531156
// ...
11541157
});

‎example/config/.mocharc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
// This is a JavaScript-based config file containing every Mocha option plus others.
4-
// If you need conditional logic, you might want to use this type of config.
4+
// If you need conditional logic, you might want to use this type of config,
5+
// e.g. set options via environment variables 'process.env'.
56
// Otherwise, JSON or YAML is recommended.
67

78
module.exports = {

‎lib/mocha.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ Mocha.prototype.fgrep = function(str) {
581581
Mocha.prototype.grep = function(re) {
582582
if (utils.isString(re)) {
583583
// extract args if it's regex-like, i.e: [string, pattern, flag]
584-
var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
584+
var arg = re.match(/^\/(.*)\/([gimy]{0,4})$|.*/);
585585
this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
586586
} else {
587587
this.options.grep = re;

0 commit comments

Comments
 (0)
Please sign in to comment.