Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

junit-reporter does not support mocha 6 #78

Closed
IdanAdar opened this issue Feb 25, 2019 · 12 comments
Closed

junit-reporter does not support mocha 6 #78

IdanAdar opened this issue Feb 25, 2019 · 12 comments

Comments

@IdanAdar
Copy link

Whenever attempting to use this reporter with the latest mocha, mocha fails. With previous releases of mocha, it did not.

@DavidBurela
Copy link

Experiencing the same issue. Pinning to mocha 5.2.0 works, but using 6.0.x results in a failure

@mega-narwhal
Copy link

Same problem here

$ codeceptjs run --reporter mocha-junit-reporter
TypeError: Cannot read property 'failures' of undefined
TypeError: Cannot read property 'failures' of undefined
    at MochaJUnitReporter.getXml (/Users/dmitriy.kurochkin/project/node_modules/mocha-junit-reporter/index.js:291:23)
    at MochaJUnitReporter.flush (/Users/dmitriy.kurochkin/project/node_modules/mocha-junit-reporter/index.js:238:18)
    at MochaJUnitReporter.<anonymous> (/Users/dmitriy.kurochkin/project/node_modules/mocha-junit-reporter/index.js:144:10)
    at Runner.emit (events.js:202:15)
    at /Users/dmitriy.kurochkin/project/node_modules/codeceptjs/node_modules/mocha/lib/runner.js:829:12
    at /Users/dmitriy.kurochkin/project/node_modules/codeceptjs/node_modules/mocha/lib/runner.js:677:9
    at next (/Users/dmitriy.kurochkin/project/node_modules/codeceptjs/node_modules/mocha/lib/runner.js:290:14)
    at Immediate.<anonymous> (/Users/dmitriy.kurochkin/project/node_modules/codeceptjs/node_modules/mocha/lib/runner.js:334:5)
    at processImmediate (timers.js:637:19)
error Command failed with exit code 1.

@YOU54F
Copy link
Contributor

YOU54F commented Mar 17, 2019

Hi,

I have 2 PR's tracking this upgrade to mocha 6, I use cypress & mochawesome for reporting.

They have circleci runs associated with them, in case anyone wants to track the change as the other dependancies update. I haven't had a chance to look into this yet in much detail

YOU54F/template-cypress-docker-typescript#15
https://github.com/YOU54F/cypressio-docker/pull/12

@YOU54F
Copy link
Contributor

YOU54F commented Mar 27, 2019

I've now updated, tested and released updated modules that fix this with mocha 6, but also retains backwards compatibility with mocha 5 and earlier versions. (tested with mocha 6.0.0 / latest and 5.2.0)

https://www.npmjs.com/package/cypress-multi-reporters
https://www.npmjs.com/package/mocha-junit-reporters

Example against Mocha 5
Example against Mocha 6

the changes required are minimal

npm i mocha-junit-reporters
npm i cypress-multi-reporters

in reporterOpts.json

{
  "reporterEnabled": "mocha-junit-reporters, mochawesome",
  "mochaJunitReportersReporterOptions": {
    "mochaFile": "cypress/reports/junit/test_results[hash].xml",
    "toConsole": false
  },
  "mochawesomeReporterOptions": {
    "reportDir": "cypress/reports/mocha",
    "quiet": true,
    "overwrite": false,
    "html": false,
    "json": true
  }
} 

in cypress.json

