2014-03-25 81 views
1

我試着讓摩卡記者輸出HTML文件,使用mocha.opts配置文件:聲明輸出文件

--compilers coffee:coffee-script/register 
--reporter html-cov > tests.html 

然而,這總是返回如下:

→ mocha 

/usr/local/lib/node_modules/mocha/bin/_mocha:432 
    if (!files.length) throw new Error("cannot resolve path (or pattern) '" 
         ^
Error: cannot resolve path (or pattern) '>' 

如果我直接在shell中傳遞命令mocha --reporter html-cov > testes.html,它確實有效。

我錯過了什麼?

+0

您錯誤地將使用摩卡功能的shell重定向(將命令的輸出寫入文件)。但是,添加該功能會很好!你可以在[GitHub repo](https://github.com/visionmedia/mocha)中添加一個問題,甚至嘗試自己實現它。 – Esteban

回答

2

您不能在mocha.opts中放置重定向。當你在命令行上執行它時,整個命令被shell解釋,並且>被理解爲重定向。然而mocha.opts文件的目的是作爲選項閱讀,只有選項,沒有別的。摩卡無法弄清楚> tests.html是否意味着重定向。你可以把這個在您的mocha.opts

--compilers coffee:coffee-script/register 
--reporter html-cov 

,並保持> tests.html在命令行上,或者如果你想避免鍵入它使用包裝腳本。

如果有一個選項告訴摩卡輸出到一個特定的文件(例如,--output file),那麼你可以把它放在mocha.opts,但摩卡目前沒有這樣的選項。