How can mocha recursively search my `src` folder for a specific file name template?

In my npm package, I would like to emulate the template that Meteor follows: the source file (named client.js) has a test file (named client.tests.js) in the folder src/. Tests are performed using the command npm test.

I follow the usage docs in 't'. I do not want to use findin my test team.

  • I understand that mocha can execute tests recursively:

    mocha --recursive

  • I understand that mocha can run tests in a specific subfolder using the flag --recursive:

    mocha src --recursive

  • I also understand that I can tell glob to filter files by going *.tests.js:

    mocha * .tests.js

But I want all three. I want mocha to only test files ending in tests.jsin the src folder, recursively checking subdirectories.

mocha --recursive *.tests.js

// See the files?
$ > ll ./src/app/
total 168
-rw-r--r--  ... client.js
-rw-r--r--  ... client.tests.js

// Option A
$ > mocha --recursive *.tests.js
Warning: Could not find any test files matching pattern: *.tests.js
No test files found

// Option B
$ > mocha *.tests.js --recursive
Warning: Could not find any test files matching pattern: *.tests.js
No test files found.

// Option C
$ > mocha --recursive src/app/*.tests.js
3 passing (130ms)
3 failing

So...

  • Why doesn't mocha collect files *.tests.jsin subfolders?
  • Why does it work if I specify the full path to the file?
  • How can I make it work as I wish?
+6
source share
1 answer

--recursive . glob, , , glob, , , --recursive . --recursive glob, globs . :

mocha 'src/app/**/*.tests.js'

, *.tests.js src/app. , . , Mobba globbing. . , , ** *, .

+17

Source: https://habr.com/ru/post/1016011/


All Articles