Let's say you have a simple mocha test:
describe("Suite", function(){
it("test",function(doneCallback){
// here be tests
});
});
In this test I can change the timeout by adding this.timeout(VALUE);
anywhere within the describe
function.
However, besides the timeout
value, there are plenty of other Mocha options that can be exclusively declared either from the command line or from a mocha.opts
file that lives in the test folder (./test/mocha.opts
).
What I want is to change some of these options at run-time (for example, the reporter
) and not in command line / mocha.opts
file.
From my research of what's possible, I found that there is an article explaining how you can use mocha programmatically, which would allow changing these options at run-time, but you need to create the Mocha
instance yourself, whereas in an ordinary test one doesn't have direct access to the Mocha
instance.
So, is there a way to get the Mocha
instance from an existent test and change some of these options like reporter
at run-time during a test?
I would like to have an option that doesn't require to modify the source code of Mocha
in any way (I suppose I could tamper with the Mocha
instance to implement a way to get an instance directly in the Mocha
constructor).