简体   繁体   中英

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

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. Now I want to add 'istanbul' or 'lcov' reporter to add in mocha. How can I do it?

You have to install your reporter via npm first. If you have installed mocha globally, you also have to install your reporter globally.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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