[英]How to run mocha tests with reporter?
When I run npm test
it outputs:当我运行
npm test
它输出:
mocha ./tests/ --recursive --reporter mocha-junit-reporter
And all tests run well.并且所有测试运行良好。 But when I try to invoke mocha
./tests/flickr/mytest --reporter junit-reporter
I got:但是当我尝试调用 mocha
./tests/flickr/mytest --reporter junit-reporter
我得到:
Unknown "reporter": junit-reporter
How to pass it correctly?如何正确传递?
I spotted two issues in your command:我在您的命令中发现了两个问题:
mocha ./tests/flickr/mytest --reporter junit-reporter
First issue is mocha
in above is a mocha command from global node module.第一个问题是
mocha
上面是全球节点模块摩卡命令。 However, when executing npm test
, it actually targets local mocha
command inside our node_modules
folder.但是,当执行
npm test
,它实际上是针对node_modules
文件夹中的本地mocha
命令。
Second issue is the name of reporter should be mocha-junit-reporter
not junit-reporter
第二个问题是记者的名字应该是
mocha-junit-reporter
而不是junit-reporter
Workaround is to target local mocha
解决方法是针对本地
mocha
./node_modules/.bin/mocha ./tests/flickr/mytest --reporter mocha-junit-reporter
This is preferrable solution.这是优选的解决方案。
Alternative solution is to install mocha-junit-reporter
for global node modules as below:替代解决方案是为全局节点模块安装
mocha-junit-reporter
,如下所示:
npm install -g mocha-junit-reporter
mocha ./tests/flickr/mytest --reporter mocha-junit-reporter
This is not too preferrable because you can target different version of mocha and mocha-junit-reporter in global compare to the one in local node modules.这不是太可取,因为与本地节点模块中的版本相比,您可以在全局中定位不同版本的 mocha 和 mocha-junit-reporter。
Cheers干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.