cypress: TypeError when using custom reporter

Current behavior:

After running cypress with --reporter mochawesome I’m getting exception:

TypeError: Cannot read property 'passes' of undefined
    at Spec.Base.epilogue (<path>\node_modules\mocha\lib\reporters\base.js:318:25)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:120:20)
    at Runner.emit (events.js:210:7)
    at Reporter.emit (<path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\server\lib\reporter.js:239:55)
    at Object.server.startWebsockets.onMocha (<path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\server\lib\project.js:296:22)
    at Socket.<anonymous> (<path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\server\lib\socket.js:237:36)
    at emitTwo (events.js:125:13)
    at Socket.emit (events.js:213:7)
    at <path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\socket\node_modules\socket.io\lib\socket.js:503:12
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

TypeError: Cannot read property 'passes' of undefined
    at Spec.Base.epilogue (<path>\node_modules\mocha\lib\reporters\base.js:318:25)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:120:20)
    at Runner.emit (events.js:210:7)
    at Reporter.emit (<path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\server\lib\reporter.js:239:55)
    at Object.server.startWebsockets.onMocha (<path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\server\lib\project.js:296:22)
    at Socket.<anonymous> (<path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\server\lib\socket.js:237:36)
    at emitTwo (events.js:125:13)
    at Socket.emit (events.js:213:7)
    at <path>\AppData\Local\Cypress\Cache\3.1.5\Cypress\resources\app\packages\socket\node_modules\socket.io\lib\socket.js:503:12
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Desired behavior:

Report is generated

Steps to reproduce: (app code and test code)

Set up according to documentation

Versions

"mocha": "^6.0.0",
"mochawesome": "^3.1.1",

"cypress": "^3.1.5"

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 22
  • Comments: 34 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@dauledk - no worries chap, some instructions I wrote that may help others,

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.

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

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

  • Can you provide the exact command you are running to run Cypress, including all arguments?

Also, I notice that mocha 6.0.0 just released 2 days ago. Can you try installing "mocha": "5.2.0" to see if that works? I’d like to narrow down whether this is an issue with their newest release.

Thank you for quick answer. With mocha 5.2.0 it works fine, thank you. I checked mocha-junit-reporter and the error is similar:

TypeError: Cannot read property 'failures' of undefined
...

Just fixed this and proposed the following 2 PR’s

https://github.com/stanleyhlng/mocha-multi-reporters/pull/58 https://github.com/michaelleeallen/mocha-junit-reporter/pull/80

My branch tracking the changes, with failing builds with mocha 6 pre and post fix is here

https://github.com/YOU54F/cypressio-docker-typescript/pull/15/files

If you do want to move up to mocha 6, you can pull my forked branch in the interim, whilst we wait for the maintainers of the source repo to review/merge/release the PR

    "mocha": "^6.0.0",
    "mocha-junit-reporter": "YOU54F/mocha-junit-reporter#master",
    "mocha-multi-reporters": "YOU54F/mocha-multi-reporters#master",

@YOU54F we were using this setup:

 "mocha": "^6.0.0",
 "mocha-junit-reporter": "YOU54F/mocha-junit-reporter#master",
 "mocha-multi-reporters": "YOU54F/mocha-multi-reporters#master",

But your repository mocha-multi-reporters seems to have changed name or removed?

Hey chap

Apologies, I deleted the fork and released it as https://github.com/YOU54F/cypress-multi-reporters as the main repository isn’t being maintained

They are both published to npm with updated dependencies

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

My 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

@YOU54F Thanks alot ! your solution worked !

Thanks mate, you are humble enough to accept the credit for work you have done!

Thank you @YOU54F, the example you showed works pretty much expected, kudos to your work and thanks for making this happen, I will surely mention you in my course 🙌

Cheers matey, glad to help where I can. I’ve consumed so many peoples projects over time, that I am only standing on the shoulders on giants. It has been a great learning exercise in coding for me as a software tester getting into the world of dev 😃

I am getting the below error while merging the mochawesome report. Command $ npx mochawesome-merge — reportDir mochawesome-report > mochawesome-report/output.json

**ERROR:** Failed to merge reports

TypeError: Cannot read property 'suites' of undefined
    at report (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\index.js:78:66)
    at Array.map (<anonymous>)
    at collection (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:3:44)
    at fns.reduce (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:121)
    at Array.reduce (<anonymous>)
    at value (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:101)
    at fns.reduce (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:121)
    at Array.reduce (<anonymous>)
    at value (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:101)

Also props to the Cypress team for all their hard work and for supporting the OSS community!

Thank you @YOU54F, the example you showed works pretty much expected, kudos to your work and thanks for making this happen, I will surely mention you in my course 🙌

@YOU54F awesome, great work and fast response 🔥 We just confirmed that it works. Thanks for making the world a better place 🙌

mocha-multi-reporters has never been maintained by Cypress. It is under another person’s repository and npm package.

@YOU54F we were using this setup:

 "mocha": "^6.0.0",
 "mocha-junit-reporter": "YOU54F/mocha-junit-reporter#master",
 "mocha-multi-reporters": "YOU54F/mocha-multi-reporters#master",

But your repository mocha-multi-reporters seems to have changed name or removed?