Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom reporter with Mocha

I am sure I am missing something obvious here!

I have read the instructions here (https://github.com/visionmedia/mocha/wiki/Third-party-reporters), and have taken their code and added as a new node module (i.e. it is within node_modules/my-reporter/reporter.js). However, I can't seem to get mocha to load this reporter.

I have tried numerous variations …

mocha allTests.js -R ./node_modules/my-reporter/reporter.js

mocha allTests.js -R my-reporter

But nothing works :-(

I can successfully load my reporter within a JS file:

my_reporter = require('./node_modules/my-reporter/reporter.js')
console.log(my_reporter);

Has anyone got any hints?

like image 274
ColinE Avatar asked Jan 26 '14 19:01

ColinE


2 Answers

u should provide the reporter like this:

mocha allTests.js -R './node_modules/my-reporter/reporter'

You should not provide the .js file extension as that is the normal convention for including modules.

like image 160
Amar Zavery - MSFT Avatar answered Oct 01 '22 17:10

Amar Zavery - MSFT


It appears that if mocha is installed globally (which I believe it almost always is), you have to install your reporter the same way.

If you don't want to publish the reporter as a public module, you can just:

npm pack
npm install /path/to/your/module.gz -g

I've tried putting the reporter everywhere else that would make sense, but was getting "invalid reporter" unless it was installed globally.

like image 29
TPresley Avatar answered Oct 01 '22 16:10

TPresley