happo / happo-cypress

A Happo integration with Cypress.io
35 stars 4 forks source link

SecurityError when setting up happo-cypress in a test suite with cy.origin usage #98

Closed dcarrot2 closed 1 year ago

dcarrot2 commented 1 year ago

Hello! I'm trying to set up happo-cypress in an app that uses a third party vendor to facilitate authentication and authorization requirements. The flow is roughly:

  1. Navigate to app domain (localhost:port locally)
  2. The app redirects to third party vendor to login
  3. If authentication is successful, vendor redirects back to app domain

After adding import 'happo-cypress' to our project's cypress/support/commands.ts, I run into the following exception when running the single test that exists in the project's Cypress suite:

Screen Shot 2022-10-09 at 6 17 20 PM

Any ideas on how to resolve this? Could this be some sort of race condition between the multi domain support and when takeDOMSnapshot.init is called? Thanks in advance!

trotzig commented 1 year ago

Hi @dcarrot2! I think your analysis is right, takeDOMSnapshot.init is supposed to run whenever a page is loaded. The only thing happening in there is that Happo sets baseUrl properties on style and link elements. IIRC, this is done so that we can later associate assets with the right base path. So if you have a stylesheet at http://localhost:5555/some/path/styles.css and reference assets in that stylesheet using relative paths (e.g. url(assets/image.png)), we'd be able to resolve that asset correctly.

Let me push a version that ignores this specific error and we can see if things get better.

trotzig commented 1 year ago

Try installing happo-e2e@1.2.2 and see if that fixes your issue!

dcarrot2 commented 1 year ago

It fixed my issue! Thank you for the quick response ❤️