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

TypeError when using mochawesome reporter #3537

Closed
gustawx opened this issue Feb 20, 2019 · 28 comments

Comments

@gustawx
Copy link

@gustawx gustawx commented Feb 20, 2019

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"
@jennifer-shehane

This comment has been minimized.

Copy link
Member

@jennifer-shehane jennifer-shehane commented Feb 20, 2019

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

@gustawx

This comment has been minimized.

Copy link
Author

@gustawx gustawx commented Feb 20, 2019

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
...
@jennifer-shehane

This comment has been minimized.

Copy link
Member

@jennifer-shehane jennifer-shehane commented Feb 20, 2019

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

@isdzulqor

This comment has been minimized.

Copy link

@isdzulqor isdzulqor commented Mar 6, 2019

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"
  }
}
@arendjantetteroo

This comment has been minimized.

Copy link
Contributor

@arendjantetteroo arendjantetteroo commented Mar 11, 2019

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.

michaelleeallen/mocha-junit-reporter#78

@YOU54F

This comment has been minimized.

Copy link

@YOU54F 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/cypress-docker-typescript#15
YOU54F/cypress-docker#12

@YOU54F

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Mar 27, 2019

Just fixed this and proposed the following 2 PR's

stanleyhlng/mocha-multi-reporters#58
michaelleeallen/mocha-junit-reporter#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",
@vidhyaSoundararajan

This comment has been minimized.

Copy link

@vidhyaSoundararajan vidhyaSoundararajan commented Apr 3, 2019

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

This comment has been minimized.

Copy link

@YOU54F YOU54F commented May 8, 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

Thirosue added a commit to Thirosue/sample-vuejs-front that referenced this issue May 13, 2019
@executeautomation

This comment has been minimized.

Copy link

@executeautomation executeautomation commented May 25, 2019

This issue still happens in latest version 3.3.0 as well !

@YOU54F

This comment has been minimized.

Copy link

@YOU54F YOU54F commented May 25, 2019

@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",
  }
@executeautomation

This comment has been minimized.

Copy link

@executeautomation executeautomation commented May 26, 2019

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

@jennifer-shehane

This comment has been minimized.

Copy link
Member

@jennifer-shehane jennifer-shehane commented May 30, 2019

Closing since this is an external issue.

@dauledk

This comment has been minimized.

Copy link

@dauledk dauledk commented Jun 3, 2019

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

@jennifer-shehane

This comment has been minimized.

Copy link
Member

@jennifer-shehane jennifer-shehane commented Jun 3, 2019

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

@dauledk

This comment has been minimized.

Copy link

@dauledk dauledk commented Jun 3, 2019

@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

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Jun 3, 2019

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

This comment has been minimized.

Copy link

@dauledk dauledk commented Jun 3, 2019

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

@YOU54F

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Jun 3, 2019

@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

@executeautomation

This comment has been minimized.

Copy link

@executeautomation executeautomation commented Jun 4, 2019

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

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Jun 4, 2019

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

@YOU54F

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Jun 4, 2019

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

@executeautomation

This comment has been minimized.

Copy link

@executeautomation executeautomation commented Jun 4, 2019

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

@nanshummt

This comment has been minimized.

Copy link

@nanshummt nanshummt commented Jun 4, 2019

@YOU54F Thanks alot ! your solution worked !

@YOU54F

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Jun 7, 2019

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

@executeautomation

This comment has been minimized.

Copy link

@executeautomation executeautomation commented Jun 10, 2019

Great to see this !

@JayeshRGujar

This comment has been minimized.

Copy link

@JayeshRGujar JayeshRGujar commented Jun 28, 2019

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 ()
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 ()
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 ()
at value (C:\Users\admin\Documents\ipapps-cypress\node_modules\mochawesome-merge\lib\utils.js:1:101)

@YOU54F

This comment has been minimized.

Copy link

@YOU54F YOU54F commented Jun 28, 2019

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 ()
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 ()
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 ()
at value (C:\Users\admin\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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
10 participants
You can’t perform that action at this time.