简体   繁体   English

如何在摩卡咖啡中添加第三方记者?

[英]How to add third party reporter in mocha?

I want to add a third party reporter in mocha. 我想在摩卡咖啡中添加第三方记者。 https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically https://github.com/mochajs/mocha/wiki/Using-mocha-以编程方式

In above link its saying to select a reporter like below: 在上面的链接中其话语如下选择记者:

var mocha = new Mocha({
    ui: 'tdd',
    reporter: 'xunit'
});

xunit comes in bundle with mocha. xunit与Mocha捆绑在一起。 Now I want to add 'istanbul' or 'lcov' reporter to add in mocha. 现在,我想添加“ istanbul”或“ lcov”记者来添加摩卡。 How can I do it? 我该怎么做?

You have to install your reporter via npm first. 您必须先通过npm安装记者。 If you have installed mocha globally, you also have to install your reporter globally. 如果您已在全球范围内安装了Mocha,则还必须在全球范围内安装报告程序。

npm install mocha-lcov-reporter -g

Then, you have to add the path of your reporter in the task: 然后,您必须在任务中添加报告者的路径:

var mocha = new Mocha({
  ui: 'tdd',
  reporter: './node_modules/mocha-lcov-reporter'
});

I have not tried this example, but I think it works. 我没有尝试过这个例子,但是我认为它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM