簡體   English   中英

如何與記者一起運行摩卡測試?

[英]How to run mocha tests with reporter?

當我運行npm test它輸出:

 mocha ./tests/ --recursive --reporter mocha-junit-reporter

並且所有測試運行良好。 但是當我嘗試調用 mocha ./tests/flickr/mytest --reporter junit-reporter我得到:

 Unknown "reporter": junit-reporter

如何正確傳遞?

來自mocha-junit-reporter自述文件

# install the package
npm install mocha-junit-reporter --save-dev

# run the test with reporter
mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=./path_to_your/file.xml

我在您的命令中發現了兩個問題:

mocha ./tests/flickr/mytest --reporter junit-reporter

第一個問題是mocha上面是全球節點模塊摩卡命令。 但是,當執行npm test ,它實際上是針對node_modules文件夾中的本地mocha命令。

第二個問題是記者的名字應該是mocha-junit-reporter而不是junit-reporter

解決方案

解決方法是針對本地mocha

./node_modules/.bin/mocha ./tests/flickr/mytest --reporter mocha-junit-reporter

這是優選的解決方案。

替代解決方案是為全局節點模塊安裝mocha-junit-reporter ,如下所示:

npm install -g mocha-junit-reporter
mocha ./tests/flickr/mytest --reporter mocha-junit-reporter

這不是太可取,因為與本地節點模塊中的版本相比,您可以在全局中定位不同版本的 mocha 和 mocha-junit-reporter。

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM