Cypress: TypeError when using custom reporter

Created on 20 Feb 2019  Β·  34Comments  Β·  Source: cypress-io/cypress

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"
reporters πŸ“„

Most helpful comment

@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

All 34 comments

  • 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
...

Yeah, I haven't thoroughly looked through Mocha 6's changelog to see if they've made a breaking change regarding this or if this is a bug on their part. Or maybe mochaawesome needs to update their code to handle Mocha 6. πŸ˜•

got this error too with this following details

{
  "name": "coba-bos-cypress",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "cy:run": "node_modules/cypress/bin/cypress run",
    "cleanup": "rm -fr mochawesome-report",
    "merge_reports": "mochawesome-merge --reportDir mochawesome-report > mochawesome-report/output.json",
    "generate_mochawesome_report": "marge mochawesome-report/output.json",
    "e2e_mochawesome": "npm run cleanup && cypress run && npm run merge_reports && npm run generate_mochawesome_report"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cypress": "^3.1.5"
  },
  "devDependencies": {
    "mocha": "^6.0.2",
    "mochawesome": "^3.1.1",
    "mochawesome-merge": "^1.0.7",
    "mochawesome-report-generator": "^3.1.5"
  }
}

We use the mocha-junit-reporter with mocha-multi-reporters but not the mochawesome one, so this seems a problem in a BC break in mocha 6 itself. Will downgrade to 5.2 for the moment.

https://github.com/michaelleeallen/mocha-junit-reporter/issues/78

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

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

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",

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
...

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

This issue still happens in latest version 3.3.0 as well !

@executeautomation It's not an issue in Cypress, it was a breaking change in Mocha, I fixed it and have just performed a run with Mocha 6>, Cypress 3.3.1 and my forks npm i mocha-junit-reporters & npm i cypress-multi-reporters and it passed successfully - https://circleci.com/gh/YOU54F/cypress-docker-typescript/180

 "dependencies": {
    "cypress": "^3.3.1",
    "mocha": "^6.1.4",
    "mocha-junit-reporters": "^1.23.0",
    "cypress-multi-reporters": "^1.1.9",
    "mochawesome": "^3.1.1",
    "mochawesome-merge": "^1.0.7",
    "mochawesome-report-generator": "^3.1.5",
    "cypress-slack-reporter": "0.2.6",
  }

Wow thats cool @YOU54F , great to fix the issue and hopefully it will be fixed in cypress-multi-reporters and mocha-junit-reporters as well.

Thanks,
Karthik KK

Closing since this is an external issue.

@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?

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

@jennifer-shehane sorry for the misunderstanding. I tried to highlight @YOU54F's name, it was a question to him on behalf of the cypress community using moche multi reporters πŸ€“

I think he renamed the package from mocha-multi-reporters to cypress-multi-reporters. Our e2e cypress tests started failing this morning because the repo could not be found. I mention it here so it can hopefully help other people using cypress and multi reporters in their dev flow.

@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

@YOU54F awesome, great work and fast response πŸ”₯ We just confirmed that it works. Thanks for making the world a better place πŸ™Œ

@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

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 πŸ™Œ

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 :)

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

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

@YOU54F Thanks alot ! your solution worked !

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

Great to see this !

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)

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:\Usersadmin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\index.js:78:66)
at Array.map ()
at collection (C:\Usersadmin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:3:44)
at fns.reduce (C:\Usersadmin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:121)
at Array.reduce ()
at value (C:\Usersadmin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:101)
at fns.reduce (C:\Usersadmin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:121)
at Array.reduce ()
at value (C:\Usersadmin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:101)

not an issue with cypress - raise it against the correct repo

https://github.com/Antontelesh/mochawesome-merge

also check that you actually have a mochawesome report in your directory mochawesome-report and that it is called mochawesome*.json

Working properly with this combination:

"cypress": "^3.5.0",
"mocha": "^6.2.2",
"mochawesome": "^4.1.0"
`

Mocha 5.2.0 won't have this issue, only the latest Mocha 6.x and 7.x are still having this same issue...

"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.18.0",
"mocha-multi-reporters": "^1.1.7",
"mochawesome": "^4.0.1",
"mochawesome-merge": "^2.0.1",
"mochawesome-report-generator": "^4.0.1"

am getting below error,
ERROR: Failed to merge reports
TypeError: Cannot read property 'filter' of undefined
at report (/Users/admin/checker/node_modules/mochawesome-merge/lib/index.js:44:18)
at Array.map ()
at items (/Users/admin/checker/node_modules/mochawesome-merge/lib/utils.js:3:46)
at merge (/Users/admin/checker/node_modules/mochawesome-merge/lib/index.js:58:18)

reopening since this is a problem we can potentially fix, we shouldn't require users to install a specific mocha version

The code for this is done in cypress-io/cypress#6951, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 4.5.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.5.0, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings