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 #4304

Closed
tijnster opened this issue May 24, 2019 · 17 comments
Closed

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

tijnster opened this issue May 24, 2019 · 17 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@tijnster
Copy link

Current behavior:

Mochawesome does not work, getting error when I am running my tests. I have tried downgrading to V5.2(As I have seen this could solve the problem in other threads). But it does still not work.

image

image

image

image

Desired behavior:

Generated Html reports from running the tests.

Steps to reproduce: (app code and test code)

I have followed everything from the Cypress docs which lead me to this link:
http://antontelesh.github.io/testing/2019/02/04/mochawesome-merge.html

Versions

Cypress V 3.3.0

@jennifer-shehane
Copy link
Member

This does look like exactly like a duplicate of this issue 🤔 #3537

@tijnster
Copy link
Author

@jennifer-shehane I read that post and tried downgrading, but still does not work for me..

@johnFProdigy
Copy link

Same with me

@YOU54F
Copy link
Contributor

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

@jennifer-shehane as cypress uses this internally, you may wish to bump the version shipped with cypress to incorporate this change

@jennifer-shehane
Copy link
Member

@YOU54F Thanks. PR for cypress can be found here: #4417

@dialex
Copy link

dialex commented Aug 19, 2019

Well that issue is still happening for me and I'm using Cypress 3.4.1

This is my cypress.json

"reporter": "mochawesome",
  "reporterOptions": {
    "reportDir": "artifacts/mochawesome-sources",
    "quiet": true,
    "overwrite": false,
    "html": false,
    "json": true
  }

It was working just fine until I upgraded dependencies this morning. These were the latest versions what worked:

"mocha": "5.2.0",
"mochawesome": "^4.0.1",
"mochawesome-merge": "^2.0.1",
"mochawesome-report-generator": "^4.0.1"

Found it, the breaking change happened somewhere between mocha 5.2.0 -> 6.2.0.
So... is this a mocha or a cypress issue?

@Optimus50
Copy link

Optimus50 commented Aug 20, 2019

I am having the same problem here, using mocha 6.2.0,
but downgrading mocha to 5.2.0 seem to work,
"mocha": "5.2.0",
"mocha-junit-reporter": "1.23.1",
"mocha-multi-reporters": "1.1.7",
"mochawesome": "4.1.0",
"mochawesome-merge": "2.0.1",
"mochawesome-report-generator": "4.0.1",

@zbigniewkalinowski
Copy link

The same situation and downgrade to 5.2.0 didn't help...

@HareemManzoor
Copy link

@zbigniewkalinowski try using these dependencies. I had same issue but resolved it with these:
"devDependencies": {
"cypress": "^3.4.1",
"cypress-page-object": "^1.0.0",
"mochawesome": "^4.1.0",
"mochawesome-merge": "^2.0.1",
"mochawesome-report-generator": "^4.0.1"
},
"dependencies": {
"mocha": "^5.2.0"
}

@rubenreyes2000
Copy link

It looks like this is still an issue. Installing Cypress from scratch and adding mocha, mochawesome, mochawesome-merge, and mochawesome-report-generator, and configuring cypress.json leads to the same error, see below:

$ mkdir cypresstest

$ cd cypresstest/

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (cypresstest)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to C:\Users\ruben\cypresstest\package.json:

