Search code examples
repositorymocha.jscypressversionpackage.json

No Mocha version is shown in the package.json when testing with cypress


I am using cypress. But as I understand the cypress is built above mocha. So, I want to check what mocha version the project I am working with uses. I am heading to the package.json doing the search, but finding no mocha dependencies. Does it mean that mocha is built into cypress? How could I determine the used inside cypress mocha version then?


Solution

  • Updated

    As Drew pointed out there are many versions of Mocha used in various packages under the Cypress repository.

    I'm not sure that dependencies vs devDependencies is a solid indicator, since Cypress uses the Mocha library to make a modified version.

    Here's a sampling from packages in the Cypress 12.16.0 repo:

    • npm/webpack-dev-server: "mocha": "^9.2.2",
    • npm/vite-dev-server: "mocha": "^9.2.2",
    • graphql: "mocha": "^8.1.3",
    • launcher: "mocha": "^8.1.3",
    • tooling/electron-mksnapshot: "mocha": "^9.2.0",
    • webpack-batteries-included-preprocessor: "mocha": "^8.1.1",
    • webpack-preprocessor: "mocha": "^7.1.0",
    • server: "mocha": "7.1.0", etc

    so it kind of depends on the part of the Cypress suite you are using (Component tester, e2e runner, module api)

    The link I would use for e2e testing is the driver package

      "devDependencies": {
        ...
        "mocha": "7.0.1",
    

    Another approach that currently works is querying the global Cypress object.

    it('log the Mocha version in use', function() { 
      console.log(Cypress.mocha._mocha.version)   // 7.0.1 for Cypress 12.16.0
    })
    

    where Cypress.mocha is the instance object and Cypress.mocha._mocha is the class definition (shown in devtools as Mocha type).

    These properties may be removed at a future time.