Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha run with recursive glob pattern does not run all tests on Mac

I am using mocha for testing. I am running mocha with a recursive glob pattern (./src/**/*.test.ts) to run all my tests, but only some of them are executed. Particularly only my tests under src/utils are being run. If I give mocha ./src/handlers/**/*.test.ts as the path the tests do execute under src/handlers, but obviously this is not ideal.

I have done some refactoring on my code and before that it worked fine.

What am I doing wrong?

My project structure looks like this:

src
  |-handlers
  |    |-Connection
  |        |-tests
  |            |- handleConnection.test.ts
  |            |- handleDisconnection.test.ts
  |            |...
  |-utils
       |-utils.test.ts
       |...

I am trying to run mocha with this npm script:

"test": "mocha ./src/**/*.test.ts -r ts-node/register"
like image 260
Levente Rozsenich Avatar asked Jan 31 '26 03:01

Levente Rozsenich


1 Answers

After digging around some more I have solved my issue by putting the glob pattern between single quotes:

"test": "mocha './src/**/*.test.ts' -r ts-node/register"

Apparently without putting it between quotes some systems can interpret ** as *: How can mocha recursively search my `src` folder for a specific filename pattern?

like image 95
Levente Rozsenich Avatar answered Feb 02 '26 17:02

Levente Rozsenich