Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test recursively using mocha

I have a problem with mocha, it does not understand my test hierarchy! I want my tests to be near their codebase, so I have some hierarchy like this in my project:

Level1
    |_ level11
        |_ level11.js
        |_ level11.test.js
                            |_ level11111
                                |_ level11111.js
                                |_ level11111.test.js
    |_ level12
        |_ level12.js
        |_ level12.test.js
        |_ level121
            |_ level121.js
            |_ level121.test.js
Level2
    |_ level2.js
    |_ level2.test.js

I have tried everything! Using **/**.test.js or —recursive flag, non of them do what it should do!

like image 813
sara usingers Avatar asked Dec 12 '25 02:12

sara usingers


1 Answers

Linux to rescue! I had the same problem in a HUGE project that literally had no structure at all! Some developers had put tests in tests folder and some other in nested layers and … (some tests were using mocha and some using jest! In the SAME project! :D)

you can use:

mocha $(find . -name '*.spec.js')

in your package.json so:

  "scripts": {
    "test": "mocha $(find . -name '*.spec.js')"
  },
like image 89
Robot Avatar answered Dec 14 '25 15:12

Robot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!