michaelleeallen / mocha-junit-reporter

A JUnit XML reporter for mocha.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mochaFile does not work when defined in mocharc files

mririgoyen opened this issue · comments

This is similar to #107. When the mochaFile option is provided via the .mocharc.js configuration file, it is not respected.

This is the case on the latest, 1.23.3 and Mocha 7.1.0.

reporterOptions: {
  mochaFile: '../reports/contract.xml'
},

A generic test-results.xml file is created every time.

More info, when digging into the reporter's code and adding some console.logs, I logged the options being fed directly into the entry point and this is what I see:

{ diff: true,
  extension: [ 'js', 'cjs', 'mjs' ],
  opts: false,
  package: false,
  reporter: [Function: MochaJUnitReporter],
  slow: '75',
  timeout: '2000',
  ui: 'bdd',
  'watch-ignore': [ 'node_modules', '.git' ],
  R: 'mocha-junit-reporter',
  s: '75',
  t: '2000',
  timeouts: '2000',
  u: 'bdd',
  _: [],
  config: false,
  exit: true,
  'reporterOptions.mochaFile': 'unit.xml',
  watchIgnore: [ 'node_modules', '.git' ],
  spec: [ 'test' ],
  '$0': 'mocha',
  grep: undefined,
  reporterOption: undefined,
  reporterOptions: undefined,
  global: [],
  files:
   [ '/Users/mirigoyen/Git/core/services/source-model-manager/test/api.test.js',
     '/Users/mirigoyen/Git/core/services/source-model-manager/test/dynamo.test.js' ] }

The reporterOption(s) are both undefined, but there is a raw reporterOptions.mochaFile with the correct value from the rc file. Hope that helps.

I've further found that the way the mocha version is being checked is problematic.

I've modified my scripts to output the mocha version it is running before executing the test suite and then adding a console log to where you determine the mocha version and they are very different.

$ mocha --version; mocha
7.1.0
MOCHA VERSION 3.5.3

We are in a monorepo and it looks like the mocha package file you're looking at is not in the same context of where the tests are executed. Perhaps there is another way you can obtain the version of mocha from the actual binary it is going to run as a fix?

Can you provide a minimal reproduction? Build setups are so varied, and monorepos are a newer and less common setup that I wouldn’t have any idea how to begin to investigate this.

@clayreimann @michaelleeallen This is a rather documentation change.

-  reporterOptions: {
-    mochaFile: 'custom-results-file.xml'
-  },
+ reporterOptions: ['mochaFile=custom-results-file.xml']

Related issue: mochajs/mocha#4654