Cypress - Cannot read properties of undefined (reading '_currentRetry')

614 views Asked by At

I'm having an issue I can't manage to fix with some Cypress tests.

I have the test file "run_tests.cy.js", that contains the following:

describe('Run tests', () => {
    it('Run all tests', () =>{
        require('../path/to/test_1.cy.js');
        require('../path/to/test_2.cy.js');
        require('../path/to/test_3.cy.js');
        require('../path/to/test_4.cy.js');
        require('../path/to/test_5.cy.js');
        require('../path/to/test_6.cy.js');
        require('../path/to/test_7.cy.js');
    })
})

And I have a custom script in my package.json file:

"cy:run:test": "cypress run --browser chromium --config baseUrl=https://google.com/ --spec './cypress/e2e/path/to/run_tests.cy.js'",

When I run the test manually, aka npx cypress open, selecting E2E testing, selecting chromium and selecting the test. It works as intended (the test works)

The problem is when I try and run my custom script npm run cy:run:test I get the following error:

Cannot read properties of undefined (reading '_currentRetry')
TypeError: Cannot read properties of undefined (reading '_currentRetry')
    at E.<anonymous> (<embedded>:4644:13577)
    at E.parseArgs (<embedded>:4644:16785)
    at E.emit (<embedded>:4644:16602)
    at Object.onMocha (<embedded>:4691:427158)
    at p.<anonymous> (<embedded>:4691:68249)
    at p.emit (node:events:527:28)
    at p.emitUntyped (<embedded>:4402:84346)
    at <embedded>:4402:91863
    at process.processTicksAndRejections (node:internal/process/task_queues:78:11)

Any idea what I can do to fix this issue?

1

There are 1 answers

3
SuchAnIgnorantThingToDo-UKR On

I am speculating that test_1.cy.js already contain it() blocks, which would mean that you effectively nest it-blocks with it('Run all tests', () => { require('../path/to/test_1.cy.js')

Another clue, _currentRetry is a property of test which is the internal object for an it-block. So maybe the Cypress runner is confused about what is the test.

describe('Run all tests', () => {
  require('../path/to/test_1.cy.js');
  require('../path/to/test_2.cy.js');
  ...
})

This would be legitamate, since you can nest describe() blocks.