2014-02-15 92 views
3

我有一個node.js/express/mocha項目。從我的項目的根目錄,我做的爲什麼不是bin/mocha運行我所有的測試?

./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) 

我看到所有的測試正在運行。但是當我想將長命令放在一個腳本中執行時,mocha只運行兩個測試並忽略其餘部分。這裏有什麼可能是錯的?

➜ ~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) 
+0

你能添加一下'test /'的樹嗎?鑑於@ dankohn的答案不起作用? – Tracker1

回答

1

您的問題很可能是您的腳本運行的路徑或環境變量不同。它可能運行的是全球摩卡,而不是您的項目中安裝的摩卡,或者它可能有不同的密碼。

我強烈建議加入以下到您的package.json的腳本部分:

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

然後,您可以輕鬆地與npm test訪問此。請注意,npm始終運行本地安裝的全球摩卡。它還可以讓你做一些聰明的事情,比如運行多個腳本,如How to run mocha and mocha-phantomjs tests from one "npm test" command in node.js?。最後,它可以可靠地工作在Windows以及Unix和OS X.

+0

不行,仍然只運行兩個測試。 摩卡咖啡 - 編譯咖啡:coffee-script-redux/register test/**/*。coffee --reporter list 。 CordBloodUnit應設置attrs:0ms 。 CordBloodUnit #getMatchCount應得到等位基因的匹配計數:0ms 2合格(2ms) – gprasant

+0

我想我應該問一個來自摩卡項目的人爲什麼會發生這種情況 – gprasant

0

嘗試./node_modules/.bin/_mocha

0

確保所有的測試文件有.coffee擴展,而不是的.js。我喜歡做的一件事是,把我的所有測試用這個模式名稱:my_file_test.coffee。全部用_test.coffee

-1

這也發生在我身上,問題是我有一個describe()塊,沒有it()調用。希望能幫助別人!

相關問題