cypress: Couldn't determine Mocha version

Current behavior

Couldn't determine Mocha version

According to documentation: https://docs.cypress.io/guides/references/bundled-tools.html#Mocha mocha should be bundled. There was a similar issue before: https://github.com/cypress-io/cypress/issues/4602

More details

Here is my dependency list

    "@types/lodash": "4.14.165",
    "@types/mongodb": "3.5.34",
    "@types/numeral": "0.0.28",
    "cypress": "6.0.1",
    "cypress-file-upload": "4.1.1",
    "cypress-multi-reporters": "1.4.0",
    "lodash": "4.17.20",
    "mocha-junit-reporter": "2.0.0",
    "moment": "2.29.1",
    "moment-business-days-diff": "1.0.2",
    "mongodb": "3.6.1",
    "numeral": "2.0.6",
    "tslint": "6.1.3",
    "tslint-consistent-codestyle": "^1.16.0",
    "tslint-plugin-cypress": "^1.0.4",
    "typescript": "4.1.2"

To fix this issue I just installed mocha "mocha": "8.2.1" but if it’s bundled it should be required. In lock file I don’t see mocha, see below:

"cypress": {
      "version": "6.0.1",
      "resolved": "https://registry.npmjs.org/cypress/-/cypress-6.0.1.tgz",
      "integrity": "sha512-3xtQZ0YM65soLgKQUgn2wg2IbWsM6A2yBg6L4RF31mZHr5LNKdO2/9sgiwxEVMKu2C2m6+IQ75zHP41kZP5rPg==",
      "dev": true,
      "requires": {
        "@cypress/listr-verbose-renderer": "^0.4.1",
        "@cypress/request": "^2.88.5",
        "@cypress/xvfb": "^1.2.4",
        "@types/sinonjs__fake-timers": "^6.0.1",
        "@types/sizzle": "^2.3.2",
        "arch": "^2.1.2",
        "blob-util": "2.0.2",
        "bluebird": "^3.7.2",
        "cachedir": "^2.3.0",
        "chalk": "^4.1.0",
        "check-more-types": "^2.24.0",
        "cli-table3": "~0.6.0",
        "commander": "^5.1.0",
        "common-tags": "^1.8.0",
        "debug": "^4.1.1",
        "eventemitter2": "^6.4.2",
        "execa": "^4.0.2",
        "executable": "^4.1.1",
        "extract-zip": "^1.7.0",
        "fs-extra": "^9.0.1",
        "getos": "^3.2.1",
        "is-ci": "^2.0.0",
        "is-installed-globally": "^0.3.2",
        "lazy-ass": "^1.6.0",
        "listr": "^0.14.3",
        "lodash": "^4.17.19",
        "log-symbols": "^4.0.0",
        "minimist": "^1.2.5",
        "moment": "^2.27.0",
        "ospath": "^1.2.2",
        "pretty-bytes": "^5.4.1",
        "ramda": "~0.26.1",
        "request-progress": "^3.0.0",
        "supports-color": "^7.2.0",
        "tmp": "~0.2.1",
        "untildify": "^4.0.0",
        "url": "^0.11.0",
        "yauzl": "^2.10.0"
      }
    },

Versions

6.0.0, 6.0.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

@wojtek1150 Are you working in a monorepo maybe? I only ask cause I am (with yarn workspaces), and I’m running into the same issue. My current theory is that my issue something to do with…

  1. running cypress within a subfolder instead of the project-root. For me, this subfolder has its own package.json and node_modules, in addition to the project root’s at ../node_modules and ../package.json,
  2. and cypress (and deps) being hoisted to the project-root ../node_modules.

I haven’t looked at the patched code @sandra-ouadghiri shared, but if the mocha-junit-reporter is using npm/npx to resolve the mocha version then I’m guessing that the reporter can’t find mocha at all: it’s looking in the wrong places with tools that don’t know how to find hoisted workspace packages.

I’ll post a followup with my environment+project details when I’ve got time, probably tomorrow. Or a solution, if I find one for myself. Going to work on this a little tonight.

The problem is we ship mocha as part of the Cypress App binary, which is not installed in node_modules. That only contains the CLI tool, which launches the Cypress app (which includes all the required modules for Cypress, like mocha).

The mocha-junit-reporter tries to do require('mocha') - which looks at your project’s node_modules - which does not contain mocha. It logs a warning - that is here: https://github.com/michaelleeallen/mocha-junit-reporter/blob/4b17772f8da33d580fafa4d124e5c11142a70c1f/index.js#L32.

There isn’t anything we can reasonable do about this warning in the Cypress code base - other than add specific code to silence a specific warning from a third party module, which I don’t think makes much sense.

The warning shouldn’t prevent the reporter from working. The only way to silence this warning when using this reporter would be a PR to the mocha-junit-reporter repository either removing the warning, or adding an option to silence it.

I am going to close this, since there isn’t any actionable work for us to do in Cypress regarding this warning.

@justinmorrow > Indeed, it’s a monorepo, with cypress being under a dedicated folder. So (root/)micro-service-A/package.json and (root/)test-folder/package.json (including the cypress dependencies and the rest).

I also have this issue A mono repo with Cypress on a sub folder, but one package.json under the root

"devDependencies": {
    "cypress": "^8.3.1",
    "junit-report-merger": "^3.0.2",
    "mocha-junit-reporter": "^2.0.0",
    "typescript": "^4.4.2"
  },

cypress.json:

{
    "reporter": "mocha-junit-reporter",
    "reporterOptions": {
        "configFile" : "reporter-config.json"
        },
}

reporter-config.json:

{
    "reporterEnabled": "mocha-junit-reporter",
    "reporterOptions": {
      "testsuitesTitle": true,
      "includePending": true,
      "mochaFile" : "./reports/test-results.[hash].xml"
    }
  }

@jennifer-shehane

Can you provide a reproducible example?

Here is a repo with a reproducible example: https://github.com/jluttrell/cypress-mocha-version-warning-repro

Also producing in 6.3 + “mocha-junit-reporter”: “^2.0.0” (via cypress-multi-reporters in my case, but not sure it matter) Appeared when I added the custom reporter. It looks very very similar to https://github.com/cypress-io/cypress/issues/4602. At that time, @gcirone produced a fix in the reporter. To see if that’s the same root cause/same fix situation or a different bug just leading to the same behaviour.

My config in cypress.json is

"reporter": "cypress-multi-reporters",
"reporterOptions": {
  "reporterEnabled": "mochawesome, mocha-junit-reporter",
  "mochawesomeReporterOptions": {
    "reportDir": "reports/mochawesome-json",
    "overwrite": false,
    "html": true,
    "json": true,
    "quiet": true
  },
  "mochaJunitReporterReporterOptions": {
    "mochaFile": "reports/junit-xml/[hash].xml"
  }
},

package.json

    "cypress": "^6.3.0",
    "cypress-multi-reporters": "^1.4.0",
    "mocha-junit-reporter": "^2.0.0",
    "mochawesome": "^6.2.2",