Mocha: Support `require` and `reporter-options` in `mocharc`

Created on 6 Jan 2020  路  11Comments  路  Source: mochajs/mocha

Is your feature request related to a problem or a nice-to-have?? Please describe.

I am not able to get reporter-options (or reporterOptions) working with either _mocha or mocha when the config is within mocha on package.json or in .mochrarc.js

require is also not working either as an array or set of strings.

But other properties are working.

Describe the solution you'd like

I'd like it to be possible to add reporterOptions and require within mocharc.js.

Describe alternatives you've considered

It seems unnecessarily clunky to add as flags to the CLI, especially when I've already added an RC file.

Additional context

-

unconfirmed-bug

All 11 comments

These _should_ be working. Can you provide a sample repo or configuration?

On master of https://github.com/brettz9/intl-dom, I'm not using it currently, but on this branch it is failing: https://github.com/brettz9/intl-dom/tree/mocha-failing .

The reporter options in master point mocha-multi-reporters to the right configFile, i.e., to mocha-multi-reporters.json which triggers mocha-badge-generator to run producing output at badges/test-badges.svg. But in the branch, the reporter-options are not passed on.

If this could be an issue with mocha-multi-reporters I seem to remember replicating with another config without it, and can look to reproduce as needed.

This is also happening to me. https://github.com/CrowdStrike/faltest/blob/58ef39600c/packages/mocha/src/index.js#L55

My junit is printing to console instead of taking reporter options "output=dist/test_output.xml".

The repro is to check out that repo, use commit 7857ec083be2867eec901d737954c3cc7d56201c (right before mocha 7). Then yarn install and run yarn start examples/runner-only/tests/* --reporter xunit --reporter-options output=dist/test_output.xml. Notice the dist file.

Then checkout d03d8fdd7e5467466f35c23f2f3936320e3f3f3e (mocha 7 commit), (remove old dist file), yarn install and run the command again. Notice it printing to console instead of file.

After reverting mocha 7 and adding a regression test, this is now the failing PR if it helps. https://github.com/CrowdStrike/faltest/pull/219

@kellyselden This has been a bug in v6. The Mocha constructor was expecting opts.reporterOption, but processed reporterOptions. see API docs.

Thank you @juergba. I fixed it by changing to reporterOption. I missed that in the changelog. Sorry @brettz9 for unintentionally hijacking your issue.

@brettz9 reporter-option in .mocharc.js is an array. Please try:

`reporter-option`: [
    'configFile=mocha-multi-reporters.json'
]

Excellent, thank you, @juergba, I see this is working now. However, for require, it still does not work:

  require: [
    'esm', 'chai/register-expect', 'test/bootstrap/node.js'
  ]

Hmmm... Ok, I was left with:

_mocha --require esm --require chai/register-expect --require test/bootstrap/node.js

which after removing the requires, I just had:

_mocha

...which was complaining about an unexpected idenifier, but it is ok with "mocha".

So I guess this is resolved as far as I am concerned (though I'd be interesting in knowing why _mocha is different).

mocha checks for Node flags and spawns a child-process if found any. --require esm is handled as Node flag, the rest of the require's are passed to Mocha.

_mocha is for backwards compability only and does not care for Node flags. It was used also for debugging, in times when debugging a child-process was difficult.

I would like to close this PR.

Was this page helpful?
0 / 5 - 0 ratings