percy / percy-cypress

Visual testing with Cypress and Percy
https://percy.io
MIT License
346 stars 40 forks source link

[Cypress regression]`TypeError: data.hasOwnProperty is not a function` #434

Closed pun-ky closed 2 years ago

pun-ky commented 2 years ago

The problem

After adding line to cypress/support/index.js:

import '@percy/cypress';

then running Cypress fails with:

 Product Page
TypeError: data.hasOwnProperty is not a function
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:39:22)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:32:26)
    at Object.deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:16:17)
    at Encoder.encodeAsBinary (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/index.js:80:41)
    at Encoder.encode (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/index.js:42:29)
    at Client._packet (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io/dist/client.js:169:44)
    at Socket.packet (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io/dist/socket.js:160:21)
    at /Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io/dist/socket.js:274:18
    at /Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/lib/socket-base.js:318:28
    at tryCatcher (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (node:internal/timers:464:21)

TypeError: data.hasOwnProperty is not a function
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:39:22)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:40:32)
    at _deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:32:26)
    at Object.deconstructPacket (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/binary.js:16:17)
    at Encoder.encodeAsBinary (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/index.js:80:41)
    at Encoder.encode (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io-parser/dist/index.js:42:29)
    at Client._packet (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io/dist/client.js:169:44)
    at Socket.packet (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io/dist/socket.js:160:21)
    at /Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/socket/node_modules/socket.io/dist/socket.js:274:18
    at /Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/lib/socket-base.js:318:28
    at tryCatcher (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/krystian.panek/Library/Caches/Cypress/9.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (node:internal/timers:464:21)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When I am downgrading cypress to:

    "cypress": "^8.7.0",

There is no error. Everything works properly.

Environment

  "devDependencies": {
    "cypress": "^9.1.0",
    "mocha": "^9.1.3",
    "mochawesome": "^7.0.1",
    "cypress-mochawesome-reporter": "^2.3.0",
    "cypress-multi-reporters": "^1.5.0",
    "mocha-junit-reporter": "^2.0.2",
    "typescript": "4.5.2",
    "@percy/cli": "^1.0.0-beta.70",
    "@percy/cypress": "^3.1.1"
  }
cexbrayat commented 2 years ago

Just ran into the same issue. Note that it works with Cypress v9.0, but not with v9.1

Robdel12 commented 2 years ago

👋🏼 I'm not at my computer to debug this yet but it feels like a red herring that there's nothing Percy related in that stack trace. Why is there bluebird in the stack trace (really old promise dep)? 🤨

I see "typescript": "4.5.2", in your provided packag.json. Given the example app works fine with Cypress v9, I suspect this is actually a typescript + Cypress problem (and maybe + Percy too, there's also this annoying TS bug: https://github.com/percy/percy-cypress/issues/430)

cexbrayat commented 2 years ago

@Robdel12 This appears to be related to percy: if I remove all the related code to percy, it works fine again in my case (on several projects). We do use TS as well, both TS 4.4 and TS 4.5.

Robdel12 commented 2 years ago

This sure does smell a lot like https://github.com/cypress-io/cypress/issues/15101 & https://github.com/percy/percy-cypress/issues/325

cexbrayat commented 2 years ago

It does. I also had that issue in the past, but this was fixed and had not happened again since.

cexbrayat commented 2 years ago

FYI someone opened a similar issue on Cypress https://github.com/cypress-io/cypress/issues/19091

atmullan commented 2 years ago

Also getting this issue after upgrade to 9.1.0, I have percy enabled.

atmullan commented 2 years ago

Downgrading to Cypress 9.0.0 Resolves the issue for me. Note: Not using Typescript

geoffharcourt commented 2 years ago

We're seeing error this happen, but only in specs that have involve @percy/cypress, and only as of Cypress 9.1.

Robdel12 commented 2 years ago

My guess is Cypress had a regression in their networking stack. Percy's SDK POST's the DOM snapshot to local Percy server and this was an issue in Cypress in the past (with almost the exact same error message). People are reporting seeing the same issue without Percy and the stack trace doesn't have any Percy code in it.

Looks like we'll have to wait for Cypress to patch

Robdel12 commented 2 years ago

I added a comment to the Cypress issue, but this doesn't appear to be a Percy issue. Staying on v9.0.x will stay away from the issue (I believe) while this is looked at by the Cypress folks. Here's the comment I left on their issue:

I spent some time digging in to try and isolate & reproduce.

describe("Breaking reproduction", function () {
  it("doesn't throw an error when making requests", function () {
    cy.then(() =>
      Cypress.backend("http:request", {
        url: "http:localhost:8001/nothing/here",
        method: "POST",
      })
    );
  });
});

This will break with the same stack trace in the OP (https://github.com/percy/example-percy-cypress/runs/4400801282?check_suite_focus=true)

Robdel12 commented 2 years ago

Upgrading to v9.1.1 of cypress should solve this https://github.com/cypress-io/cypress/issues/19091