Open pkuczynski opened 5 years ago
Maybe I am missing something, but I tried every possible combination without success :(
Fixed in https://github.com/stanleyhlng/mocha-multi-reporters/pull/32 Try:
const mocha = new Mocha({
reporter: "mocha-multi-reporters",
reporterOptions: {
"reporterEnabled": 'spec, mocha-junit-reporter',
"mochaJunitReporterReporterOptions": {
"mochaFile": "junit-custom.xml",
"includePending": true,
"outputs": true
}
}
});
That doesn't work @dragancla
Because we are here about .mocharc.js
meaning
"use strict";
module.exports = {
reporter: "mocha-multi-reporters",
reporterOptions: {
"reporterEnabled": 'spec, mocha-junit-reporter',
"mochaJunitReporterReporterOptions": {
"mochaFile": "junit-custom.xml",
"includePending": true,
"outputs": true
}
}
}
While I understand this is a different issue, is anyone able to get reporterOptions
(or reporter-options
) working in .mocharc.js
for any reporter (including configFile
for mocha-multi-reporters
)? If this isn't working for Mocha, then that would presumably need to be fixed first. (I'm able to get other mocharc working, including reporter
, but not reporter-options
; looks like someone else had this issue as well.)
I think I was able to fix this:
module.exports = {
reporter: 'mocha-multi-reporters',
'reporter-options': 'configFile=reporter.config.json'
}
You still have to have a separate file, unfortunately, but it looks like using quotes around reporter-options
allows mocha to read this flag.
https://mochajs.org/#configuration-format
I was looking at their examples: https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.js
and noticed that two-worded flags were kept hyphenated with quotes and not camel-cased.
👋. Using the examples above (in the .mocharc
), it looks like the results output to mocha-xunit-reporter
instead of mocha-junit-reporter
🤷♂️.
I'm not sure if this has been fully implemented yet based on this comment... but it always defaults to spec, mocha-xunit-reporter
no matter what is entered.
I ran into this issue as well, though I'm using the JSON format for mocharc instead of JS. I believe it would be a similar issue. What looks like is happening if you do not specify configFile in the reporterOptions is that it first loads the default file here: https://github.com/stanleyhlng/mocha-multi-reporters/blob/master/lib/MultiReporters.js#L178
This file is defaulting to spec and xunit, which is the behavior that rob4629 saw: https://github.com/stanleyhlng/mocha-multi-reporters/blob/master/config.json
But then it's supposed to find custom options to overlay over the defaults, which can come from mocharc.js, here: https://github.com/stanleyhlng/mocha-multi-reporters/blob/master/lib/MultiReporters.js#L171
However, if I define something like this in mocharc.js:
{ "reporter": "mocha-multi-reporters", "reporterEnabled": "spec,mocha-junit-reporter", "mochaJunitReporterReporterOptions": { "mochaFile": "dist/test/test-results.xml" } }
The call on 171 fails to get any options. If you print out the contents of options, which is the input to line 171, you will see this piece:
... 'reporterOptions.reporterEnabled': 'spec,mocha-junit-reporter', 'reporterOptions.mochaJunitReporterReporterOptions.mochaFile': 'dist/test/test-results.xml', reporterOptions: undefined, ...
So the call to get() returns undefined, even though there are options under reporterOptions. This looks to be the reason you cannot currently specify reporter options directly in mocharc, they cannot be loaded correctly by the call on line 171.
A working solution: tell mocha-multi-reporters
that your configFile
is your mocharc file. It would be better to have support for the current Mocha reporterOptions
as an object, but that will do it in the meantime. Here is the relevant excerpt of my .mocharc.json
:
{
"reporter": "mocha-multi-reporters",
"reporterEnabled": "spec, mocha-junit-reporter",
"reporterOptions": "configFile=.mocharc.json",
"mochaJunitReporterReporterOptions": {
"mochaFile": "./junit.xml",
"includePending": true,
"outputs": true
}
}
@mielp Didn't this solution cause you problems with parallel mode? After deep debugging it seems like it's kind of messes with the junit reporter options in a way that fails the run :(
Expected behavior
I would like to specify reporterOptions inside
.mocharc.js
file like this:Actual behavior
When specified in
.mocarc.js
,reportIOptions
are being ignored and I have to still use external file:Information about the Issue
I am using following packages: