cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.02k stars 3.18k forks source link

Component tests occasionally fail with error "Cannot read properties of undefined" #27101

Closed marcelwgn closed 5 months ago

marcelwgn commented 1 year ago

Current behavior

Our component tests occasionally fail with the following two stacktraces:

An uncaught error was detected outside of a test:
     TypeError: Cannot read properties of undefined (reading 'prevAttempts')
      at replacePreviousAttemptWith (http://localhost:3002/__cypress/runner/cypress_runner.js:170126:40)
      at Object.onRunnableRun (http://localhost:3002/__cypress/runner/cypress_runner.js:170265:11)
      at $Cypress.action (http://localhost:3002/__cypress/runner/cypress_runner.js:159665:28)
      at Runnable.run (http://localhost:3002/__cypress/runner/cypress_runner.js:168425:13)
      at ../driver/node_modules/mocha/lib/runner.js.Runner.runTest (http://localhost:3002/__cypress/runner/cypress_runner.js:117650:10)
      at http://localhost:3002/__cypress/runner/cypress_runner.js:117776:12
      at next (http://localhost:3002/__cypress/runner/cypress_runner.js:117559:14)
      at http://localhost:3002/__cypress/runner/cypress_runner.js:117569:7
      at next (http://localhost:3002/__cypress/runner/cypress_runner.js:117471:14)
      at http://localhost:3002/__cypress/runner/cypress_runner.js:117537:5
      at timeslice (http://localhost:3002/__cypress/runner/cypress_runner.js:111463:27)

and

Cannot read properties of undefined (reading 'get')
at isElement (http://localhost:3002/__cypress/runner/cypress_runner.js:164045:38) at validateType (http://localhost:3002/__cypress/runner/cypress_runner.js:163889:14) at Object.isType (http://localhost:3002/__cypress/runner/cypress_runner.js:163920:7) at $Cy.pushSubject (http://localhost:3002/__cypress/runner/cypress_runner.js:163628:22) at wrapped (http://localhost:3002/__cypress/runner/cypress_runner.js:163214:19) at <unknown> (http://localhost:3002/__cypress/runner/cypress_runner.js:162041:15) at tryCatcher (http://localhost:3002/__cypress/runner/cypress_runner.js:20941:23) at Promise._settlePromiseFromHandler (http://localhost:3002/__cypress/runner/cypress_runner.js:18876:31) at Promise._settlePromise (http://localhost:3002/__cypress/runner/cypress_runner.js:18933:18) at Promise._settlePromiseCtx (http://localhost:3002/__cypress/runner/cypress_runner.js:18970:10) at _drainQueueStep (http://localhost:3002/__cypress/runner/cypress_runner.js:15652:12) at _drainQueue (http://localhost:3002/__cypress/runner/cypress_runner.js:15641:9) at ../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:3002/__cypress/runner/cypress_runner.js:15657:5) at Async.drainQueues (http://localhost:3002/__cypress/runner/cypress_runner.js:15527:14)

Desired behavior

Tests should not occasionally crash due to outside of tests that doen't seem to originate from our code (at least looking at the stacktrace).

Test code to reproduce

So far we haven't found a reliable way to reproduce this, locally test runs are mostly fine. Running in GitHub Actions, error rate seems to be around 50%.

Cypress Version

12.15.0

Node version

20.2.0 locally, v16.16.0 in GitHub Actions

Operating System

10.0.22621.1848 locally, 22.04.2 in GitHub Actions

Debug Logs

No response

Other

This issue seemed to be fixed by downgrading our vite version from 4.3.9 to 4.1.1 seemed to have fixed this issue for us.

mike-plummer commented 1 year ago

Hi @chingucoding , sorry to hear you're having issues. Are you able to provide us with Debug Logs of a failing run so we can try to diagnose what's going on?

mike-plummer commented 1 year ago

Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.

marcelwgn commented 1 year ago

Sorry for the completely late reply. It seems our issue somehow didn't occur anymore, however I am able to reproduce this with upgrading cypress to any version after 13.0. The issue only occurs on first runs, the second, third ... run work just fine. The vite version does not seem to matter. I would be able to provide you debug logs, however we would prefer not sharing that publicly depending on the loggers you want to see.

muratkeremozcan commented 1 year ago

We can consistently reproduce this in our CI. Locally, all is well. We are working with the Cy team towards a resolution so Vite works well in CI.

jennifer-shehane commented 10 months ago

@muratkeremozcan This has the same stack trace in v13? Can someone provide a way to reproduce?

jennifer-shehane commented 5 months ago

We'll have to close this issue since there's no information to reproduce this.