From 7680a7bf99d409f12a350b0cfe080e4d3dfa791c Mon Sep 17 00:00:00 2001 From: Andrew Krawchyk <903716+akrawchyk@users.noreply.github.com> Date: Mon, 23 Apr 2018 12:13:33 -0400 Subject: [PATCH 1/3] update docs with globbing and shell expansion details; closes #3136 --- docs/index.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/index.md b/docs/index.md index a5acfc9945..2319a3383a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1275,6 +1275,18 @@ $ mocha --reporter list --growl By default, `mocha` looks for the glob `./test/*.js`, so you may want to put your tests in `test/` folder. If you want to include sub directories, use `--recursive`, since `./test/*.js` only matches files in the first level of `test` and `./test/**/*.js` only matches files in the second level of `test`. +To configure where `mocha` looks for tests, you may pass your own glob: + +``` +$ mocha ./spec/*.js +``` + +If you use shell expansion for this, you must wrap your glob pattern in double quotes (note, using the `--recursive` flag here is useless): + +``` +$ mocha "./spec/**/*.js" +``` + ## Editor Plugins The following editor-related packages are available: From d6354cb96db218096d38bd0da3b53b40f6e53017 Mon Sep 17 00:00:00 2001 From: Andrew Krawchyk <903716+akrawchyk@users.noreply.github.com> Date: Tue, 24 Apr 2018 09:38:20 -0400 Subject: [PATCH 2/3] requested changes --- docs/index.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/index.md b/docs/index.md index 2319a3383a..881f0f4f24 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1273,20 +1273,16 @@ $ mocha --reporter list --growl ## The `test/` Directory -By default, `mocha` looks for the glob `./test/*.js`, so you may want to put your tests in `test/` folder. If you want to include sub directories, use `--recursive`, since `./test/*.js` only matches files in the first level of `test` and `./test/**/*.js` only matches files in the second level of `test`. +By default, `mocha` looks for the glob `./test/*.js`, so you may want to put your tests in `test/` folder. If you want to include sub directories, pass the `--recursive` option, since `./test/*.js` only matches files in the first level of `test` and `./test/**/*.js` only matches files in the second level of `test`. To configure where `mocha` looks for tests, you may pass your own glob: -``` -$ mocha ./spec/*.js -``` - -If you use shell expansion for this, you must wrap your glob pattern in double quotes (note, using the `--recursive` flag here is useless): - -``` +```sh $ mocha "./spec/**/*.js" ``` +*Note*: Double quotes around the glob are recommended for portability. + ## Editor Plugins The following editor-related packages are available: From babdf1ef9d732bc94654bcb95bafc0709ace6e32 Mon Sep 17 00:00:00 2001 From: Andrew Krawchyk <903716+akrawchyk@users.noreply.github.com> Date: Thu, 26 Apr 2018 11:38:08 -0400 Subject: [PATCH 3/3] add explanation for recursive matching for different shells --- docs/index.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 881f0f4f24..49a18be5a7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1273,10 +1273,16 @@ $ mocha --reporter list --growl ## The `test/` Directory -By default, `mocha` looks for the glob `./test/*.js`, so you may want to put your tests in `test/` folder. If you want to include sub directories, pass the `--recursive` option, since `./test/*.js` only matches files in the first level of `test` and `./test/**/*.js` only matches files in the second level of `test`. +By default, `mocha` looks for the glob `./test/*.js`, so you may want to put your tests in `test/` folder. If you want to include sub directories, pass the `--recursive` option. To configure where `mocha` looks for tests, you may pass your own glob: +```sh +$ mocha --recursive "./spec/*.js" +``` + +Some shells support recursive matching by using the `**` wildcard in a glob. Bash >= 4.3 supports this with the [`globstar` option](https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html) which [must be enabled](https://github.com/mochajs/mocha/pull/3348#issuecomment-383937247) to get the same results as passing the `--recursive` option ([ZSH](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Recursive-Globbing) and [Fish](https://fishshell.com/docs/current/#expand-wildcard) support this by default). With recursive matching enabled, the following is the same as passing `--recursive`: + ```sh $ mocha "./spec/**/*.js" ```