A bit of a hack to get multiple reporters working with mocha
npm install mocha-multi --save-dev mocha --reporter mocha-multi
For both methods below, the special value of
- (hyphen) for destination uses normal stdout/stderr.
Set the environment variable
multi to whitespace-separated type=destination pairs.
multi='dot=- xunit=file.xml doc=docs.html' mocha -R mocha-multi
--reporter-options with comma-separated type=destination pairs.
mocha -R mocha-multi --reporter-options dot=-,xunit=file.xml,doc=docs.html
You may specify the desired reporters (and their options) by passing
reporterOptions to the Mocha contructor.
For example: the following config is the equivalent of setting
multi='spec=- Progress=/tmp/mocha-multi.Progress.out', with the addition of passing the
verbose: true option to the Progress reporter.
var reporterOptions =;var mocha = new Mocha;mocha.addFile;mocha.run;
The options will be passed as the second argument to the reporter constructor.
A big hack that keeps changing the value of process.stdout and process.stderr whenever a reporter is doing its thing.
This is very hacky, specifically:
consoleobjects get their internal state messed with
process.exitis hacked to wait for streams to finish writing
Now that https://github.com/mochajs/mocha/pull/1059 is released the process.exit hack could be tidier
Now that https://github.com/mochajs/mocha/pull/1061 is released, I only need to hijack stdout, and can leave stderr alone
Having each reporter run in a child process would make it eaiser to capture their streams, but might lead to other issues