{
  ...
  "reporter": "cypress-multi-reporters",
  "reporterOptions": {
    "configFile": "reporterOpts.json"
  }

See https://github.com/YOU54F/cypress-docker-typescript/pull/22/files for this fix applied, I have teste

Hopefully the PR's will be merged in the source repo's soon but for now, enjoy

@shavo007
Copy link

shavo007 commented Apr 1, 2019

This config worked for me
.mocharc.json

{
  "diff": true,
  "extension": ["js"],
  "package": "./package.json",
  "reporter": "mocha-junit-reporter",
  "slow": 75,
  "timeout": 2000,
  "ui": "bdd",
  "reporter-option": ["mochaFile=./reports/junit.xml"],
  "require": ["@babel/register", "test/mochaSetup", "dotenv/config"],
  "spec": "./src/**/*.spec.js"
}

@canterberry
Copy link

💡 Mocha 6 now natively supports XUnit-style reports via the xunit reporter. Rejoice!

# Before
mocha ... --reporter mocha-junit-reporter --reporter-options mochaFile=/path/to/output.xml

# After
mocha ... --reporter xunit --reporter-options output=/path/to/output.xml

This got me up and running when I ran into the snag other folks have mentioned above when using the current latest version of Mocha.

@YOU54F
Copy link
Contributor

YOU54F commented Jun 6, 2019

@canterberry great news :)

btw I have updated my comment above, with a released npm packages that will support mocha 6 and below. I couldn't wait for the PR to get merged and lots of people were after mocha 6 support

@YOU54F
Copy link
Contributor

YOU54F commented Jun 7, 2019

@IdanAdar

This should be resolved now in this repo! 🙌

The fix for mocha-junit-reporter has now been merged and is available in the newly released v1.23.0

https://github.com/michaelleeallen/mocha-junit-reporter/releases/tag/v1.23.0

@IdanAdar
Copy link
Author

Has anyone got this to work (with mocha: ^6.0.0)?

package.json

"test": "jenkins-mocha --recursive --reporter mocha-multi-reporters --reporter-options configFile=config/mocha-config.json --exit",

mocha-config.json

{
   "reporterEnabled": "list,mocha-junit-reporter",
    "mochaJunitReporterReporterOptions": {
	"mochaFile": "testResults/results.xml"
    }
}

This combination fails with (while using v1.23.0 of mocha-junit-reporter):

[2019-06-10T02:58:57.631Z] [FATAL] appBase - Unhandled exception happened! Error message: Cannot read property 'passes' of undefined
{}
TypeError: Cannot read property 'passes' of undefined
    at List.Base.epilogue (/Users/iadar/Documents/***/node_modules/mocha/lib/reporters/base.js:319:26)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at Runner.emit (events.js:208:7)
    at /Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:829:12
    at /Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:677:9
    at next (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:290:14)
    at Immediate._onImmediate (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:334:5)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5) - instanceId: SystemId
  1) *** - *** "after each" hook

If I replace mocha-junit-reporter in the JSON file with the suggested xunit, it fails with the same as above and then also this:

/Users/iadar/Documents/Bluemix/GitHub/certificate-management-service-api/node_modules/mocha/lib/reporters/xunit.js:94
          tests: stats.tests,
                       ^

TypeError: Cannot read property 'tests' of undefined
    at Runner.<anonymous> (/Users/iadar/***/node_modules/mocha/lib/reporters/xunit.js:94:24)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at Runner.emit (events.js:208:7)
    at /Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:829:12
    at done (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:666:7)
    at next (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:633:16)
    at done (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:666:7)
    at next (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:637:14)
    at done (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:666:7)
    at next (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:637:14)
    at Runner.hookErr (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:482:7)
    at Runner.uncaught (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:747:19)
    at process.uncaught (/Users/iadar/***/node_modules/jenkins-mocha/node_modules/mocha/lib/runner.js:821:10)
    at emitOne (events.js:121:20)
    at process.emit (events.js:211:7)
    at processEmit [as emit] (/Users/iadar/***/node_modules/nyc/node_modules/signal-exit/index.js:155:32)
    at process._fatalException (bootstrap_node.js:391:26)

@YOU54F
Copy link
Contributor

YOU54F commented Jun 10, 2019

Mocha-multi-reporters still doesn’t have the fix in...

Try using mocha-junit-reporter directly or try cypress-multi-reporters, as per my instructions as that also contains the fix

@IdanAdar
Copy link
Author

That combination worked.

@YOU54F
Copy link
Contributor

YOU54F commented Jun 10, 2019

@IdanAdar cool, do you want to close this issue now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants