Cypress: TypeError: Cannot read property 'passes' of undefined

Created on 24 May 2019  Β·  17Comments  Β·  Source: cypress-io/cypress

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

duplicate

Most helpful comment

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

All 17 comments

This does look like exactly like a duplicate of this issue πŸ€” https://github.com/cypress-io/cypress/issues/3537

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

Same with me

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

@YOU54F Thanks. PR for cypress can be found here: https://github.com/cypress-io/cypress/pull/4417

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?

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

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

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

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" "$@"

$

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

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

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

https://github.com/YOU54F/cypress-docker-typescript/pull/22

The master branch is running mocha 6+ and cypress

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

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

I'm using Mocha 7.0.1 and having this issue.

duplicate of https://github.com/cypress-io/cypress/issues/3537, which has been reopened

Was this page helpful?
0 / 5 - 0 ratings