3

I have a node.js/express/mocha project. From my project's root dir, whne I do

./node_modules/.bin/mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list

  1) UnitsController /units.json "before all" hook
  ․ CordBloodUnit should set attrs: 0ms
  ․ CordBloodUnit #getMatchCount should get the match count of alleles: 0ms
  ․ pg-adapter #runQuery should get results of the query: 7ms
  ․ pg-adapter #runQuery should get Cord Blood Units: 4ms

  4 passing (2s)
  1 failing

  1) UnitsController /units.json "before all" hook:
     Error: timeout of 2000ms exceeded
    at Object.<anonymous> (/Users/pguruprasad/Projects/jeevan-js/node_modules/mocha/lib/runnable.js:175:14)
    at Timer.list.ontimeout (timers.js:101:19)

I see all the tests are being run. But when I want to put the long command in a script to execute, mocha runs only two tests and ignores the remaining. What could be wrong here?

➜  ~jjs git:(master) ✗ touch test1
➜  ~jjs git:(master) ✗ echo "./node_modules/.bin/mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list" >> test1
➜  ~jjs git:(master) ✗ cat test1
./node_modules/.bin/mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list
➜  ~jjs git:(master) ✗ chmod +x test1
➜  ~jjs git:(master) ✗ ./test1       

  ․ CordBloodUnit should set attrs: 0ms
  ․ CordBloodUnit #getMatchCount should get the match count of alleles: 0ms

  2 passing (2ms)
gprasant
  • 15,589
  • 9
  • 43
  • 57

4 Answers4

2

Your issue is likely that the path or environment variables your script is running with is different. It may be running global mocha instead of the mocha installed in your project, or it may have a different cwd.

I highly recommend adding the following to the scripts section of your package.json:

"scripts": {
    "test": "mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list",
  }

You can then easily access this with npm test. Note that npm always runs the locally installed, not global mocha. It also lets you do clever things like running multiple scripts, as in How to run mocha and mocha-phantomjs tests from one "npm test" command in node.js?. Finally, it works reliably in Windows as well as Unix and OS X.

Community
  • 1
  • 1
Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
  • nope, still runs only two tests . mocha --compilers coffee:coffee-script-redux/register test/**/*.coffee --reporter list ․ CordBloodUnit should set attrs: 0ms ․ CordBloodUnit #getMatchCount should get the match count of alleles: 0ms 2 passing (2ms) – gprasant Feb 23 '14 at 08:53
  • i think I should probably ask someone from the mocha project why this happens – gprasant Feb 23 '14 at 08:54
0

try ./node_modules/.bin/_mocha

Tracker1
  • 19,103
  • 12
  • 80
  • 106
0

Make sure all your test files have the .coffee extension, and not .js. One thing I like to do is, put all my tests with this pattern name: my_file_test.coffee. All with the _test.coffee.

-1

This happened to me too, and the issue was actually that I had a describe() block with no it() calls in it. Hope that helps someone!

Ethan
  • 873
  • 1
  • 8
  • 11