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: Cannot read property 'passes' of undefined #269

Closed
carrieyummy opened this issue Feb 22, 2019 · 9 comments
Closed

TypeError: Cannot read property 'passes' of undefined #269

carrieyummy opened this issue Feb 22, 2019 · 9 comments

Comments

@carrieyummy
Copy link

I've installed the latest mocha, mochawesome, cypress etc,but when i run 'npm test',No test report was generated.
package.json:

{
  "name": "cypresstest",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "cypress": "^3.1.5"
  },
  "devDependencies": {
    "mocha": "^6.0.1",
    "mochawesome": "^3.1.1",
    "mochawesome-merge": "^1.0.5",
    "mochawesome-report-generator": "^3.1.5"
  },
  "scripts": {
    "cypress:open": "cypress open",
    "test": "cypress run --reporter mochawesome"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

exception:

TypeError: Cannot read property 'passes' of undefined
    at Spec.Base.epilogue (/Users/tianyawei/Applications/CypressTest/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 (/Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/Resources/app/packages/server/lib/reporter.js:239:55)
    at Object.server.startWebsockets.onMocha (/Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/Resources/app/packages/server/lib/project.js:296:22)
    at Socket.<anonymous> (/Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/Resources/app/packages/server/lib/socket.js:237:36)
    at emitTwo (events.js:125:13)
    at Socket.emit (events.js:213:7)
    at /Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/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 (/Users/tianyawei/Applications/CypressTest/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 (/Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/Resources/app/packages/server/lib/reporter.js:239:55)
    at Object.server.startWebsockets.onMocha (/Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/Resources/app/packages/server/lib/project.js:296:22)
    at Socket.<anonymous> (/Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/Resources/app/packages/server/lib/socket.js:237:36)
    at emitTwo (events.js:125:13)
    at Socket.emit (events.js:213:7)
    at /Users/tianyawei/Library/Caches/Cypress/3.1.5/Cypress.app/Contents/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)

npm ERR! Test failed.  See above for more details.
tianyaweideMacBook-Pro:CypressTest tianyawei$ 
@adamgruber
Copy link
Owner

At first glance this seems to be related to changes that were made in mocha 6.0.0. Specifically as part of mochajs/mocha#3458. The reporter continues to work as expected when used directly with mocha, however when used with Cypress it is throwing errors.

I wrote mochawesome to work with mocha and unfortunately Cypress has been known to have issues. I will try to look into this further but cannot guarantee when or if a fix will be released. A temporary workaround would be to install a version of mocha <6.

@carrieyummy
Copy link
Author

@adamgruber Thank you~

@YOU54F
Copy link

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

@YOU54F
Copy link

YOU54F commented Jun 4, 2019

Updated instructions

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

@amitguptagwl
Copy link

any update?

@emmonspired
Copy link

Any update?

jasonk added a commit to jasonk/mochawesome that referenced this issue Aug 28, 2019
Mocha 6 introduced a new "stats-collector" that reporters have to
manually instantiate in order to get stats.  If running under Mocha
6 reporters that haven't done this will throw exceptions like `Cannot
read property 'passes' of undefined` or `Cannot read property 'failures'
of undefined`.

fixes adamgruber#269
fixes adamgruber#282
jasonk added a commit to jasonk/mochawesome that referenced this issue Aug 28, 2019
Mocha 6 introduced a new "stats-collector" that reporters have to
manually instantiate in order to get stats.  If running under Mocha
6 reporters that haven't done this will throw exceptions like `Cannot
read property 'passes' of undefined` or `Cannot read property 'failures'
of undefined`.

fixes adamgruber#269
fixes adamgruber#282
@jasonk jasonk mentioned this issue Aug 28, 2019
@MrBokeh
Copy link

MrBokeh commented Feb 2, 2020

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

@stevenvanryckeghem
Copy link

Any news on this matter? Meanwhile Cypress 4.0 has been released and they now require Mocha 7.0.1 (https://docs.cypress.io/guides/references/migration-guide.html#Migrating-to-Cypress-4-0)

@adamgruber
Copy link
Owner

Just released v5.0.0 to address this. Specifies mocha 7+ as a peer dependency.

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

Successfully merging a pull request may close this issue.

7 participants