Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running mocha test in subfolders

I am using Sails.js for some project. Now I wrote some unit tests. My test folder hierarchy is like following:

/test
    bootstrat.test.js
    mocha.opts
    /unit
        /controller
            User.js
            Representative.js
        /model
            User.js
            Representative.js
        /service
            Utility.js

For testing I now have to run all these following commands:

$ mocha test/unit/controller
$ mocha test/unit/model
$ mocha test/unit/service

But this is time consuming and too manual. I wanted to run all these tests with just one command and searched Google. I tried running mocha --recursive test. But it's not working. It results in following error -

  1) "before all" hook
  2) "after all" hook

  0 passing (2s)
  2 failing

  1)  "before all" hook:
     Error: timeout of 2000ms exceeded
      at null.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:159:19)
      at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

  2)  "after all" hook:
     TypeError: Cannot call method 'lower' of undefined
      at Context.<anonymous> (/home/gladiator/Codes/rms-generic-web/test/bootstrap.test.js:21:9)
      at Hook.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:218:15)
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:259:10)
      at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:345:15)

Is there a way in which I can run all these tests with just one command?

like image 494
taufique Avatar asked Oct 24 '25 09:10

taufique


1 Answers

Did you try to make you own bash script ?

Create mocha.sh and put this in it :

#!/bin/bash

mocha test/unit/controller
mocha test/unit/model
mocha test/unit/service

And run it with sh ./mocha.sh

I don't know enough mocha to do it with it.

like image 123
jaumard Avatar answered Oct 25 '25 22:10

jaumard



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!