{
  "name": "cypresstest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes)

$ npm install --save-dev cypress mocha mochawesome mochawesome-merge mochawesome-report-generator

> [email protected] postinstall C:\Users\ruben\cypresstest\node_modules\cypress
> node index.js --exec install


Cypress 3.4.1 is installed in C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
added 306 packages from 634 contributors and audited 767 packages in 28.277s
found 0 vulnerabilities


$ ./node_modules/.bin/cypress open


$ cat cypress.json
{
  "reporter": "mochawesome",       
  "reporterOptions": {
    "reportDir": "cypress/results",
    "overwrite": false,
    "html": false,
    "json": true
  }
}

$ ./node_modules/.bin/cypress run


====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.4.1                                                                              │
  │ Browser:    Electron 61 (headless)                                                             │
  │ Specs:      19 found (examples\actions.spec.js, examples\aliasing.spec.js, examples\assertion… │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running: examples\actions.spec.js...                                                    (1 of 19)


  Actions
    √ .type() - type into a DOM element (4524ms)
    √ .focus() - focus on a DOM element (516ms)
    √ .blur() - blur off a DOM element (577ms)
    √ .clear() - clears an input or textarea element (699ms)
    √ .submit() - submit a form (703ms)
    √ .click() - click on a DOM element (2347ms)
    √ .dblclick() - double click on a DOM element (478ms)
    √ .check() - check a checkbox or radio element (1427ms)
    √ .uncheck() - uncheck a checkbox element (1149ms)
    √ .select() - select an option in a <select> element (1256ms)
    √ .scrollIntoView() - scroll an element into view (479ms)
    √ .trigger() - trigger an event on a DOM element (276ms)
    √ cy.scrollTo() - scroll the window or element to a position (2291ms)


TypeError: Cannot read property 'passes' of undefined
    at Spec.Base.epilogue (C:\Users\ruben\cypresstest\node_modules\mocha\lib\reporters\base.js:324:30)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:121:20)
    at Runner.emit (events.js:211:7)
    at Reporter.emit (C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\server\lib\reporter.js:237:55)
    at Object.server.startWebsockets.onMocha (C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\server\lib\project.js:300:22)
    at Socket.<anonymous> (C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\server\lib\socket.js:236:36)
    at emitTwo (events.js:126:13)
    at Socket.emit (events.js:214:7)
    at C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\socket\node_modules\socket.io\lib\socket.js:528: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 (C:\Users\ruben\cypresstest\node_modules\mocha\lib\reporters\base.js:324:30)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:121:20)
    at Runner.emit (events.js:211:7)
    at Reporter.emit (C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\server\lib\reporter.js:237:55)
    at Object.server.startWebsockets.onMocha (C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\server\lib\project.js:300:22)
    at Socket.<anonymous> (C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\server\lib\socket.js:236:36)
    at emitTwo (events.js:126:13)
    at Socket.emit (events.js:214:7)
    at C:\Users\ruben\AppData\Local\Cypress\Cache\3.4.1\Cypress\resources\app\packages\socket\node_modules\socket.io\lib\socket.js:528:12
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

./node_modules/.bin/cypress: line 14:  4000 Segmentation fault      node "$basedir/../cypress/bin/cypress" "$@"

$

@YOU54F
Copy link
Contributor

YOU54F commented Oct 15, 2019

Mocha 6+ requires a stat collector to be instantiated which cypress doesn’t do as it use an older version of mocha internally and doesn’t use the version specified in a projects package.json.

If you use cypress-multi-reporters, it will allow you to use any mocha version, and will instantiate the stats collector allowing you to use mocha 6+ in your project

@rubenreyes2000
Copy link

@YOU54F : thank you for your quick answer. Can you provide a little more guidance, please?

I installed cypress-multi-reporters with npm install --save-dev cypress-multi-reporters but I get the same error when executing cypress run.

Any suggestions?

@YOU54F
Copy link
Contributor

YOU54F commented Oct 15, 2019

You want to setup your reporter in cypress json file as cypress-multi-reporters and point to a reporterOpts json file which contains the reporters you want to run.

See one of my projects for an example

YOU54F/template-cypress-docker-typescript#22

The master branch is running mocha 6+ and cypress

@rubenreyes2000
Copy link

rubenreyes2000 commented Oct 15, 2019

Awesome!!! Thank you @YOU54F!

For the benefit of others reading this, here is a summary of what I did. What I am trying to do is generate the log/results of the tests in a format I can distribute to humans.

package.json

{
  "name": "cypresstest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^3.4.1",
    "cypress-multi-reporters": "^1.2.1",
    "mocha": "^6.2.1",
    "mochawesome": "^4.1.0",
    "mochawesome-merge": "^2.0.1",
    "mochawesome-report-generator": "^4.0.1"
  },
  "dependencies": {}
}

cypress.json

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

reporter.json

{
  "reporterEnabled": "mochawesome",
  "mochawesomeReporterOptions": {
    "reportDir": "cypress/reports/mochawesome",
    "overwrite": false,
    "html": false,
    "json": true
  }
}

Then I can execute my tests with ./node_modules/.bin/cypress run and this produces several json files in cypress/reports/mochawesome (one per spec). I merge those files with

$ npx mochawesome-merge --reportDir cypress/reports/mochawesome/ > cypress/reports/mochawesome.json

And finally I produce the HTML report with

$ npx mochawesome-report-generator --reportDir cypress/reports/ --cdn true --charts true cypress/reports/mochawesome.json

Voila!!!

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

@AlexA-1976
Copy link

I'm using Mocha 7.0.1 and having this issue.

@kuceb kuceb added the type: duplicate This issue or pull request already exists label Apr 6, 2020
@kuceb
Copy link
Contributor

kuceb commented Apr 6, 2020

duplicate of #3537, which has been reopened

@cypress-io cypress-io locked and